Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Native compilation and WMI #8184

Closed
olegsavelos opened this issue Jun 3, 2020 · 1 comment
Closed

Native compilation and WMI #8184

olegsavelos opened this issue Jun 3, 2020 · 1 comment

Comments

@olegsavelos
Copy link

I am experimenting with native compilation with .NET 5 and having troubles with executing code that contains references to WMI.

Here is an example code

public class NativeLibrary { [NativeCallable(EntryPoint = "authorize", CallingConvention = CallingConvention.StdCall)] public static IntPtr Authorize() { var m = new System.Management.ManagementClass("Win32_BIOS"); return IntPtr.Zero; } }

When called this exception error is printed in console window

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Common Language Runtime detected an invalid program. The body of method 'Void System.Management.WbemDefPath..ctor()' is invalid. at Internal.Runtime.TypeLoaderExceptionHelper.CreateInvalidProgramException(ExceptionStringID, String) + 0x40 at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowInvalidProgramExceptionWithArgument(ExceptionStringID, String) + 0x9 at System.Management.WbemDefPath..ctor() + 0x15 at NativeLibrary!<BaseAddress>+0x23dd59 at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x25d --- End of inner exception stack trace --- at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x414 at Internal.Reflection.Execution.MethodInvokers.InstanceMethodInvoker.Invoke(Object, Object[], BinderBundle, Boolean) + 0x7f at Internal.Reflection.Core.Execution.MethodInvoker.Invoke(Object, Object[], Binder, BindingFlags, CultureInfo) + 0x46 at System.Reflection.Runtime.MethodInfos.RuntimePlainConstructorInfo1.Invoke(BindingFlags, Binder, Object[], CultureInfo) + 0x90
at System.ActivatorImplementation.CreateInstance(Type, Boolean) + 0xb7
at System.Management.MTAHelper.CreateInMTA(Type) + 0x37
at System.Management.ManagementPath.CreateWbemPath(String) + 0x1d
at NativeLibrary!+0x6a68d`

There is not much information that i could find but as i understand it has to do with COM interop?

@jkotas
Copy link
Member

jkotas commented Jun 3, 2020

Yes, this looks like a problem with COM interop. CoreRT does not support COM interop currently. This is tracked by #4219 .

Also, NativeCallableAttribute was renamed to UnmanagedCallersOnlyAttribute as part of making it official public .NET API (dotnet/runtime#35433). But that is not the root cause of the problem that you are seeing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants