简体   繁体   English

如何将我的用户控件 dll 导入到我的新项目中?

[英]How do I import my user control dll to my new project?

I have a user control project which contains a few controls I made myself.我有一个用户控件项目,其中包含我自己制作的一些控件。 This project's output type is Class Library which produces a .dll file so I can import that in other projects.这个项目的输出类型是类库,它生成一个 .dll 文件,所以我可以在其他项目中导入它。 My problem here is when I rebuild the .dll project with Any CPU and import that dll to my second project I get this error:我的问题是,当我使用 Any CPU 重建 .dll 项目并将该 dll 导入我的第二个项目时,出现此错误:

An unhandled exception of type 'System.BadImageFormatException' occurred in SecondProject.exe SecondProject.exe 中发生类型为“System.BadImageFormatException”的未处理异常

Additional information: Could not load file or assembly 'TestUserControlsDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234567890abcdef' or one of its dependencies.附加信息:无法加载文件或程序集“TestUserControlsDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234567890abcdef”或其依赖项之一。 An attempt was made to load a program with an incorrect format.试图加载格式不正确的程序。

When I rebuild my dll project in 64bit I can see the user controls in design view but then I can't run my second project by clicking F5.当我在 64 位中重建我的 dll 项目时,我可以在设计视图中看到用户控件,但是我无法通过单击 F5 来运行我的第二个项目。 This question is probably asked before but I'm at the point which I don't even know how to search about this problem.这个问题之前可能有人问过,但我现在不知道如何搜索这个问题。

What I try to do is import my dll output (user control project) into another project (which will be 64 bit) and be able to see the controls in design view and also able to run my project.我尝试做的是将我的 dll 输出(用户控件项目)导入另一个项目(将是 64 位),并且能够在设计视图中看到控件并能够运行我的项目。

Problem solved..问题解决了..

I don't know how but creating a new dll project and just copy-paste my controls inside that new project under new namespace solved all of my problems.我不知道如何创建一个新的 dll 项目,然后将我的控件复制粘贴到新命名空间下的新项目中,解决了我的所有问题。 It's working now它现在工作

take a look, at both target framework versions.看一看,两个目标框架版本。 (Project properties) eg if your exe is 4.6.1 and your dll is 4.7.2, you get this error (项目属性)例如,如果您的 exe 是 4.6.1 而您的 dll 是 4.7.2,则会出现此错误

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

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