14

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.

Tamas Molnar
  • 797
  • 2
  • 9
  • 25

3 Answers3

22

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

Daniel Holth
  • 357
  • 2
  • 5
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.

Alan Mervitz
  • 507
  • 5
  • 15
  • 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.1 – Tamas Molnar Oct 29 '18 at 13:02
  • @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. – Alan Mervitz Oct 29 '18 at 17:03
  • 2
    Thanks. I ended up using CRM REST OData Web Api instead. I have set it up following this articles http://www.wrapcode.com/server-authentication-dynamics-crm/, https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/use-multi-tenant-server-server-authentication and this code sample https://github.com/jlattimer/CrmWebApiCSharp/blob/master/CrmWebApiCSharpNoAdal/Program.cs – Tamas Molnar Oct 31 '18 at 09:18
  • 1
    @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+ – joedotnot Mar 08 '23 at 04:06
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

Alessi
  • 759
  • 3
  • 11