2

I have .NET Core console app that references a data layer project in the same solution, and I have met with an error that I cannot resolve.

Job is .NET Core 2.0.

Project is .NET Framework 4.8.

Error

1 Answer 1

3

You need to have your data library target .NET Standard 2.0 instead of .NET Framework 4.8.

.NET Core and the .NET Framework are different frameworks.

You cannot reference a .NET Framework library from .NET Core, as this diagram from Microsoft illustrates:

enter image description here

To resolve this, Microsoft introduced .NET Standard for class libraries:

enter image description here

.NET Core 2.0 and higher, and .NET Framework 4.6.1 (but preferably higher) can both reference libraries which target .NET Standard 2.0 and lower - see implementation support on the .NET Standard documentation.

You need to re-target your library to .NET Standard 2.0. If any APIs are missing in .NET Standard which your library needs they may be available as NuGet packages instead - you can look these up on apisof.net.

Note that if you're using LINQ to SQL in your data library you're out of luck as that is full .NET only and not available to .NET Standard or .NET Core projects.

The above diagrams were sourced from Introducing .NET Standard

Sign up to request clarification or add additional context in comments.

3 Comments

Extremely helpful information. My project is just too out of date for what I wanted to do. oof. I suppose I can create a console app in a downgraded version before I fully convert. I didn't realize that about LINQ to SQL.. I'm in trouble there as well. I really appreciate your response.
I have to understand best practices on that before I upgrade. I'm always very grateful to those who spend time helping others. This took up a lot of my time!
Thought I would add a link that I found helpful.. some of my async code in the console app was causing things to throw errors that crashed the program. I was using linq to sql, but also async methods. recaffeinate.co/post/how-to-await-console-application

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.