Microsoft Dynamics 365 SDK Core Assemblies .NET Core 移植错误 [英] Microsoft Dynamics 365 SDK Core Assemblies .NET Core Porting Error

查看:35
本文介绍了Microsoft Dynamics 365 SDK Core Assemblies .NET Core 移植错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试在 .NET Core 2.0 项目,在运行时仅通过使用 Microsoft.Xrm.Sdk 就会出现以下错误:

When trying to use Microsoft Dynamics 365 SDK Core Assemblies in a .NET Core 2.0 project, the following error occurs at runtime simply by using Microsoft.Xrm.Sdk:

TypeLoadException: 无法加载类型'System.ServiceModel.Description.MetadataConversionError'来自程序集System.ServiceModel,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089'.

TypeLoadException: Could not load type 'System.ServiceModel.Description.MetadataConversionError' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

看起来核心程序集 (Microsoft.Xrm.Sdk.Client) 可能与 ~net4x 以外的任何东西都不兼容.

It looks like the Core Assemblies (Microsoft.Xrm.Sdk.Client) may simply not be compatible with anything other than ~net4x.

是否有任何明显的方法可以绕过此错误或在目标上下文中加载 Microsoft.Xrm.Sdk 所需的 WCF System.ServiceModel 类/接口<代码>netcoreapp2.0?是否可以使用Microsoft.Windows.Compatibility 来弥补差距?它看起来像 Microsoft.Windows.Compatibility 包 文档 表示 Windows Communication Foundation (WCF) 类/接口可用".我如何使用兼容包来加载 System.ServiceModel.Description?

Is there any obvious way to get around this error or load the WCF System.ServiceModel class/interfaces needed by Microsoft.Xrm.Sdk in the context of target netcoreapp2.0? Is it possible to use Microsoft.Windows.Compatibility to bridge the gap? It looks like the Microsoft.Windows.Compatibility pack documentation indicates Windows Communication Foundation (WCF) classes/interfaces are "available". How can I use the compatibility pack to perhaps load System.ServiceModel.Description?

感谢您提供的任何帮助!

Thank you for any help you can provide!

推荐答案

根据 github 上的多次讨论,我尝试了所有可能的方法,可以说 SDK、ServiceModel 等与 .net 核心不兼容,而且永远不会兼容.但是,我能够做到这一点:

I tried all possible things and can say that SDK, ServiceModel etc are not compatible with .net core and never will be, according to multiple discussions on github. However, i was able to do this:

  • 使用 XrmToolBox 和 crmsvcutil.exe 生成模型(可选)
  • 将它们放在 netstandard2 项目中
  • 从 nuget 引用 XRM SDK
  • SDK 在 .net 核心下工作,部分 LINQ 查询和原始 QueryExpressions 被转换为 OrganizationRequest 的子类
  • 编写自定义 IOrganizationService 来序列化 OrganizationRequests 并将它们发送到其他一些应用
  • 其他应用程序是 .net core web api,它引用了该项目和 XRM SDK,但在 windows 上的完整框架 上运行并执行实际请求、序列化响应并将它们发回.
  • Use XrmToolBox and crmsvcutil.exe to generate models (optional)
  • place them in netstandard2 project
  • reference XRM SDK from nuget
  • SDK works under .net core in part where LINQ queries and raw QueryExpressions are translated to subclasses of OrganizationRequest
  • write custom IOrganizationService which serializes OrganizationRequests and sends them to some other app
  • Other app is .net core web api which references that project and XRM SDK, but runs on full framework on windows and executes actual requests, serializes responses and sends them back.

重要我发现由于各种原因,SDK 2016 在 linux 上的 .net core 中不能可靠地工作,并在 2011 年停止(nuget 包是 Microsoft.Xrm.Sdk.2011).它工作正常,但在一种情况下:当您执行 context.AddObject 并传递一个 没有 ID 的实体时.SDK 依赖 p/invoking 本机 Windows 库来创建顺序 UUID 并在 Linux 上崩溃.您可以通过在调用 .AddObject() 之前设置 ID 来克服这个问题.

IMPORTANT I found out that SDK 2016 doesn't work reliably in .net core on linux due to various reasons, and stopped at 2011 (nuget package is Microsoft.Xrm.Sdk.2011). It works fine except in one case: whe you do context.AddObject and pass an Entity with no ID. SDK relies on p/invoking native Windows library to create sequential UUID and crashes on Linux. You can overcome this by setting ID prior to calling .AddObject().

这篇关于Microsoft Dynamics 365 SDK Core Assemblies .NET Core 移植错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆