乔恩
实际上,问题是WCF试图对服务器响应进行应对范围而无法识别正确的类型。对此问题进行排序的最佳方法是使用assembly.getExeCutingAssembly()传递当前汇编,以在创建代理时,将其传递给ProxyTypesBehavior()。
using (serviceProxy = new OrganizationServiceProxy(config.OrganizationUri,
config.HomeRealmUri,
config.Credentials,
config.DeviceCredentials))
{
// This statement is required to enable early-bound type support.
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior(Assembly.GetExecutingAssembly()));
}
这应该有所帮助:
var credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain);
var proxy = new OrganizationServiceProxy(new Uri(discoveryUrl), null, credentials, null);
proxy.EnableProxyTypes(typeof(CrmServiceContext).Assembly);
var context = CrmServiceContext(proxy);
如果在单个方法中,您可以使用相同的服务对象进行多个CRUD操作,但是使用上述示例的上下文对象,则很可能会增加此错误。但是,通过执行以下操作,您可以防止它发生。
您想使用Context1的每一个时间,都在上下文对象之前使用服务对象进行以下操作:
service.EnableProxyTypes(typeof(OrganizationServiceContext).Assembly);
using (var context1 = new OrganizationServiceContext(_service)){
// your classic code here
}
service.EnableProxyTypes(typeof(HiwebContext).Assembly);
using (var context = new XYZContext(this._service)){
// your CrmSvcUtil none-classic code here
}
通常意味着有一个或多个带有相同方法名称或属性来修复此程序的组件使用程序集的完全合格名称。例如,在使用system.io中在与system.io冲突的类代码中。。。 thisobject.system.io..path(-----)=例如。
I发现添加汇编。getExeCutingAssembly()解决了问题。
添加gassebly.getExeCutingAssembly()解决我的问题,您还需要添加using System.Reflection;
thanks
ServiceClient serviceClient = new ServiceClient(new Uri(Environment.GetEnvironmentVariable("DataverseUrl")), Environment.GetEnvironmentVariable("DataverseClientId"), Environment.GetEnvironmentVariable("DataverseSecret"), false, log);
ServiceClient service = serviceClient.Clone(Assembly.GetExecutingAssembly(), log);
.net9中的我遇到了同样的问题。 根据我尝试创建服务的何时何地,它要么起作用。
例如,如果我在program.cs中创建服务客户端时,当应用程序启动时,它将起作用,我可以将whoami api称为良好。 Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseConnectionException: Failed to Clone Connection
---> Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseOperationException: Failed constructing cloned connection. debugstate=1
---> Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseOperationException: Exception - Failed to lookup current user
---> System.ArgumentException: A proxy type with the name account has been defined by another assembly.
Current type: Integrations.Dynamics365.Entities.Account, Integrations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null,
Existing type: Integrations.Dynamics365.Entities.Account, Integrations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (Parameter 'account')
at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.Execute(OrganizationRequest request)