-
Notifications
You must be signed in to change notification settings - Fork 290
Fix OSConditionAttribute to detect OS via reflection for .NET Framework on Mono #7001
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
base: main
Are you sure you want to change the base?
Conversation
… .NET Framework Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
src/TestFramework/TestFramework/Attributes/TestMethod/OSConditionAttribute.cs
Outdated
Show resolved
Hide resolved
src/TestFramework/TestFramework/Attributes/TestMethod/OSConditionAttribute.cs
Outdated
Show resolved
Hide resolved
| #if NET462 | ||
| // On .NET Framework, we are sure we are running on Windows. | ||
| => (_operatingSystems & OperatingSystems.Windows) != 0; | ||
| #if NETFRAMEWORK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #if NETFRAMEWORK | |
| #if NET462 |
| #endif | ||
| #endif | ||
|
|
||
| #if NETFRAMEWORK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #if NETFRAMEWORK | |
| #if NET462 |
|
|
||
| if (runtimeInformationType is null) | ||
| { | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of being nullable, should we just return OperatingSystems.Windows?
| return null; | ||
| } | ||
|
|
||
| MethodInfo? isOSPlatformMethod = runtimeInformationType.GetMethod("IsOSPlatform", BindingFlags.Public | BindingFlags.Static); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure of the declared IsOSPlatform accessibility in this case.
OSConditionAttributeassumed .NET Framework always means Windows, causing[OSCondition(OperatingSystems.Windows)]tests to run on Linux/Mac when using Mono.Changes
Use
RuntimeInformation.IsOSPlatformvia reflection for NETFRAMEWORK buildsRuntimeInformationfromSystem.Runtime.InteropServices.RuntimeInformationassembly ormscorlib(Mono)Cache detected OS at class load time to avoid repeated reflection overhead
Add exception handling for reflection invocations
Fixes #6615
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
8xbvsblobprodcus382.vsblob.vsassets.io/usr/bin/dotnet dotnet msbuild /home/REDACTED/work/testfx/testfx/src/TestFramework/TestFramework/TestFramework.csproj /t:PrintTargetFrameworks /p:TargetFramework=netstandard2.0 /nologo(dns block)/usr/bin/dotnet dotnet msbuild /home/REDACTED/work/testfx/testfx/src/TestFramework/TestFramework/TestFramework.csproj /pp(dns block)/home/REDACTED/work/testfx/testfx/.dotnet/dotnet /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/11.0.0-beta.25575.1.txt t.IsInstanceOfType.cs(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.