Fluent NHibernate 1.2 - The invoked member is not supported in a dynamic assembly
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();
开发者_C百科}
}
return _factory;
}
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.
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.
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!
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.
精彩评论