NetCoreApp2.1 System.Data reference error

559 Views Asked by At

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?

1

There are 1 best solutions below

1
Barr J On

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.