Reputation: 71
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;
}
Upvotes: 7
Views: 13394
Reputation: 11
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.
Upvotes: 0
Reputation: 358
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.
Upvotes: 4
Reputation: 6557
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.
Upvotes: 12
Reputation: 2395
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!
Upvotes: 2