简体   繁体   English

VS2012 Designer无法加载程序集

[英]VS2012 Designer Could Not Load Assembly

There is a solution with a C# project referencing a managed C++ library which in turn references a native C++ library. 有一个C#项目的解决方案引用托管C ++库,该库反过来引用本机C ++库。 The C# project contains BaseUserControl and ChildUserControl which extends it. C#项目包含BaseUserControl和ChildUserControl,它扩展了它。

The problem is: if code from the native C++ is called (via the managed C++ library) in the constructor of BaseUserControl then ChildUserControl can't be veiwed in the designer view; 问题是:如果在BaseUserControl的构造函数中调用来自本机C ++的代码(通过托管C ++库),则无法在设计器视图中查看ChildUserControl; nor can you add either of BaseUserControl or ChildUserControl to a Form. 也不能将BaseUserControl或ChildUserControl添加到表单中。 We get the following error: 我们收到以下错误:

Could not load file or assembly 'TestLibCPP, Version=1.0.4877.30347, Culture=neutral, PublicKeyToken=null' or one of its dependencies. 无法加载文件或程序集“TestLibCPP,Version = 1.0.4877.30347,Culture = neutral,PublicKeyToken = null”或其依赖项之一。 The system cannot find the file specified. 该系统找不到指定的文件。

How can we fix this? 我们该如何解决这个问题?

I have included a simple VS2012 solution which demonstrates the problem. 我已经包含了一个简单的VS2012解决方案来演示这个问题。 This is a contrived example based on a problem we are having with a large codebase which has recently been converted from VS2005 to VS2012. 这是一个基于我们在大型代码库中遇到的问题的人为例子,该代码库最近已从VS2005转换为VS2012。

Thanks 谢谢

如果您有源代码,请尝试使用configuraion(X86平台)重建解决方案,然后尝试使用设计器打开ChildUserControl。

问题可能是您的本机dll构建在32位配置之上,尝试在32位平台上构建项目

Try changing the GUITest platform target to x86. 尝试将GUITest平台目标更改为x86。 It is currently 'Any CPU'. 它目前是“任何CPU”。 You can do this regardless of if your on a 64 bit or 32 bit box. 无论你是64位还是32位,你都可以这样做。 Be sure to review the plaforms in your configuration too (Debug, Release, ..) 一定要查看配置中的平台(Debug,Release,..)

The problem is exactly based on the X86 architecture of your C++ projects. 问题完全基于C ++项目的X86架构。 Your WinForms Project references "Any CPU". 您的WinForms项目引用“任何CPU”。

I've included a picture to show you where to change it (sry it's in german but you should find it from the position on the screen :) 我已经包含了一张图片,告诉你在哪里更改它(sry它用德语,但你应该从屏幕上的位置找到:)

  1. Right-click your Winforms project and go to settings 右键单击Winforms项目并转到设置
  2. Switch to tab Compile (guess thats the english name for it) 切换到选项卡编译(猜测它的英文名称)
  3. Change target platform to x86 将目标平台更改为x86
  4. Build and have fun ;) 建立并享受乐趣;)

如何更改目标平台

EDIT: 编辑:

I've just seen that the Bounty Question was regarding having everything setup to 64bit so to achieve that simply set the targets of the C++ dlls to x64 architecture. 我刚刚看到Bounty问题是关于将所有设置设置为64位,以便实现简单地将C ++ dll的目标设置为x64架构。

  1. Right click on any of the c++ DLLs and go to settings 右键单击任何c ++ DLL并转到设置
  2. in the upper area you will see a button called configuration-manager 在上部区域,您将看到一个名为configuration-manager的按钮
  3. in the newly opened window just set all C++ dlls to x64. 在新打开的窗口中,只需将所有C ++ dll设置为x64。
  4. if its not available to select just click on the arrow and create a new x64 (not ARM) architecture for the second project disselect the "create new" checkbox and select the previously created one. 如果它不可用于选择只需单击箭头并为第二个项目创建一个新的x64(非ARM)架构,则会分解“创建新”复选框并选择之前创建的一个。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM