.NET Cross-Framework referencing

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

Assume, there is a .NET Framework application called NetDesktopApp and .NET Core library NetCoreLib2.
Further, NetCoreDesktopApp references NetCoreLib2.
Implementation of NetCoreLib2 looks like:

using System;

namespace NetCoreLib2
{
    public class MyNetCoreLib2
    {
        public static string Go(long a)
        {
            return a++.ToString();
        }
    }
}

Implementation of NetCoreDesktopApp looks like:

namespace NetDesktopApp
{
    class Program
    {
         static void Main(string[] args)
        {      
            Console.WriteLine(MyNetCoreLib2.Go(DateTime.Now.Ticks));
         }
    }

When a .NET application starts, then following libraries are loaded.

image

Please note assembly netstandard.dll. This assembly is implicitly injected in the project by Visual Studio, when .NET Core assembly is referenced. The purpose of that assembly is to do type forwarding.

.NET Framework Application

Before .NET Core, thinks looked simpler. Typical .NET Framework minimal application loads following assemblies if no .NET Core libraries are referenced.

image

As you see, only two assemblies are loaded. Your application and  runtime assembly. If you take a look on such project in VS, you will notice much more assemblies. However they are not loaded if not used.

.NET Core Application

Now, let’s take a look what happen if .NET Core application is loaded. In this case no mscorelib.dll is loaded, because it is not a part of .NET Core. But note, this time System.Runtime.Dll is loaded.

image

.NET Core Application with reference to .NET Standard library

In this case, I have same .NET Core application, which this time references a .NET Standard library. When started .NET Core application will  load one additional assembly StandardLibrary.dll.

image

.NET Core Application with reference to .NET Standard library, which references .NET Framework assembly

In this example, I have created .NET Core application (NetCoreApp), which references .NET Core Library (NetCoreLib), which finally references a .NET Framework library (NetDesktopLib2). There is also .NET Framework Library (NetDesktopLib), which is referenced from application too.

In this case, System.Rrntime is loaded from .NET Core and also mscorelib from .NET Framework.

image


Posted Sep 17 2017, 05:24 PM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.