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

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

Closed
ViktorHofer opened this issue Oct 7, 2020 · 14 comments · Fixed by #44164
Closed

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

ViktorHofer opened this issue Oct 7, 2020 · 14 comments · Fixed by #44164
Assignees
Labels
area-Infrastructure-libraries blocking Marks issues that we want to fast track in order to unblock other important work
Milestone

Comments

@ViktorHofer
Copy link
Member

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

@ghost
Copy link

ghost commented Oct 7, 2020

Tagging subscribers to this area: @safern, @ViktorHofer
See info in area-owners.md if you want to be subscribed.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Oct 7, 2020
@ViktorHofer ViktorHofer removed the untriaged New issue has not been triaged by the area owner label Oct 7, 2020
@ericstj
Copy link
Member

ericstj commented Oct 9, 2020

  1. Don't feed an assembly to sgen that compiles against the very latest. Use ie a netcoreapp3.1 test helper assembly.

This sounds better to me. We could make it netstandard2.1 or net5.0. It can be a helper assembly with just the types that sgen is operating on. My inclination is netstandard2.1 since it would work for source-build.

  1. Don't invoke sgen during the test assembly's compilation at all.

This is done today because sgen produces C# which then needs to be compiled and we don't have a full SDK on the test machines.

  1. Downgrade the test assembly

I'm not a fan of this for the reasons you called out. Also it doesn't work well for source build.

  1. Upgrade to a 6.0 SDK

Although this would kick the can, it might buy time if the real issue here (#630) was fixed.

cc @mconnew @HongGit

@ericstj
Copy link
Member

ericstj commented Oct 15, 2020

@ViktorHofer is this something you're blocked on now?

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.

I don't think we've done this yet, right @Anipik?

@safern
Copy link
Member

safern commented Oct 15, 2020

This is done today because sgen produces C# which then needs to be compiled and we don't have a full SDK on the test machines.

Whenever we move to VSTest on CI, we will now have a full SDK on test machines... so maybe we can consider that option once we move to VSTest?

@ViktorHofer
Copy link
Member Author

Whenever we move to VSTest on CI, we will now have a full SDK on test machines...

Not anymore, I reverted that change as we now consume VSTest directly via a transport package.

@ViktorHofer
Copy link
Member Author

is this something you're blocked on now?

No, I'm not blocked by this at all. It's just something that devs will stumble upon locally.

@safern
Copy link
Member

safern commented Oct 15, 2020

Not anymore, I reverted that change as we now consume VSTest directly via a transport package.

Ah that is true 😢

@ericstj
Copy link
Member

ericstj commented Oct 15, 2020

It could be considered, you'd still need to figure out how to run the compiler (with appropriate references) in helix. IMHO we should make the smallest possible investment here to workaround this. The right fix is #630

@GrabYourPitchforks GrabYourPitchforks added the blocking Marks issues that we want to fast track in order to unblock other important work label Oct 29, 2020
@GrabYourPitchforks
Copy link
Member

I've marked this issue blocking because it's now affecting my ability to create local builds.

C:\runtime.io\> .\build.cmd -s clr -c Release ; .\build.cmd -s libs+libs.tests -rc Release
<< snip >>
C:\runtime.io\src\libraries\Microsoft.XmlSerializer.Generator\tests\Microsoft.XmlSerializer.Generator.Tests.csproj(43,5): error : Fail to generate C:\runtime.io\artifacts\bin\Microsoft.XmlSerializer.Generator.Tests\net6.0-Debug\Microsoft.XmlSerializer.Generator.Tests.XmlSerializers.cs
C:\runtime.io\src\libraries\Microsoft.XmlSerializer.Generator\tests\Microsoft.XmlSerializer.Generator.Tests.csproj(44,5): error MSB3030: Could not copy the file "C:\runtime.io\artifacts\bin\Microsoft.XmlSerializer.Generator.Tests\net6.0-Debug\Microsoft.XmlSerializer.Generator.Tests.XmlSerializers.cs" because it was not found.
    0 Warning(s)
    2 Error(s)

@ViktorHofer
Copy link
Member Author

A trivial fix for this issue could be approach 1 that I listed in the top post by feeding a netstandard2.1 (as Eric recommended, to not complicate source build) assembly in instead of a $(NetCoreAppCurrent) one.

@safern or @GrabYourPitchforks do you wanna give it a try?

@GrabYourPitchforks
Copy link
Member

Is this just a matter of changing the target framework for the test assembly? I'm not really sure what the proposed workaround is suggesting.

@safern
Copy link
Member

safern commented Oct 31, 2020

I believe it is introducing a new helper assembly that we feed into sgen, instead of feeding the test assembly itself. Then make that assembly target netstandard2.1

@GrabYourPitchforks
Copy link
Member

I'm still not sure what the proposed workaround is. Is there a proposed step-by-step set of instructions that I can follow to work around this? This has been blocking my ability to build + run unit tests.

@safern
Copy link
Member

safern commented Nov 2, 2020

I'm still not sure what the proposed workaround is. Is there a proposed step-by-step set of instructions that I can follow to work around this? This has been blocking my ability to build + run unit tests.

@GrabYourPitchforks I think I can tackle this one. I have a clear idea of what needs to be done. Should have a PR today.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Infrastructure-libraries blocking Marks issues that we want to fast track in order to unblock other important work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants