-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Closed
Description
CustomAssemblyLoaderContext throws PlatformNotSupportedException when invoking an assembly that uses the System.Management package
We have two projects: an Executable and a Loader.
The Executable is a .NET Core 2.0 application that uses the System.Management package to obtain the operating system information. This project is published with the following settings:
- Deployment Mode: Framework Dependent.
- Target Runtime: Portable.
The Loader is a .NET Core 2.0 application that loads the assemblies of the Executable project at runtime.
If we execute the Executable project with dotnet, we obtain the operating system information correctly. However, if we load and invoke the Executable project with the Loader, an exception occurs:
System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=System.Private.CoreLib
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Loader.Program.Main(String[] args) in D:\W\JP\Temp\Loader\Loader\Program.cs:line 15
Inner Exception 1:
PlatformNotSupportedException: System.Management currently is only supported for Windows desktop applications.
To solve this, we have to publish the Executable project for Windows instead of Portable.
Why when the Executable is Portable works with the dotnet command and not with the Loader project?
Code sample:
Loader.zip
Suriman, alexdrl and VictorIranzo
Metadata
Metadata
Assignees
Labels
No labels