Search code examples
c#winformsvisual-studio-2010installationsetup-project

Could not load file or assembly error while using the application Users Program Menu


I have a winform application which i have build as Setup by using windows Setup project.Now with the help of setup i have successfully installed the application into my system.On checking the installation folder i can notice all the external .dlls are present there along with the application .exe.Now i started the application from the Users program Menu and on button click from the application screen i am getting error as ..

System.IO.FileNotFoundException: Could not load file or assembly 'EPPlus, Version=3.1.3.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1' or one of its dependencies. The system cannot find the file specified.

While the file is present in the folder .Also when i am trying to use the application from the installation folder i am able to access all the features with out any error.

Why is this happening.Please help me to resolve this..


Solution

  • To debug this issue, open the project Properties->open Debug->set Working Directory as "Start Menu" folder (which is C:\ProgramData\Microsoft\Windows\Start Menu\Programs\YourPragram). And then start debugging to recreate the binding error.

    It is likely your application expects CurrentDirectory set as the app folder. If it is, you should set it explicitly in code. In the Main method, add this

    Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
    

    With this line, even if application is started from Start Menu, the CurrentDirectory is the app folder, not Start Menu.

    You can also use Fuslogvw.exe (Assembly Binding Log Viewer) to diagnose binding error.

    1. start Visual Studio Command prompt (as Administrator).
    2. run command "Fuslogvw.exe"
    3. click "Settings", and in Log Settings dialog, select "log bind error to disk", and check "Enable custom log path", set a path like "C:\"
    4. run your program from start menu, and after the exception occur, go to C:\Default to get a binding log for EPPlus.dll.

    The diagnostic result looks like this, you can see the attempted path.

    LOG: Attempting download of new URL file:///C:/Users/kennyzx/Desktop/cloudforge/svn/package/innosetup/Files/FolderBrowserDialogEx.DLL. LOG: Attempting download of new URL file:///C:/Users/kennyzx/Desktop/cloudforge/svn/package/innosetup/Files/FolderBrowserDialogEx/FolderBrowserDialogEx.DLL.

    LOG: All probing URLs attempted and failed.