0

I have a Visual Studio (2013) C# project that builds fine on AnyCPU is failing to build when I change the platform target to x64. This is on .NET 2. The error I get is

An attempt was made to load an assembly with an incorrect format: C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.dll.

I'm struggling to find what I should do here. I have tried re-adding Sustem.Web and resources I have read indicate that this reference should work for either platform (I presume it is itself AnyCPU). I feel like I am missing something very obvious here...

Patrick
  • 677
  • 5
  • 14
  • How did you've changed platform target? – SᴇM May 10 '18 at 07:08
  • @SeM Through project properties ->Build -> Platform target – Patrick May 10 '18 at 07:29
  • In same page, what Platform selected (not platform target, this one on top). – SᴇM May 10 '18 at 07:30
  • @SeM Active (Any CPU). Don't currently have a x64 Platform present in the dropdown but will try adding one – Patrick May 10 '18 at 07:31
  • @SeM Added a x64 build config platform but made no difference. (Wouldn't expect it to, really) – Patrick May 10 '18 at 07:33
  • System.Web must *never* be loaded from that directory, it belongs in the GAC (c:\windows\assembly). Nothing that a disk format can't fix, also a good way to get rid of the need to target 2.0 – Hans Passant May 10 '18 at 08:17
  • @HansPassant I do definitely need to target 2.0. Are you sure about the directory being wrong? This is a normal VS installation with no customizations. If this is corrupt, I have no idea how it could have become so. I also checked with a colleague and his is pointing to the same directory. – Patrick May 10 '18 at 08:38
  • 100% sure. There are no breadcrumbs in the question to guess how this could have gone so wrong, I've never seen a prior case of this going wrong either. You'll need to show us a Fuslogvw.exe trace to move this ahead. – Hans Passant May 10 '18 at 08:47

1 Answers1

0

It turns out it was caused by an AfterBuild event in the .csproj file that was invoking SGEN. Disabling "Generate serialization assembly" and removing this AfterBuild event resolved it.

Patrick
  • 677
  • 5
  • 14