Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New winmd reference enforcement takes down unit test host #12087

Open
Scottj1s opened this issue Jun 16, 2020 · 9 comments
Open

New winmd reference enforcement takes down unit test host #12087

Scottj1s opened this issue Jun 16, 2020 · 9 comments
Milestone

Comments

@Scottj1s
Copy link

If a winmd reference slips into a unit test project's deps.json file, then all unit test operations fail with:
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: Failed to create CoreCLR, HRESULT: 0x80070057

work around is to remove any winmd references prior to the generation of the deps.json:

but it would be nice if these references could just be ignored, or maybe issue a warning

/cc @jkoritzinsky

@marcpopMSFT marcpopMSFT added the untriaged Request triage from a team member label Jun 25, 2020
@sfoslund sfoslund added this to the Backlog milestone Jun 26, 2020
@sfoslund sfoslund removed the untriaged Request triage from a team member label Jun 26, 2020
@sfoslund sfoslund removed their assignment Jun 26, 2020
wli3 pushed a commit to wli3/sdk that referenced this issue Aug 31, 2020
@dsplaisted
Copy link
Member

How does a WinMD reference "slip" into a test project's deps.json file?

I'm not entirely sure what's happening, but I doubt that the NETSDK1130 error is the problem here. Perhaps the issue is that the .NET 5 runtime won't load assemblies with a winmd file in the deps.json? I think that was intentional, but we may not have considered how it would impact tests that target earlier versions of .NET Core and do reference winmds.

@jeffschwMSFT @richlander

@Scottj1s
Copy link
Author

@dsplaisted I've added diagnostics to my unit test to make it clearer what workarounds were needed for the two issues I encountered:
ReferencePathWithRefAssemblies bringing in transitive winmd dependencies from a winrt component project (TestComponentCSharp), creating deps.json entries that the CLR rejected (failing the unit test).
ReferencePath bringing in direct winmd dependencies from a winrt component project (TestComponentCSharp), causing the NETSDK1130 build error.

In both these cases, the winrt component project itself is doing the right thing (i.e., it should not be responsible for not publishing winmd files). It's the consuming project that must work around these issues, even though that project itself takes no dependency on the cswinrt nuget. It simply targets .NET 5, and collides with the winmd restrictions.

@dsplaisted
Copy link
Member

How is the transitive winmd dependency flowing in to the test project?

I do not think that either project should be responsible for working around issues in this case. When there is a reference (transitive or not) from a managed project to a managed winRT component (that produces a WinMD), the consuming project shouldn't automatically get the WinMD reference.

So it seems like there is an issue somewhere in the tooling (the .NET SDK, or NuGet, or similar) where the WinMD reference is being chosen incorrectly.

@Scottj1s
Copy link
Author

I don't know the precise mechanics (i.e, the targets involved), but the transitive dependency is standard behavior for a winrt component project - most consuming projects require it, either at build time, runtime, or both.

Agree that ideally, neither project should be responsible. In this case, the references are from managed project (unit test) to native projects (C++ winrt component, WinUI nuget, etc).

@dsplaisted
Copy link
Member

What's the easiest way to reproduce this in the cswinrt repo? Just run build.cmd? Are there prerequisites (ie the Windows SDK)?

@Scottj1s
Copy link
Author

Scottj1s commented Aug 31, 2020

Yes, clone CsWinRT, and from a VS 2019 dev prompt, run build.cmd. The unittest.csproj will spew out the workaround diags, and you can edit those targets to repro both issues. Let me know if you run into any snags.

After the first build (x64|Release by default) you can 'devenv cswinrt.sln' and iterate more quickly with a filtered build (unittest.csproj only)

@wli3
Copy link

wli3 commented Sep 1, 2020

but the transitive dependency is standard behavior for a winrt component project - most consuming projects require it, either at build time, runtime, or both.

So winmd reference should flow. But just not to unit test projects?

@wli3
Copy link

wli3 commented Sep 1, 2020

Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: Failed to create CoreCLR, HRESULT: 0x80070057

Also this is a runtime error, and NETSDK1130 is a build time error. Actually NETSDK1130 is to prevent implementation behind winmd to run since the implementation is no longer in runtime. So it is NETSDK1130 failed to prevent the test to run?

@Scottj1s
Copy link
Author

Scottj1s commented Sep 1, 2020

@wli3 it's both errors (NETSDK1130 and runtime) that the project had to work around - details above

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

No branches or pull requests

5 participants