开发者

Visual Studio designer in x64 doesn't work

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 designe开发者_如何学Cr 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 ?


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)


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.


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...


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

See this support page.


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.

Visual Studio designer in x64 doesn't work

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.

Visual Studio designer in x64 doesn't work

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:

  • Visual Studio designer in x64 doesn't work
  • https://developercommunity.visualstudio.com/t/the-windows-forms-designer-in-visual-studio-2022-d/1560514
  • https://github.com/dotnet/winforms/issues/3338
  • https://learn.microsoft.com/en-us/answers/questions/531934/the-designer-could-not-be-shown-for-this-file-beca.html?childToView=990045#answer-990045


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜