📜  除非由 AutoCAD 网络加载,否则库 dll - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:21.244000             🧑  作者: Mango

代码示例1
public class Locator{    private string _path;    public Locator()    {    }    public void InstallLocator(string path)    {        _path = path;        AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolve);    }    private Assembly AssemblyResolve(object sender, ResolveEventArgs args)    {        int position = args.Name.IndexOf(",");        if (position > -1)        {            try            {                string assemblyName = args.Name.Substring(0, position);                string assemblyFullPath = string.Empty;                //look in main folder                assemblyFullPath = _path + "\\" + assemblyName + ".dll";                if (File.Exists(assemblyFullPath))                    return Assembly.LoadFrom(assemblyFullPath);            }            catch (Exception ex)            {                System.Diagnostics.Debug.WriteLine(ex.Message);            }        }        return null;    }}