The type initializer for 'NHibernate.ByteCode.LinFu.ProxyFactory' threw an exception.
Today most of my time was spent around the Exception figuring out what made this error to be thrown by nhibernate. It was weird as the application was compiling without any warnings or Errors, and, was running without any problems till it tried to access the database.
Exception thrown was not helpful at all as it said “object reference not set….. “And there weren’t any inner exceptions as well.
Therefore the exception handling in the application was improved by including the Build session factory method in side an exception block. When the error was logged it said “The type initializer for 'NHibernate.ByteCode.LinFu.ProxyFactory' threw an exception”. The next question was how come ? as my code never accessed the LinFu proxy factory directly and it was part of the nhibernates business to do so.
In fact the problem for me was that as the proxy is being loaded dynamically, Visual Studio does not copy all the dependencies properly to the bin dir. or bin\debug dir.
Simply I had to manually copy the nhibernate dependencies to the bin folder. This fixed the problem, though it’s weird that the LinFu Proxy is not copied to the bin folder even though there is a reference from my Data Layer.
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment