在字典中找不到密钥

时间:2018-04-12 04:41:17

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

以下异常似乎表明无法找到其中一个配置值:

{
    "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
  3. 根据以下内容,异常发生在第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;
        }
    
    }
    

1 个答案:

答案 0 :(得分:0)

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