首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >静态类在动态加载的程序集中为空

静态类在动态加载的程序集中为空
EN

Stack Overflow用户
提问于 2019-01-03 05:57:46
回答 1查看 0关注 0票数 0

我正在加载一个外部程序集,其中我设置了一个断点,并且System.Net.WebUtility在命中断点时,静态类在运行时为null。

这是我加载外部组件的方式:

代码语言:javascript
复制
//We have to write the plugin assembly's PDB file to web server so debugging (or remote debugging works)
var binPath = HttpRuntime.BinDirectory;
var pdbFileName = $@"{binPath}{Path.GetFileNameWithoutExtension(AssemblyFilename)}.pdb";

try
{
    File.WriteAllBytes(pdbFileName, ByteArrayForPDBFile);
}
catch (Exception ex)
{
    throw new Exception($"An error occured copying plugin assembly symbol file to executing directory: {ex.Message}");
}

//I've also tried AppDomain.CurrentDomain.Load() here as well...
var assembly = Assembly.Load(ByteArrayForAssembly, ByteArrayForPDBFile);
IPlugin casted;

var instance = assembly.CreateInstance(TypeNameToInit);
casted = (IPlugin)instance;

casted.Execute();

此代码在ASP MVC Web应用程序的上下文中执行。

我还注意到,当外部程序集中的断点被击中时,AppDomain为null,我觉得这有点奇怪。我是否需要以某种方式注入AppDomain加载外部组件的应用程序?

我显然编译外部程序集没有问题,而intellisense可以从 System.Net.WebUtility中找到我需要的一切

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-01-03 15:14:57

我使用ILMerge与所述外部程序集加入了几个其他DLL,并且生成的合并文件没有遵循命名空间结构。所以我有一个类,

MyPluginsProjectName.Plugins.ExternalClass在一个DLL 的类中名为somename.dll

当我将DLL合并到支持命名空间结构的东西时(MyPluginsProjectName.Plugins.dll).NET静态类现在从外部程序集内部实现。

无法解释为什么这会解决它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100006350

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档