gpt4 book ai didi

c# - 服务堆栈 API - System.InvalidOperationException - ServiceStack.ServiceStackHost.OnEndRequest(IRequest 请求)

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:38 25 4
gpt4 key购买 nike

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

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

这是堆栈:

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

在 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;
}

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

最佳答案

ServiceStack 的 OnEndRequest遍历并处理该请求的所有实例或请求依赖项,因此您应该检查该请求中使用的依赖项的 IDisposable 实现,尤其是使用 哈希表

关于c# - 服务堆栈 API - System.InvalidOperationException - ServiceStack.ServiceStackHost.OnEndRequest(IRequest 请求),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43969880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com