CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

CsWinRT not removing WinMD references from deps.json (CoreCLR, 0x80070057)

Open AliveDevil opened this issue 1 year ago • 5 comments

Describe the bug When referencing a NuGet package that includes for further CsWinRT referencing a .winmd file in net8.0-windows10.X subsequent launches of the application will fail (i.e. Projection B references Projection A, because Component B uses types from Component A).

To Reproduce NuSpec file:

<file src="../../artifacts/bin/Component/Win32/Release/Component.winmd" target="lib/net8.0-windows10.0.17134.0" />
<file src="../../artifacts/bin/Component.Projection/Release/net8.0-windows10.0.22621.0/Component.Projection.dll" target="lib/net8.0-windows10.0.17134.0" />

Create a console application, that references this Nuget package. The deps.json will include the .winmd files, resulting in the .NET 8 host to fail with

.\ConsoleApp1\bin\Debug\net8.0-windows10.0.22621.0\ConsoleApp1.exe
Failed to create CoreCLR, HRESULT: 0x80070057

Expected behavior As mentioned here I expect this to seamlessly just work and not crash the CoreCLR runtime immediately.

Version Info CsWinRT: 2.1.5

Additional context Repro: CsWinRTNuGet.zip Follow steps in embedded readme.md.

My workaround is to move the winmd to lib/netstandard2.0, then create a package build/net8.0-windows10.X/build.props file, that adds a reference to the netstandard2.0 winmd, which does get collected later. This has the bad sideeffect, that Visual Studio complains about a non-existing file (the MSBuildThisFileDirectory macro doesn't resolve while a project is loaded).

<Project>
  <PropertyGroup>
    <_ComponentWinMDLibDir>$(MSBuildThisFileDirectory)../../lib/netstandard2.0/</_ComponentWinMDLibDir>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="Component">
      <HintPath>$(_ComponentWinMDLibDir)Component.winmd</HintPath>
      <IsWinMDFile>true</IsWinMDFile>
    </Reference>
  </ItemGroup>
</Project>

AliveDevil avatar Oct 07 '24 11:10 AliveDevil