在 ReflectionOnly 模式下将程序集加载到新的 AppDomain 中时,方法没有实现 [英] Method does not have an implementation when loading assemblies into a new AppDomain in ReflectionOnly mode
问题描述
在我们的应用程序(具有 65 个项目的解决方案)中,所有引用的程序集都会在运行时分析 Ninject 模块的存在(也应用了一些过滤).这些模块稍后加载到 Ninject 内核中,每个模块都为内核声明绑定.
In our application (solution with 65 projects), all referenced assemblies are analysed in run-time for the presence of Ninject modules (there is some filtering applied too). The modules are loaded later into the Ninject kernel and each module declares bindings for the kernel.
我们采用了一个加载器,它以仅反射模式将引用的程序集加载到单独的程序集中.与 Ninject 从目录加载程序集的方式不同的是,该目录可以包含带有不应加载的模块的程序集.而且在一开始,并不是所有引用的程序集都被加载.
We have adopted a loader that loads the referenced assemblies into a separate assembly in reflection only mode. The difference from the way Ninject can load assemblies from the directory is that the directory can contain assemblies with modules that should not be loaded. And also at the very start, not all referenced assemblies are loaded.
问题在于 loader(归功于 Sacha Barber)无法使用
The problem is that the loader (credit to Sacha Barber) cannot load some assemblies with the
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information
和 LoaderExceptions
一个条目:
Method 'BeforeLoad' in type 'Lekis.AppBase.Core.BLLBaseCore' from assembly 'AppBaseCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
这里有一些有趣"的事实:
Here are some "fun" facts:
- method
BeforeLoad
是虚拟的,是一个接口方法的实现 - 上周加载程序异常说不同的方法没有实现(该方法不是虚拟的),后来,当我明确实现它时,消息说找不到该方法.
- 上周程序集
AppBaseCore
的目标框架是.NET 3.5,3个程序集加载失败 - 现在程序集
AppBaseCore
的目标框架是.NET 4和5程序集加载失败 - 应用程序一切正常,否则
- method
BeforeLoad
is virtual and an implementation of an interface method - last week the loader exception was saying different method did not have an implementation (that method was not virtual) and later, when I have explicitly implemented it, the message said the method was not found.
- last week the target framework for assembly
AppBaseCore
was .NET 3.5 and 3 assemblies failed to load - now the target framework for assembly
AppBaseCore
is .NET 4 and 5 assemblies failed to load - everything is fine with the application otherwise
当我用 ILSpy 和 ILDAsm 检查它们时,程序集没有任何问题(显然).
There is nothing wrong (obviously) with the assemblies when I checked them with ILSpy and ILDAsm.
此时,我真的很迷茫,不知道如何解决这个问题.
At this point, I am really lost and don't know how to approach this issue.
感谢任何帮助.
谢谢
推荐答案
回答我自己的问题:
当异常被抛出时,我向上堆栈跟踪并列出在创建的子 AppDomain 中加载的程序集:
When the exception was thrown, I went up the stack trace and listed the assemblies loaded in the child AppDomain created:
AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies()
{System.Reflection.RuntimeAssembly[15]}
...
[13]: {System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[14]: {System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
并注意到System.Data
程序集的两个版本.有问题的方法有一个 System.Data.IDbTransaction
类型的参数.
and noticed the two versions of System.Data
assembly. The method in question has a parameter of type System.Data.IDbTransaction
.
第一个在面向 .NET Framework 3.5 的项目中被引用.将其更改为 4.0 后一切正常.
First one was referenced in a project targeting .NET framework 3.5. After changing it to 4.0 everything works fine.
多么愚蠢的问题......
What a stupid problem ...
这篇关于在 ReflectionOnly 模式下将程序集加载到新的 AppDomain 中时,方法没有实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!