Skip to content

Dotnet Core test executed in Visual Studio 2017 - Assembly.Load() is incorrectly able to load assemblies from Visual Studio Extensions #632

Closed

Description

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

  1. Install Visual Studio 2017 and include the PowerShell component when installing
  2. Extract and load the following project
    ProcessExitException.zip
  3. 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions