0

I've got a DLL library compiled in .NET Framework 4.6.1. It uses Microsoft.SqlServer.SqlManagementObjects v.140.17283.0 and Unofficial.Sql.Server.Management.Objects v17.4.1 that I've installed from NuGet. All works fine.

Now I want to use this library in a NetCoreApp2.1 project. I referenced the DLL and the dependencies. But when I instance an object that creates a Server Object it crashes. The line that go error is:

 sourceServer = new Server(GeneralSettings.Default.ServerNameSource);

and the error is:

Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I think that .NetCoreApp uses a System.Data different from the library.

How can I fix this?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Lic
  • 1,757
  • 3
  • 14
  • 16
  • "I've got a DLL library compiled in .NET Framework 4.6.1. " When it is compiled against .NET 4.x it won't necessarily run in .NETcore. (core is multiplatform and does not support everything that the regular version does.) it doesnt mean it cannot run in netcore but there are NO guarantees and any incompatible (i.e. not meant for core) dependencies should be avoided. – Daan Dec 12 '18 at 09:47

1 Answers1

0

This issue is occured in .net core 2.0 and persisted in .net core 2.1.

In order to solve it you can reference Microsoft.SqlServer.SqlManagementObjects.

There is a thread also in github regarding the issue.

Here is the official reply to the post:

Yes that is a library built against .NET Framework which is referencing types that don't exist in .NET Core. While we have done a lot of porting in .NET Core 2.0 the types this library needs aren't all present yet. So unfortunately this library will not run on .NET Core.

Barr J
  • 10,636
  • 1
  • 28
  • 46
  • 1
    Thank, I tryed to update to v. 150 of Microsoft.SqlServer.SqlManagementObjects but nothing change. I think I will wait that Microsoft.SqlServer.SqlManagementObjects includeMicrosoft.SqlServer.Server.SqlContext type.. – Lic Dec 13 '18 at 16:52