Skip to content

CustomAssemblyLoaderContext throws PlatformNotSupportedException when invoking an assembly that uses the System.Management package #1913

@ADD-Juan-Perez

Description

@ADD-Juan-Perez

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions