Using Dynamics CRM SDK with .NET Core
Asked Answered
E

3

15

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.

Exhaustion answered 24/10, 2018 at 13:34 Comment(0)
T
11

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.

Tyndareus answered 27/10, 2018 at 19:23 Comment(4)
Thanks for the suggestion. Can I still reference my other .net core projects in VS? I get an error: Project X is not compatible with net461. Project X supports: netcoreapp2.1Exhaustion
@manipurea I mispoke in the statement "allows for the use of other .NET Core class libraries". Your .NET Framework project can reference class libraries that implement .NET standard class libraries though. If you can switch your .NET Core projects to instead target .NET standard it should work.Tyndareus
Thanks. I ended up using CRM REST OData Web Api instead. I have set it up following this articles wrapcode.com/server-authentication-dynamics-crm, learn.microsoft.com/en-us/dynamics365/customer-engagement/… and this code sample github.com/jlattimer/CrmWebApiCSharp/blob/master/…Exhaustion
@AlanMervitz or someone else, what's the status of this answer in 2023 ? Please provide an update, given that from .NET Core 3.0 and above, it is no longer possible to Target the Full .NET Framework 4.6.x+Lashay
T
26

You should try the latest Dataverse SDK. It uses .NET Core and supports Dynamics CRM 365 CE. 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(connectionString);

This screenshot is from Visual Studio: NuGet Package Manager

Tindal answered 24/3, 2020 at 18:19 Comment(3)
Note that this one is deprecated and have been replaced by Microsoft.PowerPlatform.Dataverse.ClientHarpole
Thank you @Mixxiphoid. I have updated the post and the image to reflect the changesTindal
Note Microsoft.PowerPlatform.Dataverse.Client is the new namespace to import, the actual replacement type is ServiceClient so the new line should be Microsoft.PowerPlatform.Dataverse.Client.ServiceClient(connectionString)Blume
T
11

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.

Tyndareus answered 27/10, 2018 at 19:23 Comment(4)
Thanks for the suggestion. Can I still reference my other .net core projects in VS? I get an error: Project X is not compatible with net461. Project X supports: netcoreapp2.1Exhaustion
@manipurea I mispoke in the statement "allows for the use of other .NET Core class libraries". Your .NET Framework project can reference class libraries that implement .NET standard class libraries though. If you can switch your .NET Core projects to instead target .NET standard it should work.Tyndareus
Thanks. I ended up using CRM REST OData Web Api instead. I have set it up following this articles wrapcode.com/server-authentication-dynamics-crm, learn.microsoft.com/en-us/dynamics365/customer-engagement/… and this code sample github.com/jlattimer/CrmWebApiCSharp/blob/master/…Exhaustion
@AlanMervitz or someone else, what's the status of this answer in 2023 ? Please provide an update, given that from .NET Core 3.0 and above, it is no longer possible to Target the Full .NET Framework 4.6.x+Lashay
S
0

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

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

Selfdrive answered 25/10, 2018 at 0:5 Comment(1)
I believe "or above" is incorrect - .net4.62 - .net48. .net5+ won't support System.Web.Tributary

© 2022 - 2024 — McMap. All rights reserved.