Fluent NHibernate 1.2 - 动态程序集中不支持调用的成员
我已将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对于那些将再次面临问题的人。此异常是一种正常行为,因为它不是未处理的异常。您看到它的唯一原因是 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.
我还收到一个异常,提示“动态程序集中不支持调用的成员”。在我的案例中寻找其原因让我感到头疼。
@StuffHappens 的回答中提到的原因也适用于我:我还在“调试”->“异常”对话框中选中了“公共语言运行时异常”的“抛出”框。但是,我也未选中“工具”->“选项”->“调试”->“仅启用我的代码(仅限托管)”。事实上,我在调试时并没有想到会出现这样的异常。
除了上面的异常之外,我还看到
我选中了“仅启用我的代码(仅托管) )”再次出现,所有神秘的异常都消失了!
我希望这可以帮助有人摆脱这个陷阱。
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
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.
我刚刚花了整个上午的时间来解决同样的问题。
我尝试了一切,但最终为我解决的问题是删除了所有 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!
我在加载 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.