Create a new application that references CsWin32 as well as the Windows Runtime APIs. Add this to Program.cs:
using Windows.System;
using Windows.Win32.System.WinRT;
unsafe
{
Windows.Win32.PInvoke.CreateDispatcherQueueController(new DispatcherQueueOptions()
{
dwSize = (uint)sizeof(DispatcherQueueOptions),
apartmentType = DISPATCHERQUEUE_THREAD_APARTMENTTYPE.DQTAT_COM_NONE,
threadType = DISPATCHERQUEUE_THREAD_TYPE.DQTYPE_THREAD_DEDICATED
}, out DispatcherQueueController dpc);
}
The application will crash when calling CreateDispatcherQueueController with the following exception:
An unhandled exception of type 'System.TypeLoadException' occurred in ConsoleApp1.dll
Could not load type 'Windows.Win32.CsWin32.InteropServices.WinRTCustomMarshaler' from assembly 'ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Manually copying the code for WinRTCustomMarshaler into the application seems to resolve the issue.
Repro steps
NativeMethods.txt content:
CreateDispatcherQueueController
Context
CsWin32 version: Have reproed on 0.1.560-beta and 0.1.565-beta from the feed
Target Framework: Have reproed on net6.0 and netcoreapp3.1
Actual behavior
Create a new application that references CsWin32 as well as the Windows Runtime APIs. Add this to Program.cs:
The application will crash when calling
CreateDispatcherQueueController
with the following exception:Manually copying the code for
WinRTCustomMarshaler
into the application seems to resolve the issue.Repro steps
NativeMethods.txt
content:Context
0.1.560-beta
and0.1.565-beta
from the feednet6.0
andnetcoreapp3.1