【发布时间】:2023-01-18 01:59:12
【问题描述】:
我的 .NET Core 3.1 应用程序连接到 Dynamics 时遇到问题。使用ServiceClient 类连接到 dynamics 时会发生该错误,但它不会一直发生,也不是随机的。我无法确定问题的原因。
这是我在应用程序尝试连接时收到的错误消息:
2023-01-16T07:22:43.189 [Error] Executed 'CreateCustomerTimelineHttpTrigger' (Failed, Id=a36dba87-30c3-4dab-93b3-7a00aeba4de3, Duration=2346ms)Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseConnectionException : Failed to connect to Dataverse
---> System.AggregateException : One or more errors occurred. (Exception - Fault While initializing client - RefreshInstanceDetails)
---> Exception - Fault While initializing client - RefreshInstanceDetails
---> Exception - Failed to lookup current organization data
---> A proxy type with the name msdyncrm_GetReactions has been defined by another assembly.
Current type: CrmEarlyBound.msdyncrm_GetReactionsResponse, CEP.CustomerTimeline.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, Existing type: CrmEarlyBound.msdyncrm_GetReactionsResponse, CEP.CustomerTimeline.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (Parameter 'msdyncrm_GetReactions')
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)at System.Threading.Tasks.Task`1.get_Result()
at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.GetCachedService(ConnectionService& ConnectionObject)
at Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.IntilizeService(ConnectionService& ConnectionObject)
at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.CreateServiceConnection(Object externalOrgServiceProxy,AuthenticationType requestedAuthType,String hostName,String port,String orgName,NetworkCredential credential,String userId,SecureString password,String domain,String Geo,String claimsHomeRealm,Boolean useSsl,Boolean useUniqueInstance,OrganizationDetail orgDetail,String clientId,Uri redirectUri,PromptBehavior promptBehavior,OrganizationWebProxyClientAsync externalOrgWebProxyClient,String certificateThumbPrint,StoreName certificateStoreName,X509Certificate2 certificate,Uri instanceUrl,Boolean isCloned,Boolean useDefaultCreds,Version incomingOrgVersion,ILogger externalLogger,String tokenCacheStorePath)
---> (Inner Exception #0) Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseConnectionException : Exception - Fault While initializing client - RefreshInstanceDetails
---> Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseOperationException : Exception - Failed to lookup current organization data
---> System.ArgumentException : A proxy type with the name msdyncrm_GetReactions has been defined by another assembly. Current type: CrmEarlyBound.msdyncrm_GetReactionsResponse, CEP.CustomerTimeline.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, Existing type: CrmEarlyBound.msdyncrm_GetReactionsResponse, CEP.CustomerTimeline.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (Parameter 'msdyncrm_GetReactions')
at Microsoft.Xrm.Sdk.AppDomainBasedKnownProxyTypesProvider.AddTypeMapping(Assembly assembly,Type type,String proxyName)
at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.LoadKnownTypes(Assembly assembly)
at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.RegisterAssembly(Assembly assembly)at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.InitializeLoadedAssemblies()
at Microsoft.Xrm.Sdk.AppDomainBasedKnownProxyTypesProvider..ctor()
at Microsoft.Xrm.Sdk.KnownProxyTypesProvider.GetInstance(Boolean supportIndividualAssemblies)
at Microsoft.Xrm.Sdk.ProxySerializationSurrogate.System.Runtime.Serialization.ISerializationSurrogateProvider.GetObjectToSerialize(Object obj,Type targetType)
at System.Runtime.Serialization.DataContractSerializer.SurrogateToDataContractType(ISerializationSurrogateProvider serializationSurrogateProvider,Object oldObj,Type surrogatedDeclaredType,Type& objType)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer,Object graph,DataContractResolver dataContractResolver)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer,Object graph,DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer,Object graph,DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer,Object graph)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter writer,PartInfo part,Object graph)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer,PartInfo part,Object graph)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer,PartInfo[] parts,Object[] parameters)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer,MessageVersion version,String action,MessageDescription messageDescription,Object returnValue,Object[] parameters,Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer,MessageVersion version,Object[] parameters,Object returnValue,Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message,BufferManager bufferManager,Int32 initialOffset,Int32 maxSizeQuota)
at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessageAsync(Message message,Int32 maxMessageSize,BufferManager bufferManager,Int32 messageOffset)
at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message,Int32 maxMessageSize,BufferManager bufferManager,Int32 messageOffset)
at System.ServiceModel.Channels.BufferedMessageContent.EnsureMessageEncoded()
at System.ServiceModel.Channels.BufferedMessageContent.TryComputeLength(Int64& length)
at System.Net.Http.HttpContent.GetComputedOrBufferLength()
at System.Net.Http.Headers.HttpContentHeaders.get_ContentLength()
at System.Net.Http.SocketsHttpHandler.ValidateAndNormalizeRequest(HttpRequestMessage request)
at System.Net.Http.SocketsHttpHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
at async System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()at async System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask,HttpRequestMessage request,CancellationTokenSource cts,Boolean disposeCts)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.SendRequestAsync[TChannel](Message message,TimeoutHelper timeoutHelper)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async System.ServiceModel.Channels.RequestChannel.RequestAsync(??)at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async System.ServiceModel.Channels.RequestChannel.RequestAsyncInternal(Message message,TimeSpan timeout)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.TaskHelpers.WaitForCompletionNoSpin[TResult](Task`1 task)at System.ServiceModel.Channels.RequestChannel.Request(Message message,TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message,TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object[] ins,Object[] outs,TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall,ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod,Object[] args)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Reflection.DispatchProxyGenerator.Invoke(Object[] args)
at generatedProxy_1.Execute(OrganizationRequest )
at Microsoft.PowerPlatform.Dataverse.Client.Connector.OrganizationWebProxyClientAsync.<>c__DisplayClass52_0.<ExecuteCore>b__0()
at Microsoft.PowerPlatform.Dataverse.Client.Connector.WebProxyClientAsync`1.ExecuteAction[TResult](Func`1 action)
at Microsoft.PowerPlatform.Dataverse.Client.Connector.OrganizationWebProxyClientAsync.ExecuteCore(OrganizationRequest request)
at Microsoft.PowerPlatform.Dataverse.Client.Connector.OrganizationWebProxyClientAsync.Execute(OrganizationRequest request)
at async Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.RefreshInstanceDetails(IOrganizationService dvService,Uri uriOfInstance)
End of inner exception
at async Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.RefreshInstanceDetails(IOrganizationService dvService,Uri uriOfInstance)
End of inner exception
at async Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.RefreshInstanceDetails(IOrganizationService dvService,Uri uriOfInstance)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.DoDirectLoginAsync(Boolean IsOnPrem)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.PowerPlatform.Dataverse.Client.ConnectionService.InitServiceAsync()<---
End of inner exception
at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.CreateServiceConnection(Object externalOrgServiceProxy,AuthenticationType requestedAuthType,String hostName,String port,String orgName,NetworkCredential credential,String userId,SecureString password,String domain,String Geo,String claimsHomeRealm,Boolean useSsl,Boolean useUniqueInstance,OrganizationDetail orgDetail,String clientId,Uri redirectUri,PromptBehavior promptBehavior,OrganizationWebProxyClientAsync externalOrgWebProxyClient,String certificateThumbPrint,StoreName certificateStoreName,X509Certificate2 certificate,Uri instanceUrl,Boolean isCloned,Boolean useDefaultCreds,Version incomingOrgVersion,ILogger externalLogger,String tokenCacheStorePath)
at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient..ctor(Uri instanceUrl,String clientId,String clientSecret,Boolean useUniqueInstance,ILogger logger)
at CEP.CustomerTimeline.API.Repositories.DynamicsRepository..ctor(IOptions`1 options)
at D:\a\1\s\CEP.CustomerTimeline.API\Repositories\DynamicsRepository.cs : 19at lambda_method(Closure )at DryIoc.Scope.TryGetOrAdd(ImMap`1 items,Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7856at DryIoc.Scope.GetOrAdd(Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7841at lambda_method(Closure )
at DryIoc.Scope.TryGetOrAdd(ImMap`1 items,Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7856at DryIoc.Scope.GetOrAdd(Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7841at lambda_method(Closure )
at DryIoc.Scope.TryGetOrAdd(ImMap`1 items,Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7856at DryIoc.Scope.GetOrAdd(Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7841at lambda_method(Closure )
at DryIoc.Scope.TryGetOrAdd(ImMap`1 items,Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7856
at DryIoc.Scope.GetOrAdd(Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7841at lambda_method(Closure )
at DryIoc.Scope.TryGetOrAdd(ImMap`1 items,Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7856at DryIoc.Scope.GetOrAdd(Int32 id,CreateScopedValue createValue,Int32 disposalOrder)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 7841at lambda_method(Closure ,IResolverContext )
at DryIoc.Container.ResolveAndCacheDefaultFactoryDelegate(Type serviceType,IfUnresolved ifUnresolved)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 225at DryIoc.Container.DryIoc.IResolver.Resolve(Type serviceType,IfUnresolved ifUnresolved)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\DryIoc\Container.cs : 196
at Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection.ScopedServiceProvider.GetService(Type serviceType)
at D:\a\_work\1\s\src\WebJobs.Script.WebHost\DependencyInjection\ScopedServiceProvider.cs : 25
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp,Type type,Type requiredBy,Boolean isDefaultParameterRequired)at lambda_method(Closure ,IServiceProvider ,Object[] )
at Microsoft.Azure.WebJobs.Host.Executors.DefaultJobActivator.CreateInstance[T](IServiceProvider serviceProvider) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\DefaultJobActivator.cs : 42
at Microsoft.Azure.WebJobs.Host.Executors.DefaultJobActivator.CreateInstance[T](IFunctionInstanceEx functionInstance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\DefaultJobActivator.cs : 32
at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory`1.<>c__DisplayClass1_1.<.ctor>b__0(IFunctionInstanceEx i)
at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs : 20
at Microsoft.Azure.WebJobs.Host.Executors.ActivatorInstanceFactory`1.Create(IFunctionInstanceEx functionInstance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\ActivatorInstanceFactory.cs : 26
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.CreateInstance(IFunctionInstanceEx functionInstance) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs : 44
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ParameterHelper.Initialize() at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 793
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs : 104
我在使用 .NET Framework NuGets 时看到过有关此错误的帖子,他们的解决方案不适用或无效。在动态方面我不是专家,我的主要重点是集成,所以我在这里不知所措。
当应用程序 FunctionStartup 正在运行并且存储库类和连接被启动时,会发生错误。连接是在限定的生命周期内完成的,并且相同的连接用于 Dyncamics 的所有操作(我也尝试为每个实体使用一个连接)。
到目前为止我所做的观察:
- earlybound 似乎与此问题有关,因为如果我转到 latebound 并删除 earlybound 文件,问题就会消失。但是我还有其他解决方案将早期绑定与 ServiceClient 结合使用,效果很好
- 该问题似乎也与其连接的动态实例有关,因为它不会发生在我们的 DEV 环境中,但会发生在 SIT 中
- 删除导致问题的类型会导致相同的错误,但会导致不同的类型
- 它在本地工作,直到我将它部署到我的函数应用程序时才发生崩溃
- 只需重新启动函数应用即可解决该问题
我的想法是 earlybound 与其他一些组件发生冲突,因为删除它可以解决问题。这是我正在寻找的未知组件,我的一部分正在寻找动态,因为它在一个环境而不是另一个环境中工作,并且它始终是它工作的相同环境。
对此的任何帮助或见解将不胜感激。如果对此还有其他问题,请告诉我。
谢谢!
【问题讨论】:
标签: dynamics-crm dataverse serviceclient