在ReflectionOnly模式下将程序集加载到新的AppDomain中时,方法没有实现 [英] Method does not have an implementation when loading assemblies into a new AppDomain in ReflectionOnly mode

查看:96
本文介绍了在ReflectionOnly模式下将程序集加载到新的AppDomain中时,方法没有实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序(具有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:


  • 方法 BeforeLoad 是虚拟的,并且是接口方法的实现

  • 上周加载程序异常是说不同的方法没有实现(该方法不是虚拟的),后来,当我明确实现它时,消息提示找不到该方法。

  • 上周目标框架.NET 3.5的程序集 AppBaseCore 的加载失败,并且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.

任何帮助都将受到感谢。

Any help is appreciated.

nks

推荐答案

回答我自己的问题:

抛出后,我向上查看堆栈跟踪,列出了在创建的子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屋!

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