locked
Reflecting Assemblies over a network?? RRS feed

  • Question

  • Hi,

    I wish to perform reflection on assemblies loaded from UNC paths. At the moment I am having trouble getting the binding of referenced remote assemblies to work. When I try to load a remote assembly I get a FileNotFound exception and the fusion log shows that the binder is looking in the wrong directory.

    Heres my code:

    class Program
    {
    static void Main(string[] args)
    {
    string dir = @"\\host\share"
    string asmFile = Path.Combine(dir, "MyAssembly.dll");
    AssemblyName asmName = AssemblyName.GetAssemblyName(asmFile);

    // create a new AppDomain rooted at the remote directory.
    AppDomain remoteDomain = AppDomain.CreateDomain("remoteDomain", AppDomain.CurrentDomain.Evidence, dir, @".\", false);

    // this line thows a FileNotFoundException
    Assembly remoteAssembly = remoteDomain.Load(asmName);

    }
    }

    Fusion log summary: (sorry - I'm having to type all this in)

    AppBase = c:\VS2005 Projects\RemoteReflectionTest\Bin\Debug
    InitialPrivatePath = NULL
    This bind starts in default load context.
    no app.config
    using machine.config
    Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
    Attempting download of new file c:\VS2005 Projects\RemoteReflectionTest\Bin\Debug\MyAssembly.dll

    Note that it seems to have ignored the ApplicationBase directory setting of the AppDomain, and looks in the startup application's path instead.

    Any ideas where I'm going wrong?

    thanks
    felix


    Monday, February 18, 2008 3:52 PM

Answers

  • Ah my mistake.. if you use

    Assembly.LoadFrom (as opposed to Assembly.LoadFile) then the binding works fine and create a new AppDomain is not neccesary:

    Assembly remoteAssembly = Assembly.LoadFrom(@"\\host\share");
    Monday, February 18, 2008 4:32 PM