使用C#dll找不到文件错误 [英] file not found error with C# dll

查看:74
本文介绍了使用C#dll找不到文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个C#类库dll。它编译得很好,我将

结果输出文件(mylibrary.dll)从Visual Studio debug

文件夹复制到同一台机器上的另一个文件夹中(c: \ libraries")


然后我进入COM + MMC并添加一个新的COM +应用程序

(" myapplication")并添加新的组件到那个应用。现在这个

是关键:我从位于

" c:\ libraries\mylibrary.dll"

i启动使用此库的应用程序,一切正常工作

罚款。但是,当我执行以下操作时出现错误:


1.更改库并在VS中重新编译它

3.将VS调试文件夹中的dll文件移动到libraries文件夹中。文件夹

4.重新启用并启动COM +应用程序


现在突然使用库的应用程序报告文件

未找到错误,因为.dll文件不在DEBUG文件夹中。

但是,我在LIBRARIES文件夹中用COM +注册了dll。为什么

它会在调试文件夹中找到它?


感谢您的帮助


jason

解决方案

我不确定你的项目设置,你需要查看帖子构建

事件是否有注册脚本。默认情况下,Visual Studio

将生成注册脚本,当您重新编译项目时,它会调用regsvr32在输出文件夹中注册COM

dll。你需要查看的地方是项目设置对话框,构建事件标签。


" jason" < IA **** @ yahoo.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...

我写了一个C#类库dll。它编译得很好,我将
结果输出文件(mylibrary.dll)从Visual Studio调试
文件夹复制到同一台机器上的另一个文件夹(c:\libraries")

然后我进入COM + MMC并添加一个新的COM +应用程序
(myapplication)并向该应用程序添加新组件。现在这个关键是:我从位于
c:\ libraries\mylibrary.dll的文件中添加组件
我启动使用的应用程序这个图书馆,一切正常
很好。但是,当我执行以下操作时出现错误:

1.更改库并在VS中重新编译它
2.禁用并关闭COM +应用程序
3.移动从VS调试文件夹到库的dll文件文件夹
4.重新启用并启动COM +应用程序

现在突然使用库的应用程序报告文件未找到错误,因为.dll文件不是在DEBUG文件夹中。
但是,我在LIBRARIES文件夹中用COM +注册了dll。为什么
它会在调试文件夹中寻找它?

感谢您的帮助

jason




这正是它正在做的事情。看起来好像是我在执行构建时注册了dll,所以非常感谢你这个

有用的导致。


但是,当我进入项目属性时,常见属性

文件夹,构建事件设置都有预构建和后期构建

事件命令行设置为空白。它确实说运行后期构建

事件?设置为成功构建


在配置属性文件夹中,构建设置,唯一似乎引用注册的
是注册com interop"

设置为true,但实际上并没有注册dll吗

呢?我认为它只是用于com风格的电话。


再次感谢,


jason


这是构建后的事件,我几乎可以肯定这是你问题的原因。
。 COM +无法直接使用托管代码在

当前时间,它需要互操作来调用托管代码。您可以安全地从发布后事件中删除自我

注册脚本。通常情况下,当你改变其表面时,它们只是有用的。


jason < IA **** @ yahoo.com>在消息中写道

news:11 ********************** @ z14g2000cwz.googlegr oups.com ...

这正是它正在做的事情。它似乎是在我执行构建时注册dll,所以感谢你这个
有用的领导。

然而,当我进入项目属性时,常见的属性
文件夹,构建事件设置都有预构建和后构建
事件命令行设置空白。它确实说运行后期构建
事件?设置为成功构建

在配置属性文件夹中,构建设置,似乎引用注册的唯一内容是注册com interop
设置为true,但实际上并没有注册dll吗?我认为它只是用于com风格的电话。

再次感谢,

jason



i have written a C# class library dll. it compiles fine, and i copy the
resulting output file (mylibrary.dll) from the Visual Studio debug
folder to another folder on the same machine ("c:\libraries")

then i go into the COM+ MMC and add a new COM+ application
("myapplication") and add new components to that application. now this
is the key: i add the components from the file located at
"c:\libraries\mylibrary.dll"

i launch the application that uses this library, and everything works
fine. HOWEVER, the error comes up when i do the following:

1. change the library and recompile it in VS
2. disable and shut down the COM+ application
3. MOVE the dll file from the VS debug folder to "libraries" folder
4. re-enable and start the COM+ application

now all of a sudden the application using the library reports a file
not found error, because the .dll file isn''t in the DEBUG folder.
however, i registered the dll with COM+ from the LIBRARIES folder. why
on earth would it go looking for it in the debug folder??

thanks for any help

jason

解决方案

I am not sure about your project settings, you need to check the post build
events whether the registration script is there. By default, Visual Studio
will generate registration script which calls regsvr32 to register the COM
dll in output folder whenever your re-compile your project. The place you
need to look at is in project settings dialog, build events tab.

"jason" <ia****@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

i have written a C# class library dll. it compiles fine, and i copy the
resulting output file (mylibrary.dll) from the Visual Studio debug
folder to another folder on the same machine ("c:\libraries")

then i go into the COM+ MMC and add a new COM+ application
("myapplication") and add new components to that application. now this
is the key: i add the components from the file located at
"c:\libraries\mylibrary.dll"

i launch the application that uses this library, and everything works
fine. HOWEVER, the error comes up when i do the following:

1. change the library and recompile it in VS
2. disable and shut down the COM+ application
3. MOVE the dll file from the VS debug folder to "libraries" folder
4. re-enable and start the COM+ application

now all of a sudden the application using the library reports a file
not found error, because the .dll file isn''t in the DEBUG folder.
however, i registered the dll with COM+ from the LIBRARIES folder. why
on earth would it go looking for it in the debug folder??

thanks for any help

jason




that''s exactly what it seems like it''s doing. it seems like it is
registering the dll when i perform a build, so thank you for this
useful lead.

however, when i go into the project properties, the common properties
folder, build events settings have both the pre-build and post-build
event command line settings blank. it does say "run the post-build
event?" set to "on successful build"

in the configuration properties folder, build settings, the only thing
that seems to reference registration is "register for com interop"
which is set to true, but that doesn''t actually register the dll does
it? i thought it just wrapped it for com style calls.

thanks again,

jason


It is post-build events, and I am almost pretty much sure that this is the
reason for your problem. COM+ cannot work with managed code directly at
current time, it needs interop to call managed code. You can remove the self
registration script from post build events safely. Normally they are only
useful when you changed the inerface.

"jason" <ia****@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

that''s exactly what it seems like it''s doing. it seems like it is
registering the dll when i perform a build, so thank you for this
useful lead.

however, when i go into the project properties, the common properties
folder, build events settings have both the pre-build and post-build
event command line settings blank. it does say "run the post-build
event?" set to "on successful build"

in the configuration properties folder, build settings, the only thing
that seems to reference registration is "register for com interop"
which is set to true, but that doesn''t actually register the dll does
it? i thought it just wrapped it for com style calls.

thanks again,

jason




这篇关于使用C#dll找不到文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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