Skip to content

Commit 5d702f8

Browse files
authored
Fix new warnings (#43097)
* Fix CA1416 warnings in runtime repo
1 parent 7509080 commit 5d702f8

File tree

28 files changed

+55
-8
lines changed

28 files changed

+55
-8
lines changed

eng/Analyzers.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77
<ItemGroup Condition="'$(RunAnalyzers)' != 'false'">
88
<PackageReference Include="Microsoft.DotNet.CodeAnalysis" Version="$(MicrosoftDotNetCodeAnalysisVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
9-
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.0-rtm.20502.2" PrivateAssets="all" />
10-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.8.0-4.20503.2" PrivateAssets="all" />
11-
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.205" PrivateAssets="all" />
9+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersVersion)" PrivateAssets="all" />
10+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="$(MicrosoftCodeAnalysisCSharpCodeStyleVersion)" PrivateAssets="all" />
11+
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="all" />
1212
</ItemGroup>
1313
</Project>

eng/Versions.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
</ItemGroup>
5252
<PropertyGroup>
5353
<!-- Arcade dependencies -->
54+
<MicrosoftCodeAnalysisNetAnalyzersVersion>6.0.0-preview1.20513.4</MicrosoftCodeAnalysisNetAnalyzersVersion>
55+
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>3.8.0-4.20503.2</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
5456
<MicrosoftDotNetApiCompatVersion>5.0.0-beta.20506.7</MicrosoftDotNetApiCompatVersion>
5557
<MicrosoftDotNetBuildTasksFeedVersion>5.0.0-beta.20506.7</MicrosoftDotNetBuildTasksFeedVersion>
5658
<MicrosoftDotNetCodeAnalysisVersion>5.0.0-beta.20506.7</MicrosoftDotNetCodeAnalysisVersion>
@@ -69,6 +71,7 @@
6971
<!-- CoreClr dependencies -->
7072
<MicrosoftNETCoreILAsmVersion>5.0.0-preview.8.20359.4</MicrosoftNETCoreILAsmVersion>
7173
<!-- Libraries dependencies -->
74+
<StyleCopAnalyzersVersion>1.2.0-beta.205</StyleCopAnalyzersVersion>
7275
<SystemBuffersVersion>4.5.1</SystemBuffersVersion>
7376
<SystemCollectionsVersion>4.3.0</SystemCollectionsVersion>
7477
<SystemCollectionsConcurrentVersion>4.3.0</SystemCollectionsConcurrentVersion>

eng/versioning.targets

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
</AssemblyMetadata>
2323
</ItemGroup>
2424

25-
<!-- Adds SupportedOSPlatform attribute for Windows Specific libraries -->
26-
<ItemGroup Condition="'$(IsWindowsSpecific)' == 'true' and '$(IsTestProject)' != 'true'">
25+
<!-- Adds SupportedOSPlatform attribute for Windows Specific libraries and Windows targets -->
26+
<ItemGroup Condition="('$(IsWindowsSpecific)' == 'true' or '$(TargetsWindows)' == 'true') and '$(IsTestProject)' != 'true'">
2727
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatform">
2828
<_Parameter1>windows</_Parameter1>
2929
</AssemblyAttribute>
@@ -33,9 +33,9 @@
3333
<_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
3434
</ItemGroup>
3535

36-
<Target Name="AddUnsupportedOSPlatformAttribute" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild">
36+
<Target Name="AddUnsupportedOSPlatformAttribute" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild" Condition="'@(_unsupportedOSPlatforms)' != '' and '$(IsTestProject)' != 'true'">
3737
<ItemGroup>
38-
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform" Condition="'@(_unsupportedOSPlatforms)' != ''">
38+
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform">
3939
<_Parameter1>%(_unsupportedOSPlatforms.Identity)</_Parameter1>
4040
</AssemblyAttribute>
4141
</ItemGroup>

src/coreclr/src/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Reflection;
1010
using System.Runtime.InteropServices;
1111
using System.Runtime.Loader;
12+
using System.Runtime.Versioning;
1213

1314
//
1415
// Types in this file marked as 'public' are done so only to aid in
@@ -108,6 +109,7 @@ public static unsafe ComActivationContext Create(ref ComActivationContextInterna
108109
}
109110
}
110111

112+
[SupportedOSPlatform("windows")]
111113
public static class ComActivator
112114
{
113115
#if FEATURE_COMINTEROP_UNMANAGED_ACTIVATION

src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Runtime.Versioning;
5+
46
namespace System.Runtime.InteropServices
57
{
8+
[SupportedOSPlatform("windows")]
69
internal class ComEventsInfo
710
{
811
private ComEventsSink? _sinks;

src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/ComDataHelpers.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Runtime.Versioning;
5+
46
namespace System.Runtime.InteropServices.CustomMarshalers
57
{
68
internal static class ComDataHelpers
79
{
10+
[SupportedOSPlatform("windows")]
811
public static TView GetOrCreateManagedViewFromComData<T, TView>(object comObject, Func<T, TView> createCallback)
912
{
1013
object key = typeof(TView);

src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumerableToDispatchMarshaler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections;
5+
using System.Runtime.Versioning;
56

67
namespace System.Runtime.InteropServices.CustomMarshalers
78
{
9+
[SupportedOSPlatform("windows")]
810
internal class EnumerableToDispatchMarshaler : ICustomMarshaler
911
{
1012
private static readonly EnumerableToDispatchMarshaler s_enumerableToDispatchMarshaler = new EnumerableToDispatchMarshaler();

src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumerableViewOfDispatch.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics;
45
using System.Runtime.InteropServices.ComTypes;
56

67
namespace System.Runtime.InteropServices.CustomMarshalers
@@ -38,6 +39,7 @@ public System.Collections.IEnumerator GetEnumerator()
3839
IntPtr.Zero);
3940
}
4041

42+
Debug.Assert(OperatingSystem.IsWindows());
4143
IntPtr enumVariantPtr = IntPtr.Zero;
4244
try
4345
{

src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumeratorToEnumVariantMarshaler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections;
5+
using System.Runtime.Versioning;
56
using ComTypes = System.Runtime.InteropServices.ComTypes;
67

78
namespace System.Runtime.InteropServices.CustomMarshalers
89
{
10+
[SupportedOSPlatform("windows")]
911
internal class EnumeratorToEnumVariantMarshaler : ICustomMarshaler
1012
{
1113
private static readonly EnumeratorToEnumVariantMarshaler s_enumeratorToEnumVariantMarshaler = new EnumeratorToEnumVariantMarshaler();

src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4234,6 +4234,7 @@ private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperType
42344234
aArgs[i] = new UnknownWrapper(aArgs[i]);
42354235
break;
42364236
case DispatchWrapperType.Dispatch:
4237+
Debug.Assert(OperatingSystem.IsWindows());
42374238
aArgs[i] = new DispatchWrapper(aArgs[i]);
42384239
break;
42394240
case DispatchWrapperType.Error:

0 commit comments

Comments
 (0)