8
votes

Is there a way to connect to Dynamics CRM 365 from a .NET Core application via the Dynamics SDK? Or should I use the Web Api?

I've read it could be possible, but when I reference the SDK from my .NET Core Class Library and try to connect I get the error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Web.Services..

It seems like this DLL is not supported in .NET Core: How to use soap web services in Asp.net Core?

My code is like this:

 new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);

I could succesfully make it work from a .NET Framework project.

3

3 Answers

10
votes

There is a distinction to be made between applications that use the .NET Core runtime vs. the .NET Core framework. As you've found out, the Dynamics 365 SDK does not currently work with the .NET Core runtime, however it does work with the .NET Core framework when the .NET Core project targets the .NET Framework runtime using the .NET Framework's target framework moniker (TFM) setting in the project file. For example with a .NET Core console application, the .csproj file would look like this (notice the TargetFramework):

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CrmSdk.CoreAssemblies" Version="9.0.2.5" />
  </ItemGroup>

</Project>

Such applications will not be cross-platform and only be executable on Windows, but still allows for the use of other .NET Standard class libraries and frameworks such as ASP.NET Core that implement .NET Standard while executing on the .NET Framework runtime. Eventually if the Dynamics 365 SDK is ever updated to work on the .NET Core runtime, the project file's target framework monitor value can be changed to .NET Core and become cross-platform.

8
votes

You should try the new CDM SDK. It uses .NET Core and supports Dynamics CRM 365. https://www.nuget.org/packages/Microsoft.PowerPlatform.Dataverse.Client

Just remember to replace:

new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString);

With this:

new Microsoft.PowerPlatform.Dataverse.Client.ServiceClient(connectionString);

Make sure you select Include prerelease. Package Management Screen

0
votes

Unfortunately you need .NET Framework 4.6.2 or above to build custom applications.

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/visual-studio-dot-net-framework