An Unhandled exception of type 'System.IO.FileNotFoundException' in c#

0

I have an old 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, after a long time, I am trying to run my project, which was backed up. Running it in visual studio 2005 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 try to debug the following code (for example) in the InitializeComponent() event.

public CSPVMain(string[] args)
{
    InitializeComponent();
    ParseArgument(args);
}

However, the exception is actually shown to be thrown on this line even though the form gets loaded without no problems:

Application.Run(new Form1());

Besides that, when I run the code by using Ctrl-F5, I get this error:

Description:
      Stopped working

Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01:   spvmain.exe
Problem Signature 02:   1.0.0.0
Problem Signature 03:   53840363
Problem Signature 04:   SPVMain
Problem Signature 05:   1.0.0.0
Problem Signature 06:   53840363
Problem Signature 07:   d
Problem Signature 08:   16
Problem Signature 09:   System.IO.FileNotFoundException
OS Version: 6.1.7600.2.0.0.768.2
Locale ID:  1033`

I have installed VMWare and run the code in 32-bit also, but it didnt work. There is no error hwen I run the single file. When I tried to run the whole application I get this error. How do I solve it?

c#
c++
dll
asked on Stack Overflow May 27, 2014 by Prarthana • edited Oct 11, 2018 by Roman Pokrovskij

2 Answers

0

Try to debug the problem in steps:

  1. Does you c++ integrate well with a console application? (without the UI)
  2. Does the UI work ok without the c++ code?
  3. Can they work together?
answered on Stack Overflow May 27, 2014 by RGH
0

That error means there is a DLL it is looking for but it can not find. There are two ways I know of to track this issue down.

First option, edit your program to display what assembly is trying to be loaded, you will see the name of any DLL that was attempted to be loaded but failed.

    static void Main(string[] args)
    {
        AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
        Application.Run(new Form1());
    }

    private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        Debug.WriteLine("Trying to resolve:" + args.Name);
        return null;
    }

The other option is enable the Assembly Binding Log via fuslogvw. Open the program as administrator and go to the setting button, set the option to "Log Bind Failures" and set the logging path to some place you can find later to clean up.

enter image description here

Once you do that, run your program and make it error out, hit the refresh button, then you can view the log files that where generated and see which assembly asked for what and where it looked for that failed load.

answered on Stack Overflow May 27, 2016 by Scott Chamberlain

User contributions licensed under CC BY-SA 3.0