在C#中共享网络驱动器加载DLL [英] Load a dll from shared network drive in C#

查看:156
本文介绍了在C#中共享网络驱动器加载DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用这种形式加载DLL -

I am able to load the dll using this form -

System.Reflection.Assembly assembly =
System.Reflection.Assembly.LoadFile(@"C:\Users\amit.pandey\Documents\Visual Studio 2010\Projects\bin\Release\EUtility.dll");



不过,我需要从以下方式共享网络驱动器加载DLL -

However I need to load the dll from a shared network drive in the following manner -

System.Reflection.Assembly assembly =
System.Reflection.Assembly.LoadFile(@"\\falmumapp20\EUtility.dll");



我知道那是因为信任问题引起的。我曾尝试用各种编码,但无法得到它的工作。是否有人可以帮助我的示例代码加载从网络驱动器的DLL?

I know it is caused because of trust problem. I have tried various code available but could not get it working. Can someone please help me with sample code for loading the dll from a network drive?

我想这样做的代码本身,未做更改任何配置文件。

I want to do it in the code itself, without making change to any configuration file.

推荐答案

另外,从磁盘加载文件并调用的Assembly.Load 在字节数组似乎工作(Framework 4中):

Alternatively, loading the file from disk and calling Assembly.Load on the byte array seems to work (Framework 4):

        string Share = @"R:\Test\TestAssembly.dll";
        byte[] AssmBytes = File.ReadAllBytes(Share);
        Assembly a = Assembly.Load(AssmBytes);

        //Invoking a method from the loaded assembly
        var obj = a.CreateInstance("TestAssembly.Class1");
        obj.GetType().InvokeMember("HelloWorld", BindingFlags.InvokeMethod, null, obj, null);



由于 LoadFrom MS阻止网络负载(),这将表明,这样做可能不是最佳做法。然而,这是类似于通常与一个EXE嵌入组件作为资源使用的进程。

Since MS blocks network loading in LoadFrom(), it would indicate that doing so is probably not best practices. However, this is similar to the process that is often used with embedding assemblies as resources in an EXE.

这篇关于在C#中共享网络驱动器加载DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆