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

EqtTrace fails with TypeInitializationException on browser-wasm #4863

Open
idg10 opened this issue Jan 29, 2024 · 1 comment
Open

EqtTrace fails with TypeInitializationException on browser-wasm #4863

idg10 opened this issue Jan 29, 2024 · 1 comment

Comments

@idg10
Copy link

idg10 commented Jan 29, 2024

Description

If this library is used on the browser-wasm runtime, any attempt to use the EqtTrace class fails with a System.TypeInitializationException.

This occurs because the PlatformEqtTrace attempts to fetch the process id in its startup. It anticipates that Process.GetCurrentProcess() might throw an InvalidOperationException. However on browser-wasm, that API throws a PlatformNotSupportedException, which does not get handled, resulting in the static constructor failing.

This makes it impossible to use, for example, the MSTest framework on browser-wasm, because that depends on EqtTrace.

Steps to reproduce

I ran into this when trying to use the MSTestDiscoverer in the MSTest test adapter directly. (The test runner doesn't work in browser-wasm for other reasons so it never gets as far as attempting test discovery, which is why I was trying to use this type directly. But assuming the MS Test runner does at some point resolve the problems stopping it getting this far, it will then run into this.)

I ran the following code:

MSTestDiscoverer d = new();
d.DiscoverTests(
    ["BlazorWasmStandaloneApp.dll"],
    new DiscoveryContext(),
    new WasmMessageLogger(),
    new WasmDiscoverySink());

where the types of the final three arguments are all just empty implementations of the required interfaces.

This call fails with this stack:

System.TypeInitializationException: The type initializer for 'Microsoft.VisualStudio.TestPlatform.ObjectModel.EqtTrace' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace' threw an exception.
 ---> System.PlatformNotSupportedException: System.Diagnostics.Process is not supported on this platform.
   at System.Diagnostics.Process.GetCurrentProcess()
   at Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace.GetProcessId() in /_/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs:line 429
   at Microsoft.VisualStudio.TestPlatform.ObjectModel.PlatformEqtTrace..cctor() in /_/src/Microsoft.TestPlatform.PlatformAbstractions/common/Tracing/PlatformEqtTrace.cs:line 83
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.TestPlatform.ObjectModel.EqtTrace..cctor() in /_/src/Microsoft.TestPlatform.CoreUtilities/Tracing/EqtTrace.cs:line 28
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AdapterTraceLogger.LogWarning(String format, Object[] args) in /_/src/Adapter/MSTestAdapter.PlatformServices/Services/TraceLogger.cs:line 39
   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Discovery.AssemblyEnumeratorWrapper.GetTests(String assemblyFileName, IRunSettings runSettings, ICollection`1& warnings) in /_/src/Adapter/MSTest.TestAdapter/Discovery/AssemblyEnumeratorWrapper.cs:line 93
   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.UnitTestDiscoverer.DiscoverTestsInSource(String source, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, IDiscoveryContext discoveryContext) in /_/src/Adapter/MSTest.TestAdapter/Discovery/UnitTestDiscoverer.cs:line 61
   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.UnitTestDiscoverer.DiscoverTests(IEnumerable`1 sources, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, IDiscoveryContext discoveryContext) in /_/src/Adapter/MSTest.TestAdapter/Discovery/UnitTestDiscoverer.cs:line 44
   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestDiscoverer.DiscoverTests(IEnumerable`1 sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) in /_/src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestDiscoverer.cs:line 37

Expected behavior

The logging component should deal gracefully with the fact that process ids are not a thing in this particular runtime, so it should not crash.

Actual behavior

It crashes.

Diagnostic logs

See stack trace in repo.

Environment

.NET 8.0.1, SDK 8.0.101. Running browser-wasm in Edge, so I'm not sure the OS matters all that much, but it's Windows 10 22H2 19045.3930. MSTest.TestAdapter 3.2.0.

@nohwnd
Copy link
Member

nohwnd commented Jan 30, 2024

Let's start by fixing it for the mstest runner in the testfx issue above. I think we have a much higher chance of getting it working there. And it seems like a better fit for your workload.

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