[.net]如何加载位于资源中的dll

原文

适用于将dll集成为资源的项目(添加dll文件,设置编译动作为集成资源)

AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {

String resourceName = "AssemblyLoadingAndReflection." +

new AssemblyName(args.Name).Name + ".dll";

using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {

Byte[] assemblyData = new Byte[stream.Length];

stream.Read(assemblyData, 0, assemblyData.Length);

return Assembly.Load(assemblyData);

}

};

你可能感兴趣的:([.net]如何加载位于资源中的dll)