Fluent NHibernate 1.2 - 动态程序集中不支持调用的成员

发布于 2024-10-17 14:52:53 字数 1192 浏览 1 评论 0原文

我已将 Fluent NHibenate 升级到 1.2,因为我已将 NHibenate 升级到版本 3.0。这是因为我在项目中使用了 ANTLR,并且 ANTLR 版本之间存在兼容性问题。现在,我在创建映射作为 Fluently.Configure() 调用的一部分时遇到此错误,而我以前在使用相同程序集的版本 1.0.XX 中没有遇到过此错误。我正在 VS2008 中使用 C# .NET 3.5 进行开发。

错误是“动态程序集中不支持调用的成员。”

    public static ISessionFactory GetFactory()
    {
        if (_factory == null)
        {
            Assembly assembly = Assembly.Load("BigFoot.Infrastructure");

            IApplicationContext springContainer = ContextRegistry.GetContext();
            IDbProvider provider = (IDbProvider)springContainer.GetObject("DbProvider");

            string connection = provider.ConnectionString;

            if (connection.Length > 0)
            {

                _factory = Fluently.Configure()
                    .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connection))
                    .Mappings(m =>
                        {
                            m.FluentMappings.AddFromAssembly(assembly);
                            m.HbmMappings.AddFromAssembly(assembly);
                        })

                    .BuildSessionFactory();
            }
        }

        return _factory;
    }

I have upgraded my Fluent NHibenate to 1.2 because I have upgraded NHibenate to version 3.0. This was in turn because I use ANTLR in my project and had compatibility issues between ANTLR versions. I now get this error creating mappings as part of the Fluently.Configure() call which I did not previously get with version 1.0.X.X using the same assemblies. I am developing in C# .NET 3.5 in VS2008.

Error is "The invoked member is not supported in a dynamic assembly."

    public static ISessionFactory GetFactory()
    {
        if (_factory == null)
        {
            Assembly assembly = Assembly.Load("BigFoot.Infrastructure");

            IApplicationContext springContainer = ContextRegistry.GetContext();
            IDbProvider provider = (IDbProvider)springContainer.GetObject("DbProvider");

            string connection = provider.ConnectionString;

            if (connection.Length > 0)
            {

                _factory = Fluently.Configure()
                    .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connection))
                    .Mappings(m =>
                        {
                            m.FluentMappings.AddFromAssembly(assembly);
                            m.HbmMappings.AddFromAssembly(assembly);
                        })

                    .BuildSessionFactory();
            }
        }

        return _factory;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

╭⌒浅淡时光〆 2024-10-24 14:52:53

对于那些将再次面临问题的人。此异常是一种正常行为,因为它不是未处理的异常。您看到它的唯一原因是 Visual Studio 配置为您可以看到所有异常(已处理和未处理)并且“仅调试我的代码”被禁用。因此,您可以忽略异常并在捕获异常时按继续,或者配置 Visual Studio,以便它不会向您显示此类异常。

For those who will face the problem again. This exception is a normal behaviour, because it is not an unhandled one. The only reason you see it is that visual studio configured so you see all the exceptions (handled and unhandled) and 'debug just my code' is disabled. So you can just ignore the exception and press continue when it is caught or configure visual studio so that it doesn't show such exceptions to you.

耳钉梦 2024-10-24 14:52:53

我还收到一个异常,提示“动态程序集中不支持调用的成员”。在我的案例中寻找其原因让我感到头疼。

@StuffHappens 的回答中提到的原因也适用于我:我还在“调试”->“异常”对话框中选中了“公共语言运行时异常”的“抛出”框。但是,我也未选中“工具”->“选项”->“调试”->“仅启用我的代码(仅限托管)”。事实上,我在调试时并没有想到会出现这样的异常。

除了上面的异常之外,我还看到

  • 来自 DevExpress 的 MissingManifestResourceException 抱怨某些 SkinInfoBlob.resources 元素不存在于包含自定义皮肤的 DLL 中,
  • 不同的 FileNotFoundExceptions 抱怨据称缺少 *.XmlSerializers 程序集,其中的程序集具有相同的版本所需类型驻留在(不仅对于我们自己的程序集,而且对于 NHibernate.XmlSerializers),
  • 来自 Spring.Net 的 NotSupportedException 试图从 NHibernate 解析某些对象,指出“动态程序集中不支持调用的成员”。 (或德语中的“Der aufgerufene Member wird in einer dynamischen Assembly nicht unterstützt。”)
  • 处理 TatukGIS 符号时出现 FormatException,说明(或德语中的“Die Eingabezeichenfolge hat das falsche Format。”)

我选中了“仅启用我的代码(仅托管) )”再次出现,所有神秘的异常都消失了!

我希望这可以帮助有人摆脱这个陷阱。

I also got an exception saying "The invoked member is not supported in a dynamic assembly." and it caused me some headache to find its cause in my case.

The reason mentioned in @StuffHappens' answer held also for me: I also had checked the "Thrown"-box for "Common Language Runtime Exceptions" in the Debug->Exceptions dialog. But, I also had unchecked Tools->Options->Debugging->"Enable Just My Code (Managed Only)". In fact, I didn't expect such exceptions to show up during degugging when I did so.

In addition to the exception above, I also saw

  • a MissingManifestResourceException from DevExpress complaining about some SkinInfoBlob.resources element not being present in a DLL containing a custom skin
  • different FileNotFoundExceptions complaining about supposedly missing *.XmlSerializers assemblies having the same version as the assembly wherein a desired type resides (not only for our own assemblies, but also for NHibernate.XmlSerializers)
  • a NotSupportedException from Spring.Net trying to resolve some object from NHibernate stating "The invoked member is not supported in a dynamic assembly." (or "Der aufgerufene Member wird in einer dynamischen Assembly nicht unterstützt." in german)
  • a FormatException when dealing with TatukGIS symbols stating (or "Die Eingabezeichenfolge hat das falsche Format." in german)

I checked "Enable Just My Code (Managed Only)" box again and all the mysterious exceptions vanished!

I hope this may help someone to crawl out of this pitfall.

驱逐舰岛风号 2024-10-24 14:52:53

我刚刚花了整个上午的时间来解决同样的问题。

我尝试了一切,但最终为我解决的问题是删除了所有 bin 文件夹。我实际上删除了我的项目,然后从存储库更新到最新版本(不应签入 bin 文件夹),然后再次构建并运行该项目。不知何故,某个地方发生了一些变化,这意味着 nHibernate 无法找到 log4net 的程序集信息。我猜想这与目标目录中的错误配置有关,而清理/重建无法解决!

I have just spent the whole morning on the exact same problem.

I tried everything, but in the end what fixed it for me was removing all of my bin folders. I actually deleted my project then updated to the latest version from the repository (the bin folders shouldn't be checked in), then build and ran the project again. Somewhere, somehow, something changed that meant nHibernate couldn't find the assembly info for log4net. I guess its something to do with an incorrect configuration in the target directory that a clean/rebuild doesn't resolve!

梦归所梦 2024-10-24 14:52:53

我在加载 sql 文件以在 dapper 代码中使用时遇到了相同的错误,我将构建操作设置为“嵌入式资源”并且 .NET 程序集能够加载它。

I got the same error while loading a sql file for use in dapper code, I set the build action to "Embedded Resource" and .NET assembly was able to load it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文