Service Stack API - System.InvalidOperationException - ServiceStack.ServiceStackHost.OnEndRequest(IRequest request)

时间:2017-05-14 23:51:11

标签: c# entity-framework asp.net-web-api servicestack dto

我们正在为我们的Web应用程序使用Service Stack Web API。在prod服务器上,所有功能都可以工作,但是当我们向服务器发出请求时,对于每个请求都会产生如下错误。

"System.InvalidOperationException: Collection was modified; enumeration operation may not execute".

这是Stack:

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

at System.Collections.Hashtable.HashtableEnumerator.MoveNext()    在ServiceStack.ServiceStackHost.OnEndRequest(IRequest请求)

抛出错误的代码。

 public UserPetsResponse Any(GetUserPetsDTO request)
    {
        UserPetsResponse res = new UserPetsResponse();
        if (request.subscriberID != null)
        {
            try
            {
                var controller = new ExactTargetControllers.ExactTargetControllers();
                res = controller.GetActivePetsOfSubscriber(request.subscriberID);
            }
            catch (Exception ex)
            {
                res.responseMessage = ResponseMessage.Error;
                ErrorLogger errorlog = new Service.ErrorLogger();
                errorlog.LogInElmah(ex);
            }
        }
        return res;
    }

public UserPetsResponse GetActivePetsOfSubscriber(string subscriberID)
    {
        UserPetsResponse res = new UserPetsResponse();
        List<PetModel> pets = new List<PetModel>();
        APIObject[] Results;
        String requestID;
        String status;
        // Instantiate the retrieve request
        RetrieveRequest rr = new RetrieveRequest();
        rr.ObjectType = String.Format("DataExtensionObject[{0}]", _CustomerKey_PetDE);//required
                                                                                      // Setting up a simple filter
        SimpleFilterPart sf = new SimpleFilterPart();
        sf.SimpleOperator = SimpleOperators.equals;
        sf.Property = "SubscriberID";
        sf.Value = new String[] { subscriberID };
        //Add Filter
        rr.Filter = sf;
        rr.Properties = new string[] { "SubscriberID", "petName", "petBirthday", "petSpecies"
                                        ,"petBreed","_CustomObjectKey","IsActive","petID"};//required //Any Column on the Data Extension
        status = _frameWork.Retrieve(rr, out requestID, out Results);
        for (int i = 0; i < Results.Length; i++)
        {
            PetModel pet = new PetModel();
            pet = PetMapper(Results[i]);
            if (pet.isActive)
            {
                pets.Add(pet);
            }

        }
        if (status.Contains("OK"))
        {
            res.responseMessage = ResponseMessage.OK;
        }
        else
        {
            res.responseMessage = ResponseMessage.Error;
            res.errorMessage = status;
        }
        res.pets = pets;
        return res;
    }

我不确定为什么会收到此错误。

1 个答案:

答案 0 :(得分:1)

ServiceStack的OnEndRequest遍历并处理该请求的所有每个实例或每个请求的依赖项,因此您应该检查该请求中使用的依赖项的completed实现,尤其是任何它们使用IDisposable