0

I am developing a Windows Forms application that needs to access and manipulate a SharePoint 2013 Site Collection, preferably via the Server-Side Object Model (SSOM). I seem to be running into a problem similar to the question "Visual studio designer in x64 doesn't work"

I cannot run the SSOM code in x86 or AnyCPU, and when I try to open a form with user controls in the forms designer after compiling to x64, I get the following error:

Could not find type '[UserControl]'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.

It would seem the UserControl(s) are being compiled into x64, but cannot be rendered by the designer, which I suppose is running in x86. These user controls are all in the same project, and recompiling the whole project as x86 allows the forms designer to render

Is my only option to completely rebuild my entire code base each time I want to switch between form design and interfacing with SharePoint?

Community
  • 1
  • 1
Code Jockey
  • 6,611
  • 6
  • 33
  • 45
  • `if (!this.DesignMode) { /* SSOM code ... */ }` – Hans Passant Oct 09 '15 at 15:06
  • @HansPassant -- I can... try that(?) but I don't believe the issue is SSOM running during design time (it's referenced only on form load and within certain event handlers) - it's that the UserControls are compiled to a different bitness than the IDE, so when they are called in the InitializeComponent() function by the designer, they are incompatible with the IDE's bitness(?) – Code Jockey Oct 09 '15 at 18:53
  • What was the point of targeting x64 for the user controls then? Only the Platform target setting of the EXE project matters. Any other project should select AnyCPU. So that, for one, they can still work properly in the designer. – Hans Passant Oct 09 '15 at 18:57
  • @HansPassant -- they are all in the same project - I suppose I could try to put the controls in a different project - I didn't deem it quite complex enough to justify more than one, but if that would solve my issue, then that's enough reason. I'll try that. – Code Jockey Oct 09 '15 at 19:05
  • Something doesn't add up. My crystal ball says that you are changing the solution platform setting. That's the wrong one. Project > Properties > Build tab, Platform target = AnyCPU and Prefer 32-bit = off. Do that again for the Release build. – Hans Passant Oct 09 '15 at 19:16
  • @HansPassant I'm quite certain I'm not changing the solution platform. I right clicked on the project and went to properties, build tab, platform target field. I separated the controls into another project (Class Library), targeted to Any CPU, left the primary project targeted to x64, and everything seems to be working now. I guess the answer was separate the projects and target different architectures - feel free to put this as an answer and I'll accept it - I'll come back here if I encounter issues. – Code Jockey Oct 09 '15 at 20:18

1 Answers1

0

Until or unless Hans Passant comes along and claims the answer he essentially gave me in the comment thread, I'll post my resolution to the issue:

Solution

Ensure that any user controls used in a 64 bit targeted forms/projects are in a separate project, which is compiled to target "AnyCPU", and then rebuild and reference that project.

When the forms designer, which is running as x86, tries to load your user controls for rendering, it will run the controls as x86, but when you build the 64 bit project and run it, the references will be coming from an x64 process, and will thus run the controls as x64.

Code Jockey
  • 6,611
  • 6
  • 33
  • 45