msbuild: SGen doesn't work with reference assemblies (?)
Steps to reproduce
- Create a new Windows Classic Console App in VS 15.3 or newer
- Unload the project and add these package references to the .csproj:
<ItemGroup>
<PackageReference Include="MassTransit.RabbitMQ">
<Version>3.5.6</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>1.1.0</Version>
</PackageReference>
</ItemGroup>
- Set this property:
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
- Reload the project and build.
Expected behavior
Should build.
Actual behavior
Severity Code Description Project File Line Suppression State
Error An attempt was made to load an assembly with an incorrect format: C:\Users\kirillo\.nuget\packages\System.Net.Http\4.3.0\ref\net46\System.Net.Http.dll. DanTupRepro C:\Users\kirillo\Documents\Visual Studio 2017\Projects\DanTupRepro\SGEN
Environment data
msbuild /version
output:
15.3.409.57025
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 17
- Comments: 26 (6 by maintainers)
I’ve submitted a ticket in the SDK: https://github.com/dotnet/sdk/issues/1630 and proposed a work around that we use in my company.
Well, ‘me too’. We are using .net 4.7.2 and both new and old format of .csproj files in different projects. Error occurred after referencing new package.
Me too.
same error
Severity Code Description Project File Line Suppression State Error An attempt was made to load an assembly with an incorrect format: C:\Users\ey02.nuget\packages\system.memory\4.5.1\ref\netstandard2.0\System.Memory.dll. SapTalk.Scheduler C:\Workspace\SourceCode\Phase5\Ey.SapTalk\SapTalk.Scheduler\SGEN
me too. i also met the same issue in the vs 2019, .net framework 4.7.2. error message as below:
Severity Code Description Project File Line Suppression State Error An attempt was made to load an assembly with an incorrect format: C:\Users\ey02.nuget\packages\system.memory\4.5.1\ref\netstandard2.0\System.Memory.dll. SapTalk.Scheduler C:\Workspace\SourceCode\Phase5\Ey.SapTalk\SapTalk.Scheduler\SGEN
It does:
https://github.com/microsoft/msbuild/blob/master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L3429-L3431
@rainersigwald
Workaround for me is
ExcludeAssets="compile"
:Is that a bug in the package? It shouldn’t be adding references to my project, only messing with build targets to pass
/embed:bigfilelist
to csc.exe.The program
sgen.exe
is owned by the WCF folks. They own both the .NET Framework version and any future .NET Core work. We talked to them internally and agreed to move the public bug to their repo (even though that’s not where a fix would be checked in, it is at least the right people).my bad workaround looks like this currently. i overwrote the target after the import of all usual targets like this in my .csproj file (you might want to change the regex):
however this is very bad. Microsoft please come up with a real fix ASAP
Same issue with 4.8.
This is still happening for certain projects here as well, is there any other workaround besides turning off that serialization?
This will only get more common as people move to new-style projects + NuGet. Pulling into 15.6, at least for triage so we don’t forget it.