我正在加载一个外部程序集,其中我设置了一个断点,并且System.Net.WebUtility
在命中断点时,静态类在运行时为null。
这是我加载外部组件的方式:
//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中
找到我需要的一切
谢谢。
发布于 2019-01-03 15:14:57
我使用ILMerge与所述外部程序集加入了几个其他DLL,并且生成的合并文件没有遵循命名空间结构。所以我有一个类,
MyPluginsProjectName.Plugins.ExternalClass
在一个DLL 的类中名为somename.dll
。
当我将DLL合并到支持命名空间结构的东西时(MyPluginsProjectName.Plugins.dll
).NET静态类现在从外部程序集内部实现。
无法解释为什么这会解决它。
https://stackoverflow.com/questions/-100006350
复制相似问题