Skip to content
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

System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1 when running a Test Adapter Visual Studio Extension on VS 17.7.x or above. #4775

Open
felipegodias opened this issue Nov 28, 2023 · 1 comment

Comments

@felipegodias
Copy link

Description

System.Runtime.CompilerServices.Unsafe assembly fails to load the correct version when creating an test adapter extension and this only happens on projects running on VS version 17.7.x and beyond. Works fine when running on 17.6.x or previous versions.

Note that adding a listener to AppDomain.CurrentDomain.AssemblyResolve and manually handle which Assembly to load kinda solves the issue but it seems to be an ugly workaround. Also, Visual Studio extensions can not leverage App.config for assembly version rebindings.

This issue seems similar to #4673 but GenerateBindingRedirectsOutputType does not work in this case.

The zipped solution is attached to this issue.
BindingIssue.zip

Steps to reproduce

1 - Set the VSTEST_HOST_DEBUG environment variable to 1. This is needed so the testhost.exe can be attached to the debugger.
2 - Run the BindingIssue extension project in a visual studio version 17.7.x or greater.
3 - When running the BindingIssue via VS, it should create a new instance of the VS so the extension can be tested.
4 - On the new instance, open a solution that outputs an .dll library.
5 - Open the VS test explorer window.
6 - Attach the testhost.exe process in the debugging BindingIssue project.
7 - Notice that when calling Task.Wait or Task.WaitAll or yield return the process tries to load the assembly System.Runtime.CompilerServices.Unsafe Version=4.0.4.1 instead of the one installed in the nuget package.

Note: There's a menu item button in VS under "Extensions/BindingIssue/Run Binding Issue Command" this command tries to emulate how the test adapter is called, and seems to work fine without trying to load the wrong version of the Unsafe assembly.

Expected behavior

The correct assembly should be loaded

Actual behavior

It should not throw:
System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The correct version of the Unsafe assembly must be loaded.

Environment

Windows 10 and 11
Visual Studio version 17.7.x or above.

@josesimoes
Copy link

josesimoes commented Apr 8, 2024

I'm seeing this too.
Ended up having to revert the library (CLIWrap) to v3.6.1. Because it has a nested reference to System.Runtime.CompilerServices.Unsafe. Anything beyond that breaks the adapter completly. Not even test discovery works.
See nanoframework/nanoFramework.TestFramework#248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants