4

I have a package that is built using .net Standard 2.0. I want to be able to utilise it in both .net Framework and .net Core applications but it has the following line of code:

using System.Runtime.Loader;

…

AssemblyLoadContext.Default.Unloading += (ctx) => ProcessStop();
…

This doesn't work for the .net Framework (seems like the System.Runtime.Loader is a core only package). I can omit it at compile time using this sort of statement:

#if NETCOREAPP2_0 || NETCOREAPP2_1
            AssemblyLoadContext.Default.Unloading += (ctx) => ProcessStop();
#endif

Which doesn't help me when the package is compiled already and I want to use it in .net Framework. Anyone know how to do this sort of thing inline?

Thanks for any pointers in advance!

1
  • 3
    What do you mean by "it doesn't work"? Do you get run time errors? Compile errors? Do sharks eat your computer when you press F5? Commented Sep 25, 2018 at 16:03

1 Answer 1

2

It seems that there is an issue with AssemblyLoadContext (or the System.Runtime.Loader package to be precise) according to https://github.com/dotnet/cli/issues/6019 The package claims to support .NET-Framework (and netstandard1.5) but apparently doesn't. So yes, System.Runtime.Loader seems to be a core-only package - what absolutely perverts the concept of .NET-Standard in my opinion...

The consequence of this now is, that the .NET-Standard 2.0 package you mentioned does not really support .NET-Standard 2.0, but .NET-Core >= 1.0 (from the System.Runtime.Loader point of view). I don't see any chance to make an already compiled version without that mentioned switch work with .NET-Framework.

Anyone know how to do this sort of thing inline?

When providing the mentioned library as NuGet-package, there is the posibility to extract runtime-specific implementations to runtime-specific DLLs: https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks But this, of course, implies recompiling the package.

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

Comments

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.