【发布时间】:2019-07-16 01:04:38
【问题描述】:
我在 C# (.NET 4.6.2) 中创建了一个 Windows 窗体应用程序。我正在使用以下代码在线连接到 Dynamics 365:
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "XXXXX@XXX.onmicrosoft.com";
clientCredentials.UserName.Password = "XXXXXXXX";
Uri crmURL = new Uri("https://XXXXX.api.crm4.dynamics.com/XRMServices/2011/Organization.svc");
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
using (OrganizationServiceProxy orgaSvcProxy = new OrganizationServiceProxy(crmURL, null, clientCredentials, null))
{
IOrganizationService orgaService = (IOrganizationService)orgaSvcProxy;
if (orgaService != null)
{
Guid userid = ((WhoAmIResponse)orgaService.Execute(new WhoAmIRequest())).UserId;
if (userid != Guid.Empty)
{
MessageBox.Show("Connection established successfully");
}
}
}
我在 VS 2015 (.NET 4.6.2) 项目中引用了以下 2 个 dll:
- Microsoft.Xrm.Sdk.dll
- Microsoft.Crm.Sdk.Proxy.dll
如果我从 VS IDE 启动 windows 窗体或使用 exe 文件启动 windows 窗体,一切正常。但是,如果我 使用 ILMERGE 将 exe 和上述两个 dll 合并到一个 exe 文件中 并使用合并的 exe 启动 windows 窗体,则以下代码行开始失败:
OrganizationServiceProxy orgaSvcProxy = new OrganizationServiceProxy(crmURL, null, clientCredentials, null)
上面的代码行抛出以下错误:
System.NullReferenceException:对象引用未设置为实例 的一个对象。在 Microsoft.Xrm.Sdk.Client.ServiceMetadataUtility.GetSDKVersionNumberFromAssembly() 在 Microsoft.Xrm.Sdk.Client.ServiceMetadataUtility.RetrieveServiceEndpointMetadata(类型 contractType, Uri serviceUri, Boolean checkForSecondary) 在 Microsoft.Xrm.Sdk.Client.ServiceConfiguration
1..ctor(Uri serviceUri, Boolean checkForSecondary) at Microsoft.Xrm.Sdk.Client.OrganizationServiceConfiguration..ctor(Uri serviceUri, Boolean enableProxyTypes, Assembly assembly) at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateConfiguration[TService](Uri serviceUri, Boolean enableProxyTypes, Assembly assembly) at Microsoft.Xrm.Sdk.Client.ServiceConfigurationFactory.CreateConfiguration[TService](Uri serviceUri) at Microsoft.Xrm.Sdk.Client.ServiceProxy1..ctor(Uri uri, Uri homeRealmUri, ClientCredentials clientCredentials, ClientCredentials deviceCredentials)在 Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy..ctor(Uri uri, Uri homeRealmUri, ClientCredentials clientCredentials, ClientCredentials deviceCredentials)在 ElevateCRMAccess.fmElevateCRMAcces.btnElevate_Click(对象发件人, System.Windows.Forms.Control.OnClick(EventArgs e)
处的 EventArgs e) 在 System.Windows.Forms.Button.OnClick(EventArgs e) 在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs 事件) 在 System.Windows.Forms.Control.WmMouseUp(消息和 m,鼠标按钮 按钮,Int32 点击)在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.ButtonBase.WndProc(Message& m) 在 System.Windows.Forms.Button.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息& m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我使用以下行通过 ILMERGE 合并程序集:
"$(SolutionDir)ILMERGE/IlMerge.exe" /target:winexe /targetplatform:"v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319" /out:"$(SolutionDir)..\Output\ConnectToCRM.exe" "$(TargetDir)ConnectToCRM.exe" "$(TargetDir)Microsoft.Crm.Sdk.Proxy.dll" "$(TargetDir)Microsoft.Xrm.Sdk.dll"
请有人帮忙找出这里的问题。是什么导致合并的 exe 失败。
【问题讨论】:
标签: c# dynamics-crm dynamics-365 ilmerge