jaredpar / basic-reference-assemblies

Produce NuPkg files that have .NET Reference assemblies as resources
MIT License
100 stars 15 forks source link

Error with 1.4.4 #43

Closed CheloXL closed 1 year ago

CheloXL commented 1 year ago

I have a project where I'm using Basic.Reference.Assemblies.Net70 1.4.2, that uses Microsoft.CodeAnalysis.CSharp to compile some on the fly created classes. After updating it to 1.4.4, I'm starting to get the following error:

System.InvalidOperationException: Resource 'net70.System.Reflection.Metadata' not found in Basic.Reference.Assemblies.Net70, Version=1.0.0.0, Culture=neutral, PublicKeyToken=00aeae93c2ffe759.
   at Basic.Reference.Assemblies.ResourceLoader.GetResourceStream(String name) in /home/runner/work/basic-reference-assemblies/basic-reference-assemblies/Shared/ResourceLoader.cs:line 17
   at Basic.Reference.Assemblies.ResourceLoader.GetResourceBlob(String name) in /home/runner/work/basic-reference-assemblies/basic-reference-assemblies/Shared/ResourceLoader.cs:line 25
   at Basic.Reference.Assemblies.Net70.References.get_SystemReflectionMetadata() in /home/runner/work/basic-reference-assemblies/basic-reference-assemblies/Basic.Reference.Assemblies.Net70/Generated.cs:line 1911
   at Basic.Reference.Assemblies.Net70.References.get_All() in /home/runner/work/basic-reference-assemblies/basic-reference-assemblies/Basic.Reference.Assemblies.Net70/Generated.cs:line 2821
   at ....

The method where that error is thrown looks like the following:

var references = new List<MetadataReference>(Net70.References.All)
{
    MetadataReference.CreateFromFile(Assembly.GetExecutingAssembly().Location)
};

Reverting back to 1.4.2 solves the problem. Not sure what was changed between 1.4.2 and 1.4.4, but something broke.

jaredpar commented 1 year ago

I can definitely repro this bug in the manner you suggested: add a package ref then run that code. Writing a unit test though does not reproduce this bug. Looking at the binaries the resource is available when I build locally but not in the official package. That doesn't make a lot of sense though because the code to embed the resource is static ...

<EmbeddedResource Include="$(NuGetPackageRoot)\microsoft.netcore.app.ref\7.0.0-rc.1.22426.10\ref\net7.0\System.Reflection.Metadata.dll">
  <LogicalName>net70.System.Reflection.Metadata</LogicalName>
  <Link>Resources\net70\System.Reflection.Metadata.dll</Link>
</EmbeddedResource>

At the moment I don't have a good idea on how this could happen other than maybe Linux restore has a subtle different behavior here which causes this. Even if that were true though I would expect a build error, not a silent failure.

Going to have to debug this a bit.

jaredpar commented 1 year ago

Indeed the build on Linux silently removes this resource.

image

Quite puzzling.

jaredpar commented 1 year ago

This is the root cause https://github.com/dotnet/msbuild/issues/9152

jaredpar commented 1 year ago

Fixde in 1.4.5. Thanks for reporting! That was a tough one to track down .

CheloXL commented 1 year ago

Thank you for taking the time to fix this!