panu28 opened a new issue, #297:
URL: https://github.com/apache/logging-log4net/issues/297
----------------------------------------------------------------
DESCRIPTION
----------------------------------------------------------------
## Environment
- log4net version: 3.1.0 → 3.3.1 (upgrade)
- Project type: Class Library
- Target framework: .NET Standard 2.0
- NuGet format: PackageReference
- Visual Studio: 2022
- OS: Windows
----------------------------------------------------------------
## Problem Description
After upgrading log4net from 3.1.0 to 3.3.1 in a .NET Standard 2.0
Class Library project, calling XmlConfigurator.ConfigureAndWatch()
throws a FileNotFoundException at runtime.
## Exact Error
FileNotFoundException: Could not load file or assembly
'System.Configuration.ConfigurationManager, Version=4.0.1.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of
its dependencies. The system cannot find the file specified.
## Code That Triggers the Error
log4net.Config.XmlConfigurator.ConfigureAndWatch(
new FileInfo(sPath)
);
----------------------------------------------------------------
## Root Cause Analysis
The error message shows Version=4.0.1.0 is being requested, which
is an old assembly version of System.Configuration.ConfigurationManager
that no longer exists on the machine.
This happens because:
1. log4net 3.1.0 was installed — NuGet pulled
ConfigurationManager 4.5.0 as a transitive dependency silently.
No explicit install was needed.
2. After upgrading to log4net 3.3.1 — NuGet failed to re-resolve
the transitive dependency cleanly. The old Version=4.0.1.0
reference remained in the project, but the actual DLL
was no longer available.
3. The .csproj still contained a stale reference:
Version=4.0.1.0 — pointing to a DLL that does not exist.
----------------------------------------------------------------
## Steps to Reproduce
1. Create a .NET Standard 2.0 Class Library project
2. Install log4net 3.1.0 via NuGet (PackageReference format)
- Works fine. ConfigurationManager 4.5.0 resolved transitively.
3. Call XmlConfigurator.ConfigureAndWatch(new FileInfo(path))
- Works fine in 3.1.0
4. Upgrade log4net from 3.1.0 to 3.3.1 via NuGet
5. Call XmlConfigurator.ConfigureAndWatch(new FileInfo(path)) again
6. FileNotFoundException thrown — Version=4.0.1.0 not found
----------------------------------------------------------------
## Expected Behavior
After upgrading log4net to 3.3.1, NuGet should:
1. Cleanly re-resolve the transitive dependency on
System.Configuration.ConfigurationManager
2. Update any stale version references automatically
3. XmlConfigurator.ConfigureAndWatch() should work
without any manual intervention
The .nuspec manifest for BOTH 3.1.0 and 3.3.1 declares
the same dependency — so behavior should be identical:
<group targetFramework=".NETStandard2.0">
<dependency id="System.Configuration.ConfigurationManager"
version="4.5.0" />
</group>
----------------------------------------------------------------
## Actual Behavior
After upgrading to 3.3.1:
- NuGet leaves a stale Version=4.0.1.0 reference in the project
- The actual DLL for that version does not exist on the machine
- XmlConfigurator.ConfigureAndWatch() fails with FileNotFoundException
- The error only occurs at RUNTIME, not at build time
making it harder to detect
----------------------------------------------------------------
## Question for Maintainers
1. Should NuGet automatically clean up stale version references
(Version=4.0.1.0) during a log4net upgrade?
2. Should the official upgrade documentation warn developers
to explicitly install System.Configuration.ConfigurationManager
when upgrading between log4net versions on .NET Standard 2.0?
3. Is there a way log4net can handle this more gracefully
to avoid a hard crash when ConfigurationManager version
is mismatched?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]