1

I want to create a library for ASP.NET Core in VS17 that uses System.Data.SqlClient for accesing database. I picked .NET Core Library Class. The problem is that I'm getting errors like :

CS0012 The type 'Object' is defined in an assembly that is not >referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, >Culture=neutral, PublicKeyToken=b77a5c561934e089'.

On stackoverflow I found a thread with advice to add NuGet package : Microsoft.NETCore.Portable.Compatibility, but then it just throws following exception :

FileNotFoundException: Could not load file or assembly 'System.Data, >Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I tried getting other library types like .NET Standard or .NET Framework, but I am also getting errors e.g. some types from standard System.Data.SqlClient are unavailable.

Is there a way to create a library for ASP.NET Core that uses SqlClient for accesing database then?

GrayCat
  • 1,749
  • 3
  • 19
  • 30
  • does this help? https://stackoverflow.com/questions/35444487/how-to-use-sqlclient-in-asp-net-core – Hassan Khallouf Aug 18 '17 at 22:16
  • 2
    Well, you went off into the weeds. SqlClient is included in .net core. You are, for some unknown reasons, referencing the .net framework version. – Erik Funkenbusch Aug 18 '17 at 22:23
  • I tried to do it this way : http://www.c-sharpcorner.com/UploadFile/66489a/creating-C-Sharp-class-library-dll-using-visual-studio-2015-pre/ But it turned quite more complicated as I got more than one type of library to choose from. I've been using SqlClient in my previous Net Core apps, thats why I was amazed at getting those errors, while trying to place some methods in separate library – GrayCat Aug 19 '17 at 06:29

1 Answers1

0

I had a similar problem of your. Try simply run dotnet restore myProjectName on package manager console or on command prompt.

In this way the packages and SDK's on your project are download and reference problems will go away.

Kukic Vladimir
  • 1,010
  • 4
  • 15
  • 22
DaniloRO
  • 1
  • 1