.NET 从<探测 privatepath...>加载程序集.config 文件中的 attr

发布于 2024-08-14 05:07:36 字数 295 浏览 1 评论 0原文

我有一个应用程序,它从属性中的配置 (myapp.exe.config) 文件中指定的子文件夹加载其大部分 dll

<probing privatePath="subdir"/> 

我的问题是:我可以在运行时加载 dll(例如 mydll.dll)吗? em>,仅使用其文件名,如果 dll 位于探测路径中指定的同一子目录“subdir”中?

我尝试了 Assembly.LoadFile("mydll.dll") 但不会在“subdir”中搜索。

I have an application that loads most of its dll's from a subfolder specified in the configuration (myapp.exe.config) file in the attribute

<probing privatePath="subdir"/> 

My question is: Can I load a dll (say mydll.dll) at runtime, using only its filename, if it the dll lives in the same subdirectory "subdir" specified in the probing path?

I tried Assembly.LoadFile("mydll.dll") but that won't search in "subdir".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌无敌 2024-08-21 05:07:36

就我个人而言,我并不真正信任信任探测路径 - dll 一直是一场噩梦,而 .net 没有采取任何措施来改善这种情况。如果您无论如何都要使用 Assembly.Load,并且您确切地知道在哪里查找,为什么不自己找到 dll,并确保您准确地加载了您想要的内容,而不是让 .net 从 6 年前的版本中决定某些内容。局域网的阴暗角落更精彩吗?

Personally I don't really trust trust probe paths - dlls have always been a nightmare, and .net's done nothing to improve that situation. If you're going to use Assembly.Load anyway, and you know exactly where to look, why not just locate the dll for yourself and be sure that you load precisely what you want instead of letting .net decide something 6 years old from a dank corner of the LAN is much more exciting?

萌酱 2024-08-21 05:07:36

您不需要加载dll文件,只需使用Type.GetType(typeName)来获取您的类型,然后使用该类型来实例化您的对象

You need not load the dll file, just use Type.GetType(typeName) to get your type, then use this type to instance your object

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文