SGEN: An attempt was made to load an assembly with an incorrect format

Steve Ellwood
2 min readJul 2, 2020

This suddenly started happening to me on a Dotnet standard library that I have been working on for some time. Even more strangely NCrunch was showing this error but nothing else was. Visual Studio, VS Code and Rider would all build without a hint of an issue. I didn’t want to ignore this as NCrunch is very good at spotting issues that other software struggles to identify or misses completely. I find it very reliable in that sense.

I’m lucky in that I have a remote box that I offload some of my processing to. NCrunch is particularly good at this as long as things are kept reasonably consistent across machines. So I tried passing all the testing to the remote box but that didn’t help. I also tried restarting VS and even rebooting the box.

Looking around came up with a few suggestions including one on StackOverflow. Of particular interest to me was the section about Serialisation assemblies as I have been swapping between release and debug modes. For dotnet projects, if you go to project properties, on the build tab near the bottom is a drop down for Generate serialization assembly. This can be set for each combination of Solution Configuration and Solution Platform. I realised this when I tried to change it and it still didn’t help. Looking in the csproj file I found these combinations were set differently. For me, simply removing all these settings from the csproj file and adding one setting as shown resolved the issue and I’m now back to using NCrunch

<PropertyGroup>  <GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
</PropertyGroup>

--

--

Steve Ellwood

Senior Integrations Officer at Doncaster Council Any views expressed are entirely my own.