异常:“编译时使用的程序集可能与加载时使用的程序集不同,并且类型丢失。”
我正在构建一个包含多个模块的 Prism 应用程序,其中一个模块 (MyModule
) 包含我创建的用户控件 (MyUserControl
)。 MyUserControl
测试正常,但是当我将其添加到 MyModule
并运行应用程序时,出现此异常:
“找不到类型 MyUserControl
。程序集编译时使用的可能与加载时使用的不同,并且类型丢失。”
我可以通过向 Shell 应用程序添加对 MyUserControl
的引用来修复该错误。但当然,这违背了 Prism 的全部目的,因为 Shell 不使用 MyUserControl
——只有 MyModule
使用它。
MyUserControl基于WPF Toolkit中的WPF Calendar控件,它似乎也有类似的问题。我在另一个不依赖于 WPF Toolkit 的模块中有另一个用户控件,并且我没有收到该控件的此异常。
关于如何解决此问题而不将 Shell 耦合到 MyUserControl 有什么建议吗?谢谢。
I am building a Prism app with several modules, one of which (MyModule
) contains a user control (MyUserControl
) that I created. MyUserControl
tests fine, but when I add it to MyModule
and run the app, I get this exception:
"Cannot find type MyUserControl
. The assembly used when compiling might be different than that used when loading and the type is missing."
I can fix the error by adding a reference to MyUserControl
to my Shell application. But of course, that defeats the whole purpose of Prism, since the Shell does not use MyUserControl
--only MyModule
uses it.
MyUserControl is based on the WPF Calendar control from the WPF Toolkit, which seems to have a similar problem. I have another user control in another module that does not depend on the WPF Toolkit, and I don't get this exception for that control.
Any suggestions on how to fix this problem without coupling the Shell to MyUserControl? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要的只是将内置的 MyUserControl.dll 复制到主应用程序文件夹中
(在主应用程序中添加引用就是这样做的)最简单的方法是使用构建后事件。
右键单击 MyUserControl 项目,选择属性,选择“Build Events”选项卡,在 Post-build 命令行中输入:
xcopy $(TargetFileName) $(SolutionDir)\您的主应用程序文件夹\bin\Debug\Modules\ /Y
就是这样,一旦构建了 MyUserControl,它将自动复制到主应用程序文件夹中,然后当您运行应用程序时,使用它的模块将能够找到它。
I think what you need is just copy the MyUserControl.dll once built into the main app folder
(adding a reference in your main app is just doing that) the simplest way of doing that is using a post build event.
right click on MyUserControl project , select properties, select the "Build Events" tab, in the Post-build command line type:
xcopy $(TargetFileName) $(SolutionDir)\YOUR MAIN APP FOLDER\bin\Debug\Modules\ /Y
and that's it, once MyUserControl is built it will be copied into the main app folder automatically, then when you run the app the module that uses it will be able to find it.