未验证 提交 5d702f87 编写于 作者: B Buyaa 提交者: GitHub

Fix new warnings (#43097)

* Fix CA1416 warnings in runtime repo
上级 75090807
......@@ -6,8 +6,8 @@
</PropertyGroup>
<ItemGroup Condition="'$(RunAnalyzers)' != 'false'">
<PackageReference Include="Microsoft.DotNet.CodeAnalysis" Version="$(MicrosoftDotNetCodeAnalysisVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.0-rtm.20502.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="3.8.0-4.20503.2" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.205" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="$(MicrosoftCodeAnalysisNetAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="$(MicrosoftCodeAnalysisCSharpCodeStyleVersion)" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="all" />
</ItemGroup>
</Project>
......@@ -51,6 +51,8 @@
</ItemGroup>
<PropertyGroup>
<!-- Arcade dependencies -->
<MicrosoftCodeAnalysisNetAnalyzersVersion>6.0.0-preview1.20513.4</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>3.8.0-4.20503.2</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
<MicrosoftDotNetApiCompatVersion>5.0.0-beta.20506.7</MicrosoftDotNetApiCompatVersion>
<MicrosoftDotNetBuildTasksFeedVersion>5.0.0-beta.20506.7</MicrosoftDotNetBuildTasksFeedVersion>
<MicrosoftDotNetCodeAnalysisVersion>5.0.0-beta.20506.7</MicrosoftDotNetCodeAnalysisVersion>
......@@ -69,6 +71,7 @@
<!-- CoreClr dependencies -->
<MicrosoftNETCoreILAsmVersion>5.0.0-preview.8.20359.4</MicrosoftNETCoreILAsmVersion>
<!-- Libraries dependencies -->
<StyleCopAnalyzersVersion>1.2.0-beta.205</StyleCopAnalyzersVersion>
<SystemBuffersVersion>4.5.1</SystemBuffersVersion>
<SystemCollectionsVersion>4.3.0</SystemCollectionsVersion>
<SystemCollectionsConcurrentVersion>4.3.0</SystemCollectionsConcurrentVersion>
......
......@@ -22,8 +22,8 @@
</AssemblyMetadata>
</ItemGroup>
<!-- Adds SupportedOSPlatform attribute for Windows Specific libraries -->
<ItemGroup Condition="'$(IsWindowsSpecific)' == 'true' and '$(IsTestProject)' != 'true'">
<!-- Adds SupportedOSPlatform attribute for Windows Specific libraries and Windows targets -->
<ItemGroup Condition="('$(IsWindowsSpecific)' == 'true' or '$(TargetsWindows)' == 'true') and '$(IsTestProject)' != 'true'">
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatform">
<_Parameter1>windows</_Parameter1>
</AssemblyAttribute>
......@@ -33,9 +33,9 @@
<_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
</ItemGroup>
<Target Name="AddUnsupportedOSPlatformAttribute" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild">
<Target Name="AddUnsupportedOSPlatformAttribute" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild" Condition="'@(_unsupportedOSPlatforms)' != '' and '$(IsTestProject)' != 'true'">
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform" Condition="'@(_unsupportedOSPlatforms)' != ''">
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform">
<_Parameter1>%(_unsupportedOSPlatforms.Identity)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
......
......@@ -9,6 +9,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using System.Runtime.Versioning;
//
// 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
}
}
[SupportedOSPlatform("windows")]
public static class ComActivator
{
#if FEATURE_COMINTEROP_UNMANAGED_ACTIVATION
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.Versioning;
namespace System.Runtime.InteropServices
{
[SupportedOSPlatform("windows")]
internal class ComEventsInfo
{
private ComEventsSink? _sinks;
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.Versioning;
namespace System.Runtime.InteropServices.CustomMarshalers
{
internal static class ComDataHelpers
{
[SupportedOSPlatform("windows")]
public static TView GetOrCreateManagedViewFromComData<T, TView>(object comObject, Func<T, TView> createCallback)
{
object key = typeof(TView);
......
......@@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
using System.Runtime.Versioning;
namespace System.Runtime.InteropServices.CustomMarshalers
{
[SupportedOSPlatform("windows")]
internal class EnumerableToDispatchMarshaler : ICustomMarshaler
{
private static readonly EnumerableToDispatchMarshaler s_enumerableToDispatchMarshaler = new EnumerableToDispatchMarshaler();
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using System.Runtime.InteropServices.ComTypes;
namespace System.Runtime.InteropServices.CustomMarshalers
......@@ -38,6 +39,7 @@ public System.Collections.IEnumerator GetEnumerator()
IntPtr.Zero);
}
Debug.Assert(OperatingSystem.IsWindows());
IntPtr enumVariantPtr = IntPtr.Zero;
try
{
......
......@@ -2,10 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
using System.Runtime.Versioning;
using ComTypes = System.Runtime.InteropServices.ComTypes;
namespace System.Runtime.InteropServices.CustomMarshalers
{
[SupportedOSPlatform("windows")]
internal class EnumeratorToEnumVariantMarshaler : ICustomMarshaler
{
private static readonly EnumeratorToEnumVariantMarshaler s_enumeratorToEnumVariantMarshaler = new EnumeratorToEnumVariantMarshaler();
......
......@@ -4234,6 +4234,7 @@ private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperType
aArgs[i] = new UnknownWrapper(aArgs[i]);
break;
case DispatchWrapperType.Dispatch:
Debug.Assert(OperatingSystem.IsWindows());
aArgs[i] = new DispatchWrapper(aArgs[i]);
break;
case DispatchWrapperType.Error:
......
......@@ -16,6 +16,7 @@ private static ThreadPoolBoundHandle BindHandleCore(SafeHandle handle)
try
{
Debug.Assert(OperatingSystem.IsWindows());
// ThreadPool.BindHandle will always return true, otherwise, it throws. See the underlying FCall
// implementation in ThreadPoolNative::CorBindIoCompletionCallback to see the implementation.
bool succeeded = ThreadPool.BindHandle(handle);
......
......@@ -279,6 +279,7 @@ public Variant(object? obj)
else if (obj is DispatchWrapper)
{
vt = VarEnum.VT_DISPATCH;
Debug.Assert(OperatingSystem.IsWindows());
obj = ((DispatchWrapper)obj).WrappedObject;
}
else if (obj is ErrorWrapper)
......@@ -401,6 +402,7 @@ internal static void MarshalHelperCastVariant(object pValue, int vt, ref Variant
switch (vt)
{
case 9: /*VT_DISPATCH*/
Debug.Assert(OperatingSystem.IsWindows());
v = new Variant(new DispatchWrapper(pValue));
break;
......@@ -442,7 +444,9 @@ internal static void MarshalHelperCastVariant(object pValue, int vt, ref Variant
6 => /*VT_CY*/ new Variant(new CurrencyWrapper(iv.ToDecimal(provider))),
7 => /*VT_DATE*/ new Variant(iv.ToDateTime(provider)),
8 => /*VT_BSTR*/ new Variant(iv.ToString(provider)),
#pragma warning disable CA1416 // Validate platform compatibility
9 => /*VT_DISPATCH*/ new Variant(new DispatchWrapper((object)iv)),
#pragma warning restore CA1416
10 => /*VT_ERROR*/ new Variant(new ErrorWrapper(iv.ToInt32(provider))),
11 => /*VT_BOOL*/ new Variant(iv.ToBoolean(provider)),
12 => /*VT_VARIANT*/ new Variant((object)iv),
......
......@@ -4,6 +4,7 @@
using System.Collections;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Runtime.Versioning;
namespace System
{
......@@ -11,6 +12,7 @@ namespace System
/// __ComObject is the root class for all COM wrappers. This class defines only
/// the basics. This class is used for wrapping COM objects accessed from managed.
/// </summary>
[SupportedOSPlatform("windows")]
internal class __ComObject : MarshalByRefObject
{
private Hashtable? m_ObjectToDataMap; // Do not rename (runtime relies on this name).
......
......@@ -4,6 +4,7 @@
#nullable enable
using System.Diagnostics;
using System.Runtime.Versioning;
namespace System.Runtime.InteropServices
{
......@@ -11,6 +12,7 @@ namespace System.Runtime.InteropServices
/// Part of ComEventHelpers APIs which allow binding
/// managed delegates to COM's connection point based events.
/// </summary>
[SupportedOSPlatform("windows")]
internal partial class ComEventsSink : IDispatch, ICustomQueryInterface
{
private Guid _iidSourceItf;
......
......@@ -4,6 +4,7 @@
#nullable enable
using System.Diagnostics;
using System.Runtime.Versioning;
namespace System.Runtime.InteropServices
{
......@@ -13,6 +14,7 @@ namespace System.Runtime.InteropServices
/// to and from COM calls.
/// </summary>
[StructLayout(LayoutKind.Explicit)]
[SupportedOSPlatform("windows")]
internal partial struct Variant
{
#if DEBUG
......
......@@ -5,6 +5,7 @@
<TargetFrameworks>net461-Windows_NT</TargetFrameworks>
<Nullable>enable</Nullable>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
......
......@@ -496,6 +496,7 @@ public sealed partial class Interaction
public static object? CallByName(object? ObjectRef, string ProcName, Microsoft.VisualBasic.CallType UseCallType, params object?[] Args) { throw null; }
public static object? Choose(double Index, params object?[] Choice) { throw null; }
public static string Command() { throw null; }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static object CreateObject(string ProgId, string? ServerName = "") { throw null; }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static void DeleteSetting(string AppName, string? Section = null, string? Key = null) { }
......
......@@ -266,6 +266,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
If UseCallType = CallType.Set Then
flags = flags Or BindingFlags.PutRefDispProperty
If args(args.GetUpperBound(0)) Is Nothing Then
Debug.Assert(OperatingSystem.IsWindows())
#Disable Warning BC40000 ' DispatchWrapper is marked obsolete.
args(args.GetUpperBound(0)) = New DispatchWrapper(Nothing)
#Enable Warning BC40000
......
......@@ -494,6 +494,7 @@ Namespace Microsoft.VisualBasic
End If
End Sub
<SupportedOSPlatform("windows")>
Public Function CreateObject(ByVal ProgId As String, Optional ByVal ServerName As String = "") As Object
'Creates local or remote COM2 objects. Should not be used to create COM+ objects.
'Applications that need to be STA should set STA either on their Sub Main via STAThreadAttribute
......
......@@ -466,9 +466,10 @@ public partial class PermissiveModifyControl : System.DirectoryServices.Protocol
}
public delegate System.Security.Cryptography.X509Certificates.X509Certificate QueryClientCertificateCallback(System.DirectoryServices.Protocols.LdapConnection connection, byte[][] trustedCAs);
public delegate System.DirectoryServices.Protocols.LdapConnection QueryForConnectionCallback(System.DirectoryServices.Protocols.LdapConnection primaryConnection, System.DirectoryServices.Protocols.LdapConnection referralFromConnection, string newDistinguishedName, System.DirectoryServices.Protocols.LdapDirectoryIdentifier identifier, System.Net.NetworkCredential credential, long currentUserToken);
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public partial class QuotaControl : System.DirectoryServices.Protocols.DirectoryControl
{
public QuotaControl() : base (default(string), default(byte[]), default(bool), default(bool)) { }
public QuotaControl() : base (default(string), default(byte[]), default(bool), default(bool)) { }
public QuotaControl(System.Security.Principal.SecurityIdentifier querySid) : base (default(string), default(byte[]), default(bool), default(bool)) { }
public System.Security.Principal.SecurityIdentifier QuerySid { get { throw null; } set { } }
public override byte[] GetValue() { throw null; }
......
......@@ -7,6 +7,7 @@
using System.Text;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Runtime.Versioning;
namespace System.DirectoryServices.Protocols
{
......@@ -1020,6 +1021,7 @@ public byte[] ContextId
public ResultCode Result { get; }
}
[SupportedOSPlatform("windows")]
public class QuotaControl : DirectoryControl
{
private byte[] _sid;
......
......@@ -21,6 +21,7 @@ protected StandardOleMarshalObject()
private IntPtr GetStdMarshaler(ref Guid riid, int dwDestContext, int mshlflags)
{
Debug.Assert(OperatingSystem.IsWindows());
IntPtr pUnknown = Marshal.GetIUnknownForObject(this);
if (pUnknown != IntPtr.Zero)
{
......@@ -69,6 +70,7 @@ unsafe int IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContex
}
finally
{
Debug.Assert(OperatingSystem.IsWindows());
Marshal.Release(pStandardMarshal);
}
}
......@@ -91,6 +93,7 @@ unsafe int IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int
}
finally
{
Debug.Assert(OperatingSystem.IsWindows());
Marshal.Release(pStandardMarshal);
}
}
......
......@@ -2,6 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>netstandard2.0;netstandard2.0-Windows_NT</TargetFrameworks>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\Runtime\Caching\_shims.cs" />
......
......@@ -76,6 +76,7 @@ public partial class UnmanagedMemoryAccessor : System.IDisposable
}
namespace System.Runtime.CompilerServices
{
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
[System.AttributeUsageAttribute(System.AttributeTargets.Field | System.AttributeTargets.Parameter, Inherited=false)]
public sealed partial class IDispatchConstantAttribute : System.Runtime.CompilerServices.CustomConstantAttribute
{
......
......@@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace System.Runtime.CompilerServices
{
[SupportedOSPlatform("windows")]
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
public sealed partial class IDispatchConstantAttribute : CustomConstantAttribute
{
......
......@@ -25,6 +25,7 @@ public partial class PasswordDeriveBytes : DeriveBytes
private HashAlgorithm? _hash;
private readonly CspParameters? _cspParams;
#pragma warning disable CA1416 // Validate platform compatibility, CspParametersis is windows only type, we might want to annotate this constructors windows only, suppressing for now
public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt) : this(strPassword, rgbSalt, new CspParameters()) { }
public PasswordDeriveBytes(byte[] password, byte[]? salt) : this(password, salt, new CspParameters()) { }
......@@ -34,6 +35,7 @@ public partial class PasswordDeriveBytes : DeriveBytes
public PasswordDeriveBytes(byte[] password, byte[]? salt, string hashName, int iterations) :
this(password, salt, hashName, iterations, new CspParameters()) { }
#pragma warning restore CA1416
public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, CspParameters? cspParams) :
this(strPassword, rgbSalt, "SHA1", 100, cspParams) { }
......
......@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
......
......@@ -4,6 +4,7 @@
<Nullable>enable</Nullable>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppCurrent)-Windows_NT;netstandard2.0;netcoreapp2.0-Windows_NT;netstandard2.0-Windows_NT;net461-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
<!-- Generator for code mapping table, target to invoke is GenerateEncodingSource -->
<PropertyGroup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册