开发者

runtime error when calling a C++ dll from C# .NET windows application

I had a C# .NET windows application having C# user interface and all the code behind processing is done by calling C++ dll (C++ class library project) which is added as a reference to the C# project.

However recently when I formatted my computer and again tried to run my project which was backed up, in visual studio 2005 it gave the following exception:


An unhandled exception of type 'System.IO.FileNotFoundException' occurred in System.Windows.Forms.dll

Additional information: The specified module could not be found. (Exception from HRESULT: 0x8007007E)


This exception is thrown when I put the following code (for example) in the button click event.

    private void button3_Click(object sender, EventArgs e)
    {
        CyclopiaDll.Class1 cc = new CyclopiaDll.Class1(); // calling dll 
        cc.clearData();            
    }

However the exception is actually shown to be thrown in t开发者_如何学Chis line even though the form gets loaded without a problem:

  Application.Run(new Form1());

I tried building the new project and adding the referenced dll again but I m still getting the exception. This happened to me before also when I tried to run this project in another computer. However after my machine was formatted even I cant even run the application.

Only way I can think of solving this is to recreate the project from the scratch as before. which is time consuming.

Is there a way to avoid this problem so that I can run this project in my computer as well as in another computer ?


It sounds like you have a missing dependency i.e. another dll that your C++ dll depends on, that is not present on your machine.

You can use a utility like "Dependency Walker" to load your C++ dll on a machine where you have a problem, and it will point out any any missing dependencies. It is then a case of working out what this dependency is (e.g. missing C++ runtime version) and then ensuring this is packaged with your application either directly or via a merge module if suitable, for instance.

Dependency Walker: http://www.dependencywalker.com/


It looks like the compiler is not putting the referenced dll in the output folder. I would just put it in there manually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜