在.NET中动态添加引用 [英] Adding references dynamically in .NET

查看:108
本文介绍了在.NET中动态添加引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个dll(sqlite),一个dll是64位和其他32位dll。是否可以根据处理器架构动态添加引用? P / Invoke是我的最后一个选择。任何帮助将不胜感激!



示例代码:

  string pathToDll = Path.GetDirectoryName(Assembly.GetExecutingAssembly()。Location)+\\x64\\\System.Data.SQLite.dll; 
Assembly assembly = Assembly.LoadFrom(pathToDll);
AppDomain.CurrentDomain.Load(assembly.GetName());


解决方案

是的,您可以从文件加载程序集



  Assembly.LoadFrom(MyAssembly.dll);可以使用.net4中的

,您可以使用Is64BitOperatingSystem Environment属性。否则检查IntPtr.Size哪些更改根据运行的架构



无法在.NET4中加密/解密SQLite数据库


I have two dll's (sqlite) , one dll is a 64 bit and other 32 bit dll. Is it possible to add reference dynamically based on processor architecture? P/Invoke is my last option. Any help would be appreciated!!

Sample Code:

string pathToDll = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\x64\\System.Data.SQLite.dll";
Assembly assembly = Assembly.LoadFrom(pathToDll);
AppDomain.CurrentDomain.Load(assembly.GetName());

解决方案

Yes, you can load assembly from a file

 Assembly.LoadFrom("MyAssembly.dll");

from .net4 you may use Is64BitOperatingSystem Environment property. Otherwise check IntPtr.Size which changes according to running architecture

Cannot encrypt / decrypt SQLite database in .NET4

这篇关于在.NET中动态添加引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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