Description
openedon Mar 18, 2017
Description
Attempting to execute dotnet core unit/integration tests that use RavenDB 3.5.3 client. These tests execute and pass using the dotnet CLI, or the ReSharper Test Runner in Visual Studio, but using the Test Explorer, they fail with an error about log4net and AppDomain.add_ProcessExit:
Message: Test method ProcessExitException.RavenException.InitializeStore threw exception: System.TypeInitializationException: The type initializer for 'log4net.Core.LoggerManager' threw an exception. ---> System.MethodAccessException: Attempt by method 'log4net.Core.LoggerManager.RegisterAppDomainEvents()' to access method 'System.AppDomain.add_ProcessExit(System.EventHandler)' failed.
From debugging, I found that the ravendb client attempts to load log4net using Assembly.Load(...). If it's able to load then it uses that library for logging. The issue is that it's finding log4net from the directory of an installed Visual Studio extension. When debugging, I can see that the CodeBase for the log4net assembly loaded by my test is:
file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/Ide/Extensions/XSNRCEZZ.l1M/log4net.dll
I don't believe test code should be able to load assemblies from extensions loaded into Visual Studio, and I bet in this case, this log4net assembly is built against the full runtime, and not dotnet core or one of the netstandard targets. I believe that explains the message I included above.
This extension directory is the powershell tools for Visual Studio. When I removed that component for Visual Studio, the tests started passing.
Steps to reproduce
- Install Visual Studio 2017 and include the PowerShell component when installing
- Extract and load the following project
ProcessExitException.zip - Run the RavenException.InitializeStore test inside Visual Studio
Expected behavior
The test should pass
Actual behavior
It fails as noted above
Environment
Windows 10 15025+
Visual Studio 2017 (with the PowerShell component installed)
Workaround
Remove the PowerShell component (and probably also Xamarin/Mobile tools, I see log4net.dll in that extension also)