dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.24k stars 1.35k forks source link

Unable to compile NET Core project with localized stream resources #3311

Open nguerrera opened 6 years ago

nguerrera commented 6 years ago

From @amrmahdi on May 10, 2018 0:38

I'm not able to get a vanilla NET Core app to with localized stream resources to compile. The app is targeting net core 2.0. I've created a repo with a simple project to repro the error: https://github.com/amrmahdi/dotnetcore-localized-resources

The error that I get is

E:\repro\Resources\AudioFiles.en-US.resx(123,5): error MSB3103: Invalid Resx file. Could not load file or assembly 'System.Runtime.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencie s. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) Line 123, position 5. [E:\repro\repro.csproj]
  E:\repro\Resources\AudioFiles.es-ES.resx(123,5): error MSB3103: Invalid Resx file. Could not load file or assembly 'file:///C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Runtime.Ex tensions.dll' or one of its dependencies. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) Line 123, position 5. [E:\repro\repro .csproj]

The resource files are added using the Visual studio experience.

Copied from original issue: dotnet/sdk#2228

nguerrera commented 6 years ago

From @amrmahdi on May 10, 2018 6:55

This works if I edit the .resx files manually and replace System.IO.MemoryStream, System.Runtime.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a with System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

Why does Visual studio references the wrong assembly ?

nguerrera commented 6 years ago

cc @ericstj @davkean @rainersigwald

Why does Visual studio references the wrong assembly ?

The reference VS wrote is technically correct, but the code that is reading the resx is assuming that it can do an active load on assemblies that appear in it.

ericstj commented 6 years ago

It’ll probably work on .net 4.7.1 since that assembly is in the unification table but that’s a hack. I thought this same problem was hit for UWP and a task was rewritten on s.r.m or LMR. Apparently not this task.