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

Possible issue with Microsoft Fakes #4441

Open
avivanoff opened this issue Dec 24, 2024 · 7 comments
Open

Possible issue with Microsoft Fakes #4441

avivanoff opened this issue Dec 24, 2024 · 7 comments
Assignees

Comments

@avivanoff
Copy link

A project that uses MSTest.Sdk/3.7.0 and EnableMicrosoftTestingExtensionsFakes set to true has issues execution tests that use fakes. Partial trace output:

  Message:
Test method TestMethod1 threw exception: 
Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables.

  Stack Trace: 
IntelliTraceInstrumentationProvider.ResolveProfilerPath()
IntelliTraceInstrumentationProvider.Initialize()
UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider()
ShimRuntime.CreateContext()

Unfortunately, I was not able to create a project to reproduce the issue.

@avivanoff
Copy link
Author

avivanoff commented Dec 24, 2024

Some additional observations:

  • Test project targets .NET Framework 4.8.
  • Running EXE directly results in the same error.
  • Running the tests using vstest.console.exe has no issues.
  • Converting back to non-MSTest.Sdk works as expected.

@avivanoff
Copy link
Author

Finally, I was able to create a sample project.

@drognanar
Copy link
Member

Looking at the sample the <PlatformTarget>AnyCPU</PlatformTarget> portion of the csproj is causing issues.

When specified, the <RuntimeIdentifier> property is not automatically resolved via the .NET SDK. As a result, NuGet will not restore the necessary native Fakes dlls to the bin folder.

Removing <PlatformTarget>AnyCPU</PlatformTarget> or for instance explicitly setting <RuntimeIdentifier>win-x64</RuntimeIdentifier> makes the NuGet native dll files get copied to the bin folder (such as FakesInstrumentationProfiler_x64.config, Microsoft.QualityTools.Testing.Fakes.dll, Microsoft.QualityTools.Testing.Fakes.Instrumentation_x64.dll, Microsoft.Testing.Extensions.Fakes.dll) and the tests run successfully.

The reason why this is working with vstest.console (non-MSTest.SDK) is that it dynamically loads the Fakes libraries from C:\ProgramFiles, whereas the testing platform is designed to be self-contained and all of the libraries needed to run Fakes are expected to be in the bin folder instead.

@Evangelink
Copy link
Member

@drognanar Thanks for the investigation. Would it be possible to update the Fakes extension doc page?

@drognanar
Copy link
Member

@Evangelink it makes sense to add an FAQ entry as the same issue impacts code coverage, i.e. in this configuration the coverage file generated by running testProject.exe --coverage will be empty, since the code coverage native binaries are not copied into the bin folder.

@avivanoff
Copy link
Author

@drognanar, @Evangelink, looks like the SDK-style projects have problems with .NET 4.8 targeting. If you change the target framework in the sample project to net8.0 it works.

@avivanoff
Copy link
Author

@drognanar, @Evangelink, removing <PlatformTarget>AnyCPU</PlatformTarget> results in another issue: you cannot build for multiple platforms anymore. The reason is that fake assemblies are generated in FakesAssemblies folder. So if I build x64 first, the generated assemblies will be x64, and subsequent build of ARM64 or x86 will fail.

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

No branches or pull requests

4 participants