【问题标题】:RegAsm: Method 'LoadContent' in type 'MyAlgorithms.MyAlgorithm' from assembly 'A' does not have an implementationRegAsm:来自程序集“A”的“MyAlgorithms.MyAlgorithm”类型中的方法“LoadContent”没有实现
【发布时间】:2011-01-06 00:45:53
【问题描述】:

我有以下类型(见下面的代码部分)。它已编译,但 RegAsm 给出以下错误:“方法 'LoadContent' in type 'MyAlgorithms.MyAlgorithm' from assembly 'A' does not have an implementation。”

知道为什么吗?如果我不实现 LoadContent() 方法,它将不会被编译。

我在这里看到了一个几乎相同的问题: TypeLoadException says 'no implementation', but it is implemented 但它没有帮助,因为:

A、B、C项目在同一个解决方案中,构建顺序为C、B、A。

所有项目的“构建后事件命令行”包含下一行:

"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe" /u $(TargetPath)
"C:\WINDOWS\Microsoft. NET\Framework\v2.0.50727\RegAsm.exe" $(TargetPath)
"c:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe" /u $(TargetName)
"c:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe" /if $(TargetPath)

所以我认为项目 A 指的是正确的程序集。

如果我将下一个添加到 MyAlgorithmBase 类中,为什么会解决问题:

protected override void LoadContent(PersistenceReader reader) { }

谢谢!

凯特

// C.dll from project C
namespace Microsoft.SqlServer.DataMining.PluginAlgorithms
{
 public abstract class AlgorithmBase : IDisposable
 {
  //....
  protected abstract void LoadContent(PersistenceReader reader);
 }
}

//in B.dll from project B, refers C.dll
namespace AlgorithmCommons
{
 public abstract class MyAlgorithmBase : AlgorithmBase
 {
  //....
  // Why solves the problem if the next line is commented out?
  // protected override void LoadContent(PersistenceReader reader) { }
 }
}

//in A.dll from project A, refers B.dll and C.dll

namespace MyAlgorithms
{
 public class MyAlgorithm : MyAlgorithmBase
 {
  protected override void LoadContent(PersistenceReader reader)
  {
  //....
  }
 }
}

【问题讨论】:

    标签: com abstract-class regasm typeloadexception


    【解决方案1】:

    编译器会验证这一点。这几乎肯定意味着在运行时,当 Regasm.exe 加载程序集时,它不会加载您认为它会加载的程序集。由于您使用 GAC,因此有很多机会。它可以根据参考程序集中的 [AssemblyVersion] 编号生成旧版本的依赖程序集。

    使用 Fuslogvw.exe 解决此问题,记录所有绑定。它向您展示了每个程序集的来源。

    通过将您的程序集放入 GAC 中,避免此类麻烦。这是一个部署细节,不适合您的开发机器,因为程序集版本可以快速更改,尤其是当您让构建系统自动增加它们时。为此,您可以使用 Regasm.exe 的 /codebase 选项

    【讨论】:

    • 您好,谢谢! Fuslogvw.exe 说:操作成功。
    • VisualStudio 会返回上述错误,因为项目的“构建后事件命令行”包含 RegAsm.exe。
    • 好的,现在我明白了!如果我在项目的“构建后事件命令行”中更改了 gacutil 和 regasm 的调用顺序,它就可以工作!
    猜你喜欢
    • 1970-01-01
    • 2011-07-17
    • 1970-01-01
    • 2011-08-24
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多