Skip to content

Fix new warnings #43097

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

Merged
merged 13 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eng/Analyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -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>
3 changes: 3 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
8 changes: 4 additions & 4 deletions eng/versioning.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,6 +109,7 @@ public static unsafe ComActivationContext Create(ref ComActivationContextInterna
}
}

[SupportedOSPlatform("windows")]
public static class ComActivator
{
#if FEATURE_COMINTEROP_UNMANAGED_ACTIVATION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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
Expand Down Expand Up @@ -38,6 +39,7 @@ public System.Collections.IEnumerator GetEnumerator()
IntPtr.Zero);
}

Debug.Assert(OperatingSystem.IsWindows());
IntPtr enumVariantPtr = IntPtr.Zero;
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/src/System.Private.CoreLib/src/System/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
using System.Collections;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Runtime.Versioning;

namespace System
{
/// <summary>
/// __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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#nullable enable

using System.Diagnostics;
using System.Runtime.Versioning;

namespace System.Runtime.InteropServices
{
/// <summary>
/// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#nullable enable

using System.Diagnostics;
using System.Runtime.Versioning;

namespace System.Runtime.InteropServices
{
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ public static void Beep() { }
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) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Runtime.Versioning;

namespace System.DirectoryServices.Protocols
{
Expand Down Expand Up @@ -1020,6 +1021,7 @@ public byte[] ContextId
public ResultCode Result { get; }
}

[SupportedOSPlatform("windows")]
public class QuotaControl : DirectoryControl
{
private byte[] _sid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -69,6 +70,7 @@ unsafe int IMarshal.GetMarshalSizeMax(ref Guid riid, IntPtr pv, int dwDestContex
}
finally
{
Debug.Assert(OperatingSystem.IsWindows());
Marshal.Release(pStandardMarshal);
}
}
Expand All @@ -91,6 +93,7 @@ unsafe int IMarshal.MarshalInterface(IntPtr pStm, ref Guid riid, IntPtr pv, int
}
finally
{
Debug.Assert(OperatingSystem.IsWindows());
Marshal.Release(pStandardMarshal);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void Write<T>(long position, ref T structure) where T : struct { }
}
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) { }
Expand All @@ -34,6 +35,7 @@ public PasswordDeriveBytes(string strPassword, byte[]? rgbSalt, string strHashNa

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) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down