none
Trying to call into .NETCore from .NETFramework RRS feed

  • Question

  • So I did some simple test.  Opened VS 2019, and created a new solution

    Added three projects

    1. TestExe, using .NET Framework 4.6.1
    2. StdDll, using .NetStandard 2.0
    3. CoreDll, using .NETCore 2.0

    All compiles well...

    Adding a reference from StdDll to TestExe works ok.  I can do call from TestExe into StdDll

    Adding Reference from CoreDll to TestExe does not work. Get compile error

    Adding Reference from CoreDll to StdDll does not work. Get compile error

    The compile error is: Project CoreDLL is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Project CoreDLL supports: netcoreapp2.0 (.NETCoreApp,Version=v2.0)

    So, where is the problem here.  I was in the impression that I could use .NETStandard as a layer between .NETFramework and .NETCore

    Reason I have to get this to work is because we have an existing solution already written in .NETFramework and I nead to use a WEB service where the client DLL is written with .NETCore 2.1

    Regards

    Ole


    ------------------------------------------- Ole Morten Heien HD Software / Advisor AS -------------------------------------------

    Wednesday, August 14, 2019 1:13 PM

All replies

  • Hi,

    You cannot call into .NET Core from .NET Framework and you cannot call into .NET Framework from .NET Core.

    You can only call into .NET Standard from both .NET Framework and .NET Core (if the .NET Standard version is correct based on the .NET Framework and .NET Core).

    Answering your question: you can only call into the Client DLL from .NET Framework if the Client DLL is written using .NET Standard or .NET Framework.

    Kind regards,

    Johnny Hooyberghs


    Wednesday, August 14, 2019 1:44 PM
  • Really!!!   That was a bummer!!!

    I have a Library written in .NETFramework already and its nothing I would like to rewrite. And I have to utilize a New WEB Service provided by one of Our vendors.  They provide a DLL written in .NETCore

    So if Your right, I cannot use it.  I have to as for a New one…. written for .NETFramework..


    ------------------------------------------- Ole Morten Heien HD Software / Advisor AS -------------------------------------------

    Wednesday, August 14, 2019 2:57 PM
  • I'm sorry for bringing you bad news.

    The point of .NET Standard is indeed to bridge the gap between .NET Framework and .NET Core. If a vendor wants his library to be compatible from both .NET Framework and .NET Core, it should be written using .NET Standard.

    .NET Framework and .NET Core are different runtimes that cannot run within the same process. .NET Standard is not a runtime, but an intersection between the API's for both the frameworks. Classes that are only available in .NET Framework are not available in .NET Standard and classes that are only available in .NET Core are not available in .NET Standard. Only classes that are available in both .NET Framework and .NET Core are available in .NET Standard.

    An assembly written using .NET Standard will be loaded into the .NET Framework or .NET Core process, and cannot run by itself.

    Since runtimes cannot be mixed within one process, calling from .NET Core into .NET Framework or from .NET Framework in .NET Core  is not possible.

    Kind regards,

    Johnny Hooyberghs

    Wednesday, August 14, 2019 3:14 PM
  • hmm.  Someone told me to change the target in the Project XML to this:

    <TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>

    Note the added s and multiple targets.  Havent tested it yet, but he claims that this ctually Works...


    ------------------------------------------- Ole Morten Heien HD Software / Advisor AS -------------------------------------------


    • Edited by Ole Morten Wednesday, August 14, 2019 3:19 PM
    Wednesday, August 14, 2019 3:18 PM
  • The only thing that that will do is compile your project to both framework targets. (compiling into separate DLL's).

    You could do this to the vendor client DLL, but I guess you don't have access to its source to compile a new one.

    Wednesday, August 14, 2019 3:28 PM
  • If it does, wil they both contain the thirdparty .NETCore service ?

    ------------------------------------------- Ole Morten Heien HD Software / Advisor AS -------------------------------------------

    Thursday, August 15, 2019 6:45 AM
  • Hi Ole,

    >>wil they both contain the thirdparty .NETCore service

    You are right, .net standard contains the third party .net core service.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, August 15, 2019 8:21 AM
    Moderator
  • Not sure I understand what your saying here.  I asked if both the compiled components (.NetCore and .NetFramework) wil actually contain support for the WEB service component I have to use.

    If so, can I just delete the compiled .NETCore DLL and distribute the .NETFramework compiled binary?   


    ------------------------------------------- Ole Morten Heien HD Software / Advisor AS -------------------------------------------

    Thursday, August 15, 2019 8:35 AM