我现在想从网络中的某台电脑上远程加载一个dll,但是碰到了个问题。
比方我做了如下处理
首先:建立一个dll,比方A.dll 在这个dll里面我写了个Form,然后我为这个Form写了些配置信息存放在XML里面。
public class form
{
    string m_strFilePath = "";
    public string FilePath
    {
       get{return m_strFilePath;}
       set{m_strFilePath= value;}
     }
    public form()
    {
       InitializeComponent();
    }
    private void frmMain_Load(object sender, EventArgs e)
    {
         XmlDocument m_xmlDocument = new XmlDocument();         string strPath = m_strStartPath + "\\aaa.xml";        m_xmlDocument.Load(strPath);
        //其他脚本
    }
}
然后我新建了一个客户端,在这个客户端里面我动态加载这个a.dll,在程序开始的时候我就调用a.dll里面的Form,所以我修改Main。
static void Main()
 {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);                s_assembly = Assembly.LoadFile("Z:\\a.Dll"); //远程电脑上DLL,这里的Z是我为其做的一个网络映射
                //s_assembly = Assembly.LoadFile("D:\\a.Dll");//本地电脑上的存放路径
                Type type = s_assembly.GetType("form");
                //创建反射的实例
                object objForm = type.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic |
                           BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);
                Form frm = objForm as Form;
               //设置对象的FilePath属性
 PropertyDescriptor propertyDescriptor = null;
                PropertyDescriptorCollection propertyDescriptorCollection = null;                propertyDescriptorCollection = TypeDescriptor.GetProperties(objForm);
                propertyDescriptor = propertyDescriptorCollection.Find("FilePath", true);
                if (propertyDescriptor != null)
                {
                    propertyDescriptor.SetValue(objForm, "D:\\MyWork"); //这是我本地电脑上的希望访问的文件的初始路径
                }                 Application.Run(frm);
}
这样整个程序就完成了,如果把上面的LoadFile改成本地的时候,一点问题都没有,但是如果改成远程的,那么这个时候问题就出来了,如果不读取外部文件信息,窗体是打开了 但是打开的时候窗体上写着的是Internet- 登录- 登录的用户,也就是说是网络登录的,且提示我们不要输入个人帐号和密码除非我们信任改窗口,好像问题都没有发生,但是一旦我们读取了外部文件(比方我电脑上的D:\Mywork\aaa.xml)这个时候就出错了,出错的代码m_xmlDocument.Load(strPath);这个地方弹出错误,{"Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."}
这个的意思好像是我的文件访问权限有问题,所以我估计我问题是出在LoadFile的时候,这个函数还有个是带信任参数的,LoadFile(string path, Evidence securityEvidence),但是这个函数苦于用不来,希望大家能够帮帮忙!!