none
FileLoadException, assembly on network storage RRS feed

  • Question

  • Hello there!

    The application I'm working on always crashes if started on non-local storage, in my case an intranet folder:

    System.IO.FileLoadException was unhandled
    Message: Could not load file or assembly 'xxxxxxxxx, Version=xy, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)

    It is known to me and I read it many times that this has to do with the .net security model. I know why it happens and in general I'm fine with it. The thing I want to solve is that unexperienced users of this application don't know and nag me about this error (which is not even visible in detail without debugger)

    I didn't find any information about how to catch that error. In some article someone claimed that this might be impossible due to the nature of this exception (components not being able to catch and circumvent the security exceptions they cause). Could anyone shed light on this? I'd rather like to have a messagebox or something similar appear at program start so that everyone gets a hint to copy the files to a local folder..

    Thanks in advance,

    Sebastian

    Tuesday, March 4, 2008 4:15 PM

Answers

All replies

  • Hi Sebastian,

     

     

    Have you tried to handle AppDomain.UnhandledException event in order to show message box?

    Also you can try to handle Application.ThreadException event...

    Tuesday, March 4, 2008 5:04 PM
  • Hello Vitaliy,

    thanks for your reply. I tried some code (quoted below), mostly taken from MSDN documentation pages:


    Code Snippet

    static void Main(string[] args)
    {
        AppDomain mydomain = AppDomain.CurrentDomain;
        mydomain.UnhandledException += new UnhandledExceptionEventHandler(mydomain_UnhandledException);

        Application.Run(new frmMdiMain());
    }

    static void mydomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        Exception ex = (Exception)e.ExceptionObject;
        MessageBox.Show(
            "Program could not be started, an exception occured.\n" +
            "Are you trying to start the program from an intranet folder?\n\n" +
            "Exception: " + ex.ToString(),
            "Unhandled exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }



    I put it in the Main method because I figured that this is the initial entry point. However, the application still crashes and I assume this is because it happens before that code is even reached. Sad Do I need some kind of wrapper application? That would be really annoying. Can't imagine that all .net programs have to workaround this problem.

    Sebastian
    Wednesday, March 5, 2008 10:21 AM
  •  

    Sebastian,

     

    Let's have a look what CLR performs when executes Main method:

    1. JIT Compiler tries to compile method. JIT Compiler finds reference to frmMdiMain class.

    2. CLR tries to initialize Type instance of frmMdiMain class.

    3. If frmMdiMain class is located within external assembly or has fields of types declared in external assembly, CLR will try to load these assemblies.

     

    I suggest you to create class wrapper (for instance - static class MainImpl).

    Wednesday, March 5, 2008 11:24 AM
  • Check out Interesting .net Application exceptions before entering the Main function for an explanation to this issue as well as a recommended work around.
    Thursday, March 6, 2008 3:41 AM
  • Hello Chen and Vitaliy,

    I'm quite busy with other stuff right now but your help is still appreciated. I'll check out your proposed solutions later!

    Sebastian
    Thursday, March 6, 2008 11:38 AM