Skip to content

Invoking SGen creates a dependency on the repo local's shared framework #43137

Closed
@ViktorHofer

Description

@ViktorHofer

When using the repo local SDK ($(DotNetTool)) to invoke dotnet-Microsoft.XmlSerializer.Generator which dynamically (via reflection) loads the test assembly Microsoft.XmlSerializer.Generator.Tests.dll we create a dependency between the repo local shared framework and the test assembly.

This surfaces in the following error locally:

  .NET Xml Serialization Generation Utility, Version 6.0.0]
  Assembly 'C:\git\runtime2\artifacts\bin\Microsoft.XmlSerializer.Generator.Tests\net5.0-Debug\Microsoft.XmlSerializer.Generator.Tests.dll' does not contain any types that can be serialized using XmlSerializer.
C:\git\runtime2\src\libraries\Microsoft.XmlSerializer.Generator\tests\Microsoft.XmlSerializer.Generator.Tests.csproj(45,5): warning : Fail to generate C:\git\runtime2\artifacts\bin\Microsoft.XmlSerializer.Generator.Tests\net5.0-Debug\Microsoft.XmlSerializer.Generator.Tests.XmlSerializers.cs
C:\git\runtime2\src\libraries\Microsoft.XmlSerializer.Generator\tests\Microsoft.XmlSerializer.Generator.Tests.csproj(46,5): error MSB3030: Could not copy the file "C:\git\runtime2\artifacts\bin\Microsoft.XmlSerializer.Generator.Tests\net5.0-Debug\Microsoft.XmlSerializer.Generator.Tests.XmlSerializers.cs" because it was not found.

The exact cause is that the call to Type.GetTypes fails with an ReflectionTypeLoadException saying that references with assembly version X can't be resolved.

This likely has to do with us bumping the assembly version of our shared framework assemblies to 6.0.0 while the SDK still uses 5.0.0 shared framework assemblies.

There are couple of options:

  1. Don't feed an assembly to sgen that compiles against the very latest. Use ie a netcoreapp3.1 test helper assembly.
  2. Don't invoke sgen during the test assembly's compilation at all.
  3. Downgrade the test assembly (which is the input to sgen) to netcoreapp3.1. This is problematic as we would also need to downgrade TestUtilities and add support for testing non $(NetCoreAppCurrent) configurations (unreleated but we might want do this anyway at some point, similar to .NETFramework testing).
  4. Upgrade to a 6.0 SDK. This would fix the issue temporarily but it would re-appear with 7.0.

This needs to be sorted out now as it already started to happen on my machine and because I thought it was related to one of my PRs I already lost multiple hours on that. Others will start noticing this soon as well.

cc @ericstj @Anipik @safern

Metadata

Metadata

Assignees

Labels

area-Infrastructure-librariesblockingMarks issues that we want to fast track in order to unblock other important work

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions