导入不在 bin 文件夹中的程序集的命名空间
是否可以从 bin 文件夹中不在的程序集中导入命名空间?
我使用 ASP.NET MVC 2 和 MEF 将控制器从程序集中拉出。我能够让一切正常工作,但是,强类型视图无法识别程序集的对象,除非程序集位于 bin 文件夹中。
Is it possible to import a namespace from an assembly that is not in the bin folder?
I'm using ASP.NET MVC 2 with MEF to pull controllers out of the assembly.I was able to get everything working, however, strongly typed views can't recognize the assemblies' objects unless the assembly is in the bin folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
强类型视图意味着在编译时知道对象类型。为了在编译时知道对象,需要引用包含该类的程序集。在 ASP.NET 应用程序中引用程序集是通过将它们放入
bin
文件夹中来完成的。如果您使用反射从其他非标准位置加载程序集,则类型仅在运行时已知,并且您不能将它们用作强类型视图的模型。
Strongly typed view means knowing the object type at compile time. In order to know the object at compile time the assembly containing the class needs to be referenced. Referencing assemblies in an ASP.NET application is done by putting them in the
bin
folder.If you use reflection to load assemblies from some other non-standard location, types will be known only at runtime and you cannot use them as models for strongly typed views.
如果您想在运行时从 bin 文件夹之外的其他位置加载程序集,您可以通过 AppDomain 调用适当的方法来实现。
If you want to load assemblies from somewhere else than the bin folder at runtime, you may do so by calling the appropriate method through the AppDomain.