-
Notifications
You must be signed in to change notification settings - Fork 315
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
Set default ApartmentState to STA on .NET Core 3.0 #1865
Comments
|
@dotMorten This is a relevant ask with respect to NetCore 3.0. Would you like to contribute? |
|
Is it a breaking behavior to change the default apartment state to STA? If so we'd need to enable it with the configuration (which doesn't currently work). Or some other way? |
|
It will be breaking, I assume for now, so let's keep that as MTA. |
|
@dotMorten Would you like to contribute to enable it with the configuration ? |
|
@singhsarab Sorry I don't know where I'd have to start to do this. Also it might mean adding netcore3.0 targets across the board, which is probably a rather large task, and I don't know your project architecture well enough to do that. |
Description
With WinForms and WPF being added to .NET Core 3.0 we have a need for being able to run in STA on
netcoreapp3.0targets.I believe this is done by adding the extra target, and changing these lines of codes to also be STA for netcore3.0+
https://github.com/Microsoft/vstest/blob/7b6248203164f8ea821f6795632bd22e0b69afb0/src/Microsoft.TestPlatform.ObjectModel/Constants.cs#L179-L185
I've tried setting it with a test settings file, but it does not appear to have any effect on .NET Core:
...Same setttings file has an effect on .NET Framework when setting it to MTA, where it'll behave and fail the same way as .NET Core, so the value does work in one place. This line of code also seem to indicate that it isn't supported currently:
https://github.com/Microsoft/vstest/blob/7b6248203164f8ea821f6795632bd22e0b69afb0/src/Microsoft.TestPlatform.PlatformAbstractions/netcore/System/PlatformThread.cs#L15-L18
Steps to reproduce
Running unit tests that require STA thread like the tests in
https://github.com/Microsoft/XamlBehaviorsWpfwill fail on .NET Core 3.0 with a STA error, whereas it works on net45+I have a branch here that adds that support. .NET Core tests will fail:
https://github.com/dotMorten/XamlBehaviorsWpf/commit/8e6d588e9d3b6a49924b972d9c50d5fe7a97d3dd
Expected behavior
Tests pass as on .NET Framework
Actual behavior
Fails with messages like
Message: Test method Microsoft.Xaml.Interactions.UnitTests.ActionTest.AttachDetachTest threw exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The calling thread must be STA, because many UI components require this.Environment
The text was updated successfully, but these errors were encountered: