CNAP
CNAP

Reputation: 59

Dataverse.ServiceClient fails to connect to Dynamics with "Failed to lookup current organization data"

I have a problem with my .NET Core 3.1 application that connects to Dynamics. The error occurs when connecting to dynamics using the ServiceClient class, but it does not happen all the time and is not random. I am having trouble pinpointing the cause of the issue.

This is the error message I get when the application tries to connect:

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

I have seen posts regarding this error when using .NET Framework NuGets, the solution from them are either not applicable or have not worked. I am no expert when it comes to dynamics, my main focus are on integrations so I am at a loss here.

The error occurs when the applications FunctionStartup is running and the repository class, with the connection, is initiated. The connection is done with a scoped lifetime and the same connection is used for all operations towards Dyncamics (I have tried to use one connection per entity as well).

Observations I have made so far:

My reflection is that the earlybound is conflicting with some other component as removing it removes the issue. It is the unknown component that I am looking for and part of me is looking towards dynamics, as it works in one environment and not the other and it is always the same environment it works for.

Any help or insight into this would be greatly appreciated. Please let me know if there are further questions on this.

Thank you!

Upvotes: 1

Views: 3879

Answers (1)

MattB
MattB

Reputation: 186

---> A proxy type with the name msdyncrm_GetReactions has been defined by another assembly.

You are correct, that this is the relevant part of the error. That that you're not seeing it locally, and or you're not seeing it on the restart of a function indicates that you're dynamically loading a lib during runtime. ( are you? )

if so that lib has the same types as the root function has + the assembly attribute

[assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()]

That attribute causes the client to attempt to load the types of that assembly into the type mapper used by the client.

its only usefull if your using Linq operations based on the organization service context.

if your not using linq, the easiest way to fix this is to remove the assembly attribute above.

Upvotes: 2

Related Questions