在runntime上加载mytest.dll时出错 [英] Error on Load mytest.dll at runntime

查看:73
本文介绍了在runntime上加载mytest.dll时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在我的csharp应用程序中,当我尝试使用


加载名为mytest.dll的dll时
汇编a = Assembly.LoadFrom(mytest.dll);



显示错误,例如



无法加载文件或程序集'file:/// C:\Users\DEVP \Documents\Visual Studio 2008 \Projects \ConsoleApplication1 \ConsoleApplication1 \ bin \ Release.com mytest.dll'或其依赖项之一。系统找不到指定的文件。





i将mytest.dll复制到C:\ Users \ DEVP \Documents \ Visual Studio 2008 \Projects \ConsoleApplication1 \ConsoleApplication1 \ bin \ Release \



还...

解决方案

异常(不是错误!)是自我解释的。您应该确保将有问题的DLL放在包含加载它的代码的项目的输出目录中。替代解决方案是提供app.config文件,该文件可用于提供提示路径,其中可以在运行时找到此DLL(如果您有兴趣,我会向您提供有关此技术的信息,请询问我是一个后续问题,但这不是主要方法,但它的适用性有限。)



如果您的项目构建mytest.dll,解决这个问题的最佳方法是将该项目放在一个解决方案中,该项目包含加载它的代码。然后,如果程序集是静态依赖的,则通常使用添加引用窗口的项目选项卡添加对项目的引用,而不是程序集。如果在运行时动态加载mytest.dll,它将无济于事。因此,如果您修改所有产品以在同一目录中具有输出目录(每个配置或配置/平台组合分开),那将是最好的。例如,我通常使用.. \..\..\bin.Debug或.. \\\\...\.Release之类的路径并写下 .. \所有项目获取相同物理输出目录的方式,某些目录位于所有项目目录的父目录。



这实际上是最好的解决方案配置如果您从未使用动态DLL加载。您会看到,默认情况下,Visual Studio会创建单独的输出目录,但依赖项目的输出会复制到依赖项目的输出中;这会创建可执行模块和其他东西的多个副本,这有点浪费。 Visual Studio只是为了提供立即工作的质量,但它不适合经过精心调整的解决方案。



-SA

Hi,

In my csharp application when i tried to load a dll called mytest.dll by using

Assembly a = Assembly.LoadFrom("mytest.dll");

It show an error like

Could not load file or assembly 'file:///C:\Users\DEVP\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\bin\Release\mytest.dll' or one of its dependencies. The system cannot find the file specified.


i copied mytest.dll to C:\Users\DEVP\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\bin\Release\

also...

解决方案

The exception (not error!) is self-explaining. You should make sure than the DLL in question is placed to the output directory of the project containing the code loading it. Alternative solution would be providing the "app.config" file which can be used to provide a "hint" path where this DLL can be found during runtime (if you are interested, I'll give you the information on this technique, just ask me a follow-up question, but this is not the main approach, but it has limited applicability).

If "mytest.dll" is build by your project, the best way to deal with that would be putting the this project in one solution with the project containing the code loading it. Then, if assemblies are dependent statically, you normally add references to the projects, not assemblies, by using the tab "Projects" of the "Add Reference" window. It won't help if you load "mytest.dll" dynamically, during runtime. So, it would be the best if you modify all your products to have output directories (separate for each Configuration or Configuration/Platform combination) in the same directory. For example, I usually use the paths like "..\..\..\bin.Debug" or "..\..\..\bin.Release" and write the number of "..\" the way all projects get the same physical output directories, somewhere on some directory parent to all project directories.

This is actually the best solution configuration even if you never use dynamic DLL loading. You see, by default, Visual Studio creates separate output directories, but output of the dependency projects is copied to dependent project's output; this creates multiple copies of executable modules and other things, which is somewhat wasteful. Visual Studio does it just to provide its "works immediately" quality, but it is not the best for well-tuned solution.

—SA


这篇关于在runntime上加载mytest.dll时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆