【问题标题】:key was not found in dictionary在字典中找不到密钥
【发布时间】:2018-09-22 02:36:45
【问题描述】:

以下异常,似乎提示找不到配置值之一:

{
    "error": {
        "code": "",
        "message": "An error has occurred.",
        "innererror": {
            "message": "One or more errors occurred.",
            "type": "System.AggregateException",
            "stacktrace": "   at Microsoft.ServiceFabric.Services.Communication.Client.ServicePartitionClient`1.<InvokeWithRetryAsync>d__24`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServiceFabric.Services.Remoting.V2.Client.ServiceRemotingPartitionClient.<InvokeAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServiceFabric.Services.Remoting.Builder.ProxyBase.<InvokeAsyncV2>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServiceFabric.Services.Remoting.Builder.ProxyBase.<ContinueWith>d__12.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n   at Sales.o777.OrderManagement.Controller.OrderCapturesController.<Post>d__9.MoveNext() in C:\\ws\\CleanRoom\\DEV\\Source\\ENTERPRISEAPI\\abc.API.Sales.o777.OrderManagement\\Sales.o777.OrderManagement\\Controller\\OrderCaptureController.cs:line 75\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()",
            "internalexception": {
                "message": "The given key was not present in the dictionary.",
                "type": "System.Collections.Generic.KeyNotFoundException",
                "stacktrace": "   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)\r\n   at OCLineItemsActor.Interfaces.IOCLineItemsActor_.actor.disp.IOCLineItemsActorMethodDispatcher.OnDispatchAsync(Int32 , Object , IServiceRemotingRequestMessageBody , IServiceRemotingMessageBodyFactory , CancellationToken )\r\n   at Microsoft.ServiceFabric.Actors.Runtime.ActorManager.ActorMethodDispatch(ActorMethodDispatcherBase methodDispatcher, ActorBase actor, Int32 interfaceId, Int32 methodId, IServiceRemotingRequestMessageBody requestBody, IServiceRemotingMessageBodyFactory remotingMessageBodyFactory, CancellationToken innerCancellationToken)\r\n   at Microsoft.ServiceFabric.Actors.Runtime.ActorManager.<>c__DisplayClass30_0.<InvokeAsync>b__0(ActorBase actor, CancellationToken innerCancellationToken)\r\n   at Microsoft.ServiceFabric.Actors.Runtime.ActorManager.<DispatchToActorConcurrencyLockHeldAsync>d__48`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServiceFabric.Actors.Runtime.ActorManager.<DispatchToActorAsync>d__29`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.ServiceFabric.Actors.Runtime.ActorManager.<DispatchToActorAsync>d__29`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServiceFabric.Services.Remoting.Runtime.ServiceRemotingCancellationHelper.<Dispatabcequest>d__5`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServiceFabric.Actors.Remoting.V2.Runtime.ActorServiceRemotingDispatcher.<HandleActorMethodDispatchAsync>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.ServiceFabric.Services.Remoting.V2.FabricTransport.Runtime.FabricTransportMessageHandler.<RequestResponseAsync>d__7.MoveNext()"
            }
        }
    }
}

流程:

  1. 针对微服务发布正文
  2. 微服务启动编排,其中之一是使用共享接口IOCLineItemsActor 上的方法

根据以下,异常发生在第75行,见innerexception:

...\Sales.o777.OrderManagement\\Controller\\OrderCaptureController.cs:line 75\r\n--- End of stack trace from pr...

第 74/75 行如下:

var proxy = ActorProxy.Create<IOCLineItemsActor>(ActorId.CreateRandom(), new Uri(@"fabric:/abc.API/OCLineItemsActor/OCLineItemsActorService"));

await proxy.MergeLineItemsToOpportunity(orderCapture.Id, (Guid)orderCapture.OpportunityId); //this is line 75 ! seems like it may be looking for a onfig setting here?

发布开发环境时,我们没有得到给定的键不在字典中异常;但是,当我发布到 QA 时,我们确实得到了这个异常。

我比较了 ApplicationParameters 文件(dev vs qa),它们是相同的。

我做错了什么?我如何确定它缺少哪个键?

这里是MergeLineItemsToOpportunity

    internal class OCLineItemsActor : Actor, IOCLineItemsActor
    {
        /// <summary>
        ///     Initializes a new instance of OCLineItemsActor
        /// </summary>
        /// <param name="actorService">
        ///     The Microsoft.ServiceFabric.Actors.Runtime.ActorService that will host this ocLineItemsActor
        ///     instance.
        /// </param>
        /// <param name="actorId">The Microsoft.ServiceFabric.Actors.ActorId for this ocLineItemsActor instance.</param>
        public OCLineItemsActor(ActorService actorService, ActorId actorId)
            : base(actorService, actorId)
        {
            CMConnectionString = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config")
                .Settings.Sections["CRMWebService"].Parameters["CMDatabaseConnection"].Value;
            CRMConnectionString = FabricRuntime.GetActivationContext().GetConfigurationPackageObject("Config")
                .Settings.Sections["CRMWebService"].Parameters["CRMDatabaseConnection"].Value;
            SprocExecutor = new SprocExecutor(CMConnectionString, CRMConnectionString);
        }

    public Task MergeLineItemsToOpportunity(int orderCaptureId, Guid opportunityId)
    {
        OCLineItemsEventSource.Current.Message("orderCaptureId: " + orderCaptureId);

        var executor = new SprocExecutor(CMConnectionString, CRMConnectionString);

        SprocExecutor.MergeLineItemsToOpportunity(orderCaptureId, opportunityId);

        return Task.CompletedTask;
    }

}

【问题讨论】:

  • 哇,我刚刚看到了你所有的徽章。但是我认为我们缺少一些重要信息。我的意思是里面有什么MergeLineItemsToOpportunity 因为这不可能是故事的结局
  • 感谢@TheGeneral 我已更新

标签: c# .net visual-studio visual-studio-2017 azure-service-fabric


【解决方案1】:

我没有直接引用Interfaces DLL,而是引用了包含接口的csproj 文件。为什么这有效,我不知道。

【讨论】:

    猜你喜欢
    • 2013-11-07
    • 2023-01-12
    • 2013-01-04
    • 2014-02-10
    • 2017-11-20
    • 2017-10-08
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多