Description
When a project is set as PublishAot = true, and the OutputType = Library, and when trying to dynamically load said library within another application and call WinRT related functions, the following exception is thrown:
Unhandled exception. System.NotSupportedException: The managed type 'System.Object' does not have any associated marshalling info. This should never be the case
. Please file an issue at https://github.com/microsoft/CsWinRT.
at WindowsRuntime.InteropServices.WindowsRuntimeComWrappers.GetOrCreateComInterfaceForObject(Object) + 0x1dd
at WindowsRuntime.InteropServices.Marshalling.WindowsRuntimeInterfaceMarshaller`1.ConvertToUnmanaged(T, Guid&) + 0xa3
at ABI.Windows.Devices.Enumeration.IDeviceInformationStatics2Methods.FindAllAsync(WindowsRuntimeObjectReference, String, IEnumerable`1, DeviceInformationKind
) + 0xca
...
Otherwise, when the same project is compiled as an Exe, there are no exceptions and it works.
I currently do not have a minimal repro, although I will try to provide one.
Steps To Reproduce
- Prepare a project of type
OutputType=Library, and set PublishAot=true.
- Export a simple function (using
UnmanagedCallersOnly) within the project which calls any WinRT-related function or component (for example, DeviceInformation.FindAllAsync()).
- Compile the project.
- Dynamically load the built NativeAOT library into any other application, and call the exported function.
Expected Behavior
The application does not throw an exception.
Version Info
CsWinRT version: 3.0.0-preview260319.2
NET SDK: net10.0-windows10.0.19041.1
Additional Context
Specifically, what I have observed is:
- The
TypeMapAssemblyTarget generator usually generates all the assembly attributes required for the application to function when the OutputType=Exe and PublishAot=true.
- When
OutputType=Library and PublishAot=true, the generator is disabled, and the project compiles without the necessary assembly attributes.
Description
When a project is set as
PublishAot = true, and theOutputType = Library, and when trying to dynamically load said library within another application and call WinRT related functions, the following exception is thrown:Otherwise, when the same project is compiled as an
Exe, there are no exceptions and it works.I currently do not have a minimal repro, although I will try to provide one.
Steps To Reproduce
OutputType=Library, and setPublishAot=true.UnmanagedCallersOnly) within the project which calls any WinRT-related function or component (for example,DeviceInformation.FindAllAsync()).Expected Behavior
The application does not throw an exception.
Version Info
CsWinRT version: 3.0.0-preview260319.2
NET SDK: net10.0-windows10.0.19041.1
Additional Context
Specifically, what I have observed is:
TypeMapAssemblyTargetgenerator usually generates all the assembly attributes required for the application to function when theOutputType=ExeandPublishAot=true.OutputType=LibraryandPublishAot=true, the generator is disabled, and the project compiles without the necessary assembly attributes.