44

In Visual Studio 2010 64bit I can't design my forms.
I keep getting this warning (and error):

Warning 18  
The designer could not be shown for this file because none of the classes within it can be designed.  The designer inspected the following classes in the file: 
MainForm --- The base class 'Blah' could not be loaded.  Ensure the assembly has been referenced and that all projects have been built.

This only happens with when I compile for x64 ... in x86 the designer works well.

Just want to be clear that I NEED the project to work on x64 because a lot of the project's components are compiled in x64 and won't work if the forms are in x86.

Has anyone else encountered this and found a solution ?

ViRuSTriNiTy
  • 5,017
  • 2
  • 32
  • 58
Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185
  • Sorry if this is a dumb question, but are you running Visual Studio on a 64-bit O/S? Assuming the answer is "yes", do you have any dependencies (3rd-party libraries) that are not 64-bit capable? Or, maybe a control that wrappers a native dll (in which case, you will need a 64-bit version of the native dll) – JMarsch Mar 21 '11 at 14:26
  • It's a 64bit OS, there are dependencies that are 64-bit. All components are 64-bit (verified). Only thing I can think of that isn't 64-bit is maybe something internal to VS2010. @SLaks - funny :) ... – Yochai Timmer Mar 21 '11 at 14:50
  • 1
    Attach a debugger to VS and see what the exception is. – SLaks Mar 21 '11 at 14:55
  • 1
    Currently fighting with this 64-bit problem in a WinForms project in VS2015. We removed AnyCPU. Do you know of any other solutions? – TheFitGeekGirl Mar 10 '16 at 11:18
  • I have hte same issue. MOving to AnyCPU produces an enormous list of errors. – Ted Sep 07 '19 at 09:21
  • Finally in VS2022 this is no problem anymore (thanks to its 64 bit design) – oo_dev Nov 03 '21 at 12:07

6 Answers6

52

I can repro your problem by creating a WPF application with a user control (put the user control on the wpf app, and build x64).

Here's my guess as to what's going on:

Visual Studio is a 32-bit application and the WPF designer has to load referenced assemblies (you see that behavior all of the time when you use user controls, where you have to rebuild to get the designer to update). Windows does not support a sharing between 32-bit and 64-bit - you have to have either a 32 bit app or a 64-bit app, period, no sharing.

Since the WPF designer is 32-bit, the assemblies need to be 32 bit.

Here is a possible solution:

Design your app with the "Any CPU" option. This will cause your code to JIT to 32-bit on 32-bit platforms and 64-bit on 64-bit platforms.

  • The designer will work in "any cpu" because the assemblies get jitted to 32-bit.
  • When you need to debug 64-bit specifically, switch your build configuration to 64-bit (knowing that you must switch back to "32-bit or "any cpu" do form design)
ViRuSTriNiTy
  • 5,017
  • 2
  • 32
  • 58
JMarsch
  • 21,484
  • 15
  • 77
  • 125
  • 1
    @Hans Passant: I agree, it's the WPF Designer in VS, and it's by design. It's very easy to repro - give it a shot: Start a new WPF project in VS (leave all settings alone for now). Add a new UserControl (you can just leave it blank). Add the user control to your main form. Build (all fine so far). Now create an x64 build profile and rebuild solution (boom). Switch back to x86 and rebuild (good), lather, rinse repeat. – JMarsch Mar 21 '11 at 19:24
  • 3
    For what it's worth, I can repro using the same steps with the Winform designer as well. It happens because the designer is a 32-bit app, and we hare handing it a 64-bit only assembly to load (because the user control is in our compiled output). "Any CPU" is the best answer. – JMarsch Mar 21 '11 at 19:29
  • Currently fighting with this 64-bit problem in a WinForms project in VS2015. We removed AnyCPU. Do you know of any other solutions? – TheFitGeekGirl Mar 10 '16 at 12:17
  • 1
    @TheFitGeekGirl The Visual Studio designer is going to need 32-bit assemblies. Even if you don't release or Q/A your software with AnyCPU, create either an AnyCPU or x86 profile for development. If you are requiring x64 builds for release, you can always have your build server use the x64 profile for release and Q/A builds. – JMarsch Mar 10 '16 at 16:08
  • Spent all morning chasing this one... Glad to see I came to the same conclusion. So tired of WPF being a 3rd class citizen in Visual Studio. – Jason Stevenson Jul 21 '16 at 19:56
  • 4
    This is the correct answer. 2018 and we're still fighting with 32-bit problems from the previous century. C'mon MS: If it's *that* hard to build VS itself in x64, there's a lot of egg on your face – smirkingman Jul 03 '18 at 21:27
10

This is a bug in VS 2008, 2010, 2013, 2015, 2017, and 2019.

Here's the bug report:

http://connect.microsoft.com/VisualStudio/feedback/details/646328/the-designer-could-not-be-shown-with-platform-x64

It seems there is no fix for this yet.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Gerardo Contijoch
  • 2,421
  • 5
  • 20
  • 29
9

The proposed solution from Microsoft is to move the base classes to a separate assembly, compiled using AnyCPU or x86 (if your actual project must be x64).

Unfortunately this applies to all base classes: if your inheritance is FormC : FormB : FormA, then both FormA and FormB must be in an (external) 32bit assembly, if you want to edit FormC in the designer.

Of course, this also applies to UserControls! I wish I had known this before our team decided to move to 64bit - a notice when changing the compile options would have been really nice, Microsoft...

mike
  • 1,627
  • 1
  • 14
  • 37
3

It is a limitation for Visual Studio since it does not have an x64 version.

See this support page.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
1

I had similar issues when building an old .Net project using Visual Studio Enterprise 64 Bit. ViRuSTriNiTy's solution worked for me (I changed the platform from x86 to 'Any CPU'. But it is odd that this is exactly the opposite of Julio Nobre's solution (Workaround 1)

0

It seems this a Visual Studio 2022 bug that affects only inherited forms whenever their base classes are stored on x86 dll assemblies.

As of today, using Microsoft Visual Studio Professional 2022 (64-bit) - Version 17.3.3, C# Form Designer is unable to design/load previous forms.

Fortunately there are several workarounds.

Workaround 1 (VS2022)

On Configuration Manager, locate the project that contains your form base class (the form class which your offending form as inherited from) and change Platform from Any CPU to x86, save and rebuild it. Your target form should load ok.

enter image description here

Workaround 2 (VS2022)

One guy, Frank Wenzl, figured out that changing Output type from Class Library (.dll) to Windows Application (.exe) on the project that contains the form base class and rebuilding it, allow Windows Form Designer to load inherited forms normally.

enter image description here

Workaround 3 (VS2019 or prior versions)

Using Microsoft Visual Studio Professional 2019 (32 bit, i guess) - Version 16.9.4, C# Form Designer allowed me to proceed my work.

For further info on this issue, check:

Julio Nobre
  • 4,196
  • 3
  • 46
  • 49