Microsoft Dynamics 365 SDK Core Assemblies .NET Core Porting Error

10,544

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:

  • 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.

IMPORTANT EDIT: 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().

Share:
10,544

Related videos on Youtube

Alexander Staroselsky
Author by

Alexander Staroselsky

Updated on September 15, 2022

Comments

  • Alexander Staroselsky
    Alexander Staroselsky over 1 year

    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: Could not load type 'System.ServiceModel.Description.MetadataConversionError' from assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

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

    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!

  • Mike Brunner
    Mike Brunner over 4 years
    Can you add more details on how to accomplish these steps? I don't see how you can reference the XRM SDK from a netstandard project. Also, your last step says "other app is .net core web api"...should that be .NET framework? Seems like a typo.
  • Rast
    Rast over 4 years
    You just reference nuget package i mentioned. It warns you that it may not work, as usual with other nuget packages which do not target netstandard. Just ignore the warning. And the latter thing, i am just used to call projects with controllers and without pages as web api. Sure it is not that web api from the past, i meant aspnetcore application with http api. Which targets netcore, but runs on full framework.