sdk: .NET 4.6.1/.NET Standard 2.0 build with SGen fails
The context is a .NET Standard 2.0 targeted library Lib. It is referenced by a .NET Framework 4.6.1 targeted library LibNetFramework. (see GitHub repository: https://github.com/emmanuelguerin/issue-sgen)
In LibNetFramework, serialization assemblies generation is forced by the use of the GenerateSerializationAssemblies
property set to On
. Typically, this would happen when adding a WebReference to the project.
The compilation fails with the message
SGEN : error : An attempt was made to load an assembly with an incorrect format: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\ref\netfx.force.conflicts.dll.
The issue might have been corrected by the use of the patch in https://github.com/dotnet/sdk/pull/1582, that is put ine the LibNetFrameworkPatched project in the GitHub repo.
But this breaks the build, as the netstandard.dll reference is no longer added to the compilation:
LibNetFrameworkPatched\Class1.cs(9,30,9,34): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
You can find an appveyor build failing on the VS2017, and VS2017 preview: https://ci.appveyor.com/project/emmanuelguerin/issue-sgen/build/1.0.6
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 11
- Comments: 45 (9 by maintainers)
I I got this error only in project having web service refrences @tomek14 to fix it i disabled GenerateSerializationAssemblies on teh csproj i added this line for all the build config
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
I believe we do know now what is happening here. In order for SGen to work correctly on 4.7.1, it will require one of two possible solutions:
</Project>
tag.For me, a similar work around like Joses helped. I’m just temporarily removing all reference assemblies.
Thanks for the MSBuild Structured Log Viewer making it possible to efficiently analyze issues like this.
Frustrating aint the word, starting to contemplate my career choice lol, tried all work arounds 😦, no luck… Seems to complain about the 1 reference
10> - Could not load file or assembly 'file:///C:\Users\corbi\.nuget\packages\system.memory\4.5.1\ref\netstandard2.0\System.Memory.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) (TaskId:154)
I have too been bitten by this (netstandard2.1 assembly, but otherwise equivalent).
It has now been over two years since this issue was opened, and not even a hint of what Microsoft is doing about this (indication is rather that Microsoft isn’t doing anything about it). To put it mildly, that’s absurd.
Is this the kind of quality and apathy one should now expect from Microsoft. We’re talking about over two years!
Have you just given up, moved on to greener pastures, abadoning your customers? Wouldn’t be the first time, but if so you could at least man up and tell us so!
off-topic, but since it seems you (Microsoft representatives) don’t realize this, perhaps it can be an eye-opener: One shouldn’t have to wait two weeks for a fix for this. Two years is like you’re laughingly pissing your customers in the face without even the curtesy of calling it rain.
Do you (Microsoft representatives) even realize how bad this reflects on Microsoft as a whole? Apathy like this is what makes friends tell friends to “Stay the hell away from .NET (and while at it get rid of anything Microsoft)”.
Is that the message you want to send your customers? 'cause that’s the message you do send them by apathy like this.
Is that the message you want Microsoft to be known for?
Is that the message you can proudly proclaim for your boss, the boss’ boss, all the way up to CEO and shareholders, with a smile and completely unwarranted pride with loud a clear voice state “We don’t give a fuck about neither our products nor our customers!”.
(yes, I’m pissed off, and so would you be after you’ve went through the same shit due to this buggy crap - it’s a clusterf… of such proportions we’ve seriously started considering porting everything to Java, just to get rid of you)
I am getting this on a regular ASP.NET project when I upgraded to .NET 4.7.1 and it has references to .NET Standard 2.0 libs. Is there any official guidance on how this is going to get addressed?
I’m on the latest VS - 15.5.6
I have the same problem as @mouadhtrabelsi, in my WebForms App targeting 4.7.1 when building Relase.
looks like the issue is still open here
https://github.com/Microsoft/msbuild/issues/2707
@mouadhtrabelsi i can confirm turning that param off the application does compile correctly. however surely this will have an affect on application performance at runtime? and possible runtime errors?
im happy for this to be a temporary solution, but is there a planned fix?
Thanks
I am also having this issue with an on-prem windows 10 VSTS build agent
SGEN(0,0): Error : An attempt was made to load an assembly with an incorrect format: C:\Users\BUILD\.nuget\packages\system.memory\4.5.1\ref\netstandard2.0\System.Memory.dll.
Tried all sorts of fixes but had no luck, been trying to fix the issue for 3 days, please help
I am running on .NET 4.7.2, have installed the latest win 10 SDK
@joperezr It’s already 4.7.2 for https://github.com/dotnet/sdk/issues/1630#issuecomment-415655150
@mattwhetton if your machine runs on 4.7.1 (and you have installed latest windows updates) or if you are running on 4.7.2 then you shouldn’t hit this issue at all. Not on Debug builds or Release builds. Do you mind trying to update your machine to make sure you have the latest Windows Updates and trying again?
I’m experiencing a similar issue. Please also see my post: NuGet package (.NET Standard 2.x) breaking ASP.NET MVC5 application (.NET full framework)
do your patch work for .NET Framework 4.7.1 ? i added <Target Name=“ImplicitlyExpandNETStandardFacades” …> … to my csproj , but did not fix the problem,
I get this error error : An attempt was made to load an assembly with an incorrect format: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.1\Facades\System.IO.Compression.ZipFile.dll.
But i m not referincing this DLL in my project !
any help please ?
My company just ran into this. I’m not quite brave enough to use the workaround yet.
We don’t run into this so long as we don’t add a package reference to SourceLink.Embed.AllSourceFiles.