-
Notifications
You must be signed in to change notification settings - Fork 934
Cannot create configuration due to log4net loading failure #1836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It seems the application finds a log4net assembly in the application directory and tries to instantiate the logger for it, but then fails as if the assembly was indeed not available (or maybe outdated, classes not having expected methods). Either remove log4net or ensure it is up-to-date and available in GAC. |
Thank you for the fast response! I do have a log4net assembly in the GAC, version 2.0.8, which I use for my own logging purposes. Does NHibernate expect a different version? |
That is the version used in NHibernate tests. Have you check no older version was also in the GAC? Otherwise, NHibernate attempts to load log4net only if it finds it in the app domain base directory or search directory. This has not changed either, but maybe during your test a log4net assembly gets there while in your normal setup it is not there, avoiding having NHibernate attempting to load it. Corresponding code is: nhibernate-core/src/NHibernate/Logging.cs Lines 120 to 129 in f8b1bc4
If you do not need NHbernate logs, you can also disable them instead: put an empty appSetting named |
Yeah, I dug through that code as well. When I attempted to debug I was unable to hit a breakpoint in the code extract from your post. I just can't make it past the call to I only see one log4net folder in the GAC: I checked both Before upgrading, I did use NHibernate logging of SQL statements, and I'd prefer not to lose that. But if I could get async instead, I might be willing to accept it. But I'm not sure it would help me to put the app setting you mentioned in my .config file, since the crash happens on the |
I found the problem! Thanks to your work in #1837, which I replicated, built and deployed locally, I was able to get a more reasonable exception message. It was of course something stupid. :)
My NuGet references to Remotion.Linq and Remotion.Linq.EagerFetching had been updated to 2.2.0, while NHibernate expects 2.1.0. A simple binding redirect fixed the problem. |
You may have other issues after the binding redirect. Some possible breaking changes in Remotion 2.2.0 are breaking for NHibernate. See #696. If you must use ReLinq 2.2 instead of 2.1, you would have to wait for NHibernate 5.2. |
Thanks for the info! What's the planned release date for 5.2? |
Just to follow up: I downgraded the Remotion.Linq packages to 2.1 and removed the binding redirects and that seemed to do it. I then switched back to the official NHibernate 5.1.3 release and that gave me the same error as before. So for now I need to use the changes referenced in #1837 to even make it work. Really look forward to an updated official release (could just be 5.1.4). |
This means the ReLinq reference trouble was another, unrelated trouble. For checking what is the actual trouble with the logger, may you try again but only with (Alternatively, you can also fully take #1837 changes but moreover, in your application code, force the logger to use log4net with following instruction: |
Indeed, it does not work if I rollback the changes made to
|
I cannot tell more from that. Now you would have to do classical dependency loading failure debugging. (Like using fusion log.) You can still work around the issue either by using my full changes (which surely cause the logger to be disabled in your case) or by disabling the logger yourself as explained in a previous comment.
This setting has a special independent handling. It is a .Net appSetting, not a NHibernate setting. |
I'll keep looking into it. When I do I also tried your other suggestion, but I cannot do |
The failure seems to happen with the code The suggestion about setting the logger is not for working around the failure, but for explicitly triggering the failure in case you use my changes. Sorry for the error, it appears the log4net default NHibernate logger still implements the obsolete logging interface, so the code should instead be |
|
How about changing the first statement of the static constructor of
and similarly the first statement of the static constructor of
Then also updating
This gives me NHibernate logging. |
The above does work, but it is also extremely slow. I therefore reverted to the original changes you made in #1837 and now both configuration and logging works without issue for me! I'm not sure why. |
It was only slow due to massive amounts of logging being done. I have now adjusted the log level and re-implemented my changes above, and it works without issue. I'm still not sure why it seemed to work without my changes, but I must just have missed an app pool recycle or something between all be attempts. |
But looking in the file history, it looks like the same non-full name was used in NHibernate 4. So why that was working with NH4 and no more with NH5? And also, hard-coding a log4net version into the code would be of course troublesome. About nhibernate-core/src/NHibernate/Util/ReflectHelper.cs Lines 399 to 477 in 97dc207
Unfortunately it cannot be used here, since |
That helper method should indeed do the job. You could refactor it into a new class that both Thanks for all your help! |
I have updated the PR. |
As it now looks like the current handling should not work for a GAC-ed log4net anyway, reopening this. |
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to upgrade NH from 4.0.0 til 5.1.3. I have installed the proper Nuget packages and have not yet changed any existing code. This is the first (and right now, only) line of NHibernate-related code:
var config = new NHibernate.Cfg.Configuration();
After this, I plan to do different things to complete the configuration. However, the code fails at this line and I am unable to do any configuration.
I cloned the NH repo so I could debug the problem, and I cannot get past the line
properties = Environment.Properties;
in the
Reset()
method of theNHibernate.Cfg.Configuration
class.All projects in my solution target .NET 4.6.1. A thing to note is that my web projects are SharePoint (2016) projects, and the assemblies are therefore deployed to the GAC. I have confirmed that all the assemblies have been deployed correctly and that there are no versioning issues (only one version of each NHibernate-related assembly is deployed to the GAC). And just to be clear, everything worked without issue on the same setup with NH 4.0.0 (if I uninstall 5.1.3 and go back to 4.0.0, then everything works just fine again).
I have spent the last couple of days on this upgrade and I am getting no closer to a solution. I hope you can help me out.
The complete stack trace for the exception is:
The text was updated successfully, but these errors were encountered: