none
System.Security.SecurityException when loading assembly from network RRS feed

  • Question

  • I have an application that loads controls using the Assembly.LoadFrom() method and then invokes the constructor.

    Everything works fine, until the user tries to load a dll file that is located on a network drive. When it tries to invoke the constructor a System.Security.SecurityException is thrown.

    The code looks something like this:
    // Load Assembly
    Assembly custom = Assembly.LoadFrom(controlPath);
    
     // Get the application type.
    Type type = Custom.GetType(application.executableType);
    
    // Get the constructor
    ConstructorInfo controlObjectConstructor = type.GetConstructor(new Type[0]);
    
    // Invoke the constructor
    // This is where it fails
    Control loadedControl = (UserControl)controlObjectConstructor.Invoke(new object[0]);
    I know that if I increase the code access security policy for intranet to Full Trust it will work, but as this program needs to work right out of the install (our customers will not be able to follow any extra steps), this is not an acceptable solution.

    Any ideas?
    Wednesday, September 23, 2009 6:57 PM

Answers

All replies