CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

DllModule does not work with PublishSingleFile

Open eerhardt opened this issue 2 years ago • 2 comments

Describe the bug

https://github.com/microsoft/CsWinRT/blob/205d2e4233fe7d44cda0192bd09c01e66a8e7ffc/src/cswinrt/strings/WinRT.cs#L98

That code does not work when publishing your app as <PublishSingleFile>true</PublishSingleFile>. See https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file/warnings/il3000. Assembly.Location returns string.Empty in a single file.

You later end up with a ArgumentNullException in Path.Combine:

0:000> !pe
Exception object: 0000012dd07f2e88
Exception type:   System.ArgumentNullException
Message:          Value cannot be null.
InnerException:   <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 80004003
0:000> !clrstack
OS Thread Id: 0x3830 (0)
        Child SP               IP Call Site
000000074E57C548 00007ffb03f24f69 [HelperMethodFrame: 000000074e57c548] 
000000074E57C640 000000018039df02 System.IO.Path.Combine(System.String, System.String) [/_/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs @ 324]
000000074E57C680 00007ff60ddc1340 WinRT.DllModule.TryCreate(System.String, WinRT.DllModule ByRef)
000000074E57C6F0 00007ff60ddc1194 WinRT.DllModule.TryLoad(System.String, WinRT.DllModule ByRef)
000000074E57C750 00007ff60ddc0c41 WinRT.BaseActivationFactory..ctor(System.String, System.String)
000000074E57C7C0 00007ff60ddc0785 WinRT.ActivationFactory`1[[System.__Canon, System.Private.CoreLib]]..ctor()
000000074E57C830 00000001801d4fb3 System.RuntimeType.CreateInstanceOfT() [/_/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs @ 3782]
000000074E57C880 00000001805009e5 System.Activator.CreateInstance[[System.__Canon, System.Private.CoreLib]]() [/_/src/libraries/System.Private.CoreLib/src/System/Activator.RuntimeType.cs @ 140]
000000074E57C8C0 00007ff60ddc0640 WinRT.WeakLazy`1[[System.__Canon, System.Private.CoreLib]].get_Value()
000000074E57C930 00007ff60ddc03ed WinRT.ActivationFactory`1[[System.__Canon, System.Private.CoreLib]].ActivateInstance[[WinRT.Interop.IUnknownVftbl, WinRT.Runtime]]()
000000074E57C970 00007ff60ddc0333 Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl..ctor()
000000074E57C9B0 00007ff60ddc0281 Microsoft.Maui.Graphics.Win2D.W2DGraphicsView.UserControl_Loaded(System.Object, Microsoft.UI.Xaml.RoutedEventArgs)
000000074E57CA00 00007ff60ddc0218 WinRT._EventSource_global__Microsoft_UI_Xaml_RoutedEventHandler+EventState.b__1_0(System.Object, Microsoft.UI.Xaml.RoutedEventArgs) [D:\a\_work\1\s\BuildOutput\obj\amd64fre\src\projection\generated\WinRTEventHelpers.cs @ 7874]
000000074E57CA40 00007ff60ddbfdfc ABI.Microsoft.UI.Xaml.RoutedEventHandler+c__DisplayClass10_0.<Do_Abi_Invoke>b__0(Microsoft.UI.Xaml.RoutedEventHandler) [D:\a\_work\1\s\BuildOutput\obj\amd64fre\src\projection\generated\Microsoft.UI.Xaml.cs @ 43205]
000000074E57CA90 00007ff60ddbfcfb ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(IntPtr, IntPtr, IntPtr) [D:\a\_work\1\s\BuildOutput\obj\amd64fre\src\projection\generated\Microsoft.UI.Xaml.cs @ 43203]
000000074E57E5B0 00007ffa10a1d5ae [InlinedCallFrame: 000000074e57e5b0] 
000000074E57E5B0 00007ff60cf856ad [InlinedCallFrame: 000000074e57e5b0] 
000000074E57E580 00007ff60cf856ad ILStubClass.IL_STUB_PInvoke(IntPtr, IntPtr)
000000074E57E640 00007ff60cc4f94c ABI.Microsoft.UI.Xaml.IApplicationStatics.global::Microsoft.UI.Xaml.IApplicationStatics.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback) [D:\a\_work\1\s\BuildOutput\obj\amd64fre\src\projection\generated\Microsoft.UI.Xaml.cs @ 13158]
000000074E57E6C0 00007ff60cc376d5 Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback) [D:\a\_work\1\s\BuildOutput\obj\amd64fre\src\projection\generated\Microsoft.UI.Xaml.cs @ 285]
000000074E57E700 00007ff60cc35769 MauiTest.WinUI.Program.Main(System.String[]) [C:\DotNetTest\MauiTest\obj\Release\net6.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App.g.i.cs @ 31]


To Reproduce

  1. dotnet new maui
  2. Add the following properties to the .csproj:
    <WindowsPackageType>None</WindowsPackageType>
    <WinUISDKReferences>false</WinUISDKReferences>

    <PublishSingleFile>true</PublishSingleFile>
  1. dotnet publish -f net6.0-windows10.0.19041.0 -c Release
  2. Launch the app in bin\Release\net6.0-windows10.0.19041.0\win10-x64\publish\

Expected behavior The app should launch successfully.

Version Info Microsoft.Windows.SDK.NET.Ref: 10.0.19041.24

Additional context

cc @agocke @vitek-karas @mattleibow

eerhardt avatar Apr 12 '22 23:04 eerhardt

@eerhardt this looks related to #999

angelazhangmsft avatar Apr 14 '22 17:04 angelazhangmsft

Yes, that the same issue which I try to address with https://github.com/microsoft/CsWinRT/pull/993

kant2002 avatar Jun 02 '22 09:06 kant2002

Fixed in 1.6.5.

manodasanW avatar Aug 13 '22 01:08 manodasanW