6

I have been trying to follow some already existing tutorials and stackoverflow questions/answers, but nothing seems to be working;

I am working in Visual Studio 2019 V16.0.0 Preview 2.2, if that is relevant.

TheRealVira
  • 1,444
  • 4
  • 16
  • 28
  • 1
    _"nothing seems to be working"_ is not a question. What is expected and a real behavior of your code? – vasily.sib Feb 12 '19 at 09:52
  • @vasily.sib well, of course I am trying to reference my said library in one of my .net framework projects. Since .NET Core is corss platform compatible my goal is to use said library in my .NET 4.8 project. – TheRealVira Feb 12 '19 at 09:54
  • ok, and what happens when you try to follow recomendations from one of this links that you provide? – vasily.sib Feb 12 '19 at 09:56
  • 1
    Yes, but .NET Core is moving forwards faster than .net framework. If you want to reference libs from both, the libs should be .NET Standard, not Core, and Standard doesn't match what you can do in Core – Damien_The_Unbeliever Feb 12 '19 at 09:56
  • 8
    .NET Core and .NET Framework are different frameworks; I wouldn't *expect* this to work; if you want a library that is consumable from both, AFAIK it needs to either multi-target (i.e. have .NET Core and .NET Framework targets), or target .NET Standard. Or, to cover all bases: multi-target *including all 3* (.NET Core, .NET Framework, .NET Standard) - useful when you can exploit framework-specific features, with .NET Standard as the least-common-denominator fallback – Marc Gravell Feb 12 '19 at 09:57

1 Answers1

1

As mentioned by Marc Gravell, .NET Core and .NET Framework are different frameworks. The Api Surface that each of them offer is different. A good way to picture their surface area is by using a Venn Diagram, where the intersection of both is what we call .NET Standard. If the library you are consuming was targeting .NET Standard, then this would be guaranteed to work in both .NET Framework 4.8 and in .NET Core 2.1+. You can try consuming a .NET Core 3.0 library in a .NET Framework app but that is not guaranteed to work, as you might get lucky and your .NET Core library only needs the API surface that they have in common, but most likely it will need something that is only supported in .NET Core 3.0 which will mean that you will get Runtime Exceptions for methods not found, types not found, or assembly load issues.

Do you own the .NET Core Library code? If so, the best option for you would be to try to retarget to .NET Standard (so that you can use the library in the future in other frameworks) or .NET Framework directly, and that way you would know that all of the API surface your library needs will be present at runtime.

I hope this helps clarifying the issue, but feel free to reply in case you want more details.