diff --git a/eng/Analyzers.props b/eng/Analyzers.props
index 2c9b1c8bee446..c14a86901948a 100644
--- a/eng/Analyzers.props
+++ b/eng/Analyzers.props
@@ -6,7 +6,7 @@
-
+
diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset
index 42ea385a079d5..3726904d2fd7e 100644
--- a/eng/CodeAnalysis.ruleset
+++ b/eng/CodeAnalysis.ruleset
@@ -64,6 +64,7 @@
+
@@ -112,6 +113,8 @@
+
+
@@ -174,6 +177,15 @@
+
+
+
+
+
+
+
+
+
@@ -239,6 +251,8 @@
+
+
diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CreateProcessWithLogon.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CreateProcessWithLogon.cs
index 7d4fc64ff1aa9..61e28bd616d5a 100644
--- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CreateProcessWithLogon.cs
+++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CreateProcessWithLogon.cs
@@ -18,7 +18,9 @@ internal static extern bool CreateProcessWithLogonW(
IntPtr password,
LogonFlags logonFlags,
string? appName,
+#pragma warning disable CA1838 // reasonable use of StringBuilder to build up a command line
[In] StringBuilder cmdLine,
+#pragma warning restore CA1838
int creationFlags,
IntPtr environmentBlock,
string lpCurrentDirectory,
diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs
index 8b3a702d23aac..3a264330a3275 100644
--- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs
+++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs
@@ -20,7 +20,9 @@ public static extern bool CryptGetDefaultProvider(
int dwProvType,
IntPtr pdwReserved,
GetDefaultProviderFlags dwFlags,
- StringBuilder? pszProvName,
+#pragma warning disable CA1838 // not on a hot path
+ [Out] StringBuilder? pszProvName,
+#pragma warning restore CA1838
ref int pcbProvName);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateProcess.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateProcess.cs
index 104bfe0e0e16b..95a17f1b5624b 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateProcess.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CreateProcess.cs
@@ -15,7 +15,9 @@ internal partial class Kernel32
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false, EntryPoint = "CreateProcessW")]
internal static extern bool CreateProcess(
string? lpApplicationName,
+#pragma warning disable CA1838 // reasonable use of StringBuilder to build up a command line
[In] StringBuilder lpCommandLine,
+#pragma warning restore CA1838
ref SECURITY_ATTRIBUTES procSecAttrs,
ref SECURITY_ATTRIBUTES threadSecAttrs,
bool bInheritHandles,
diff --git a/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs b/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs
index c56d91b3a0a49..ddaaf8a56d09c 100644
--- a/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs
+++ b/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs
@@ -43,7 +43,9 @@ public static extern SafeWinHttpHandle WinHttpOpenRequest(
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool WinHttpAddRequestHeaders(
SafeWinHttpHandle requestHandle,
+#pragma warning disable CA1838 // Uses pooled StringBuilder
[In] StringBuilder headers,
+#pragma warning restore CA1838
uint headersLength,
uint modifiers);
@@ -59,7 +61,7 @@ public static extern bool WinHttpAddRequestHeaders(
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool WinHttpSendRequest(
SafeWinHttpHandle requestHandle,
- [In] StringBuilder headers,
+ IntPtr headers,
uint headersLength,
IntPtr optional,
uint optionalLength,
diff --git a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
index b9c72520b7ea8..e118672a4a0a8 100644
--- a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
+++ b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
@@ -3,7 +3,7 @@
true
$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-Solaris;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent);netcoreapp2.0-FreeBSD;netcoreapp2.0-Linux;netcoreapp2.0-OSX;netcoreapp2.0-Windows_NT;netstandard2.0;net461-Windows_NT
true
- $(NoWarn);CA2249
+ $(NoWarn);CA2249;CA1838
enable
diff --git a/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj b/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj
index 42937d19fb581..a22f890d5bd57 100644
--- a/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj
+++ b/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj
@@ -3,6 +3,7 @@
true
$(NetCoreAppCurrent)-Windows_NT;netcoreapp2.0-Windows_NT;net461;netstandard2.0
true
+ $(NoWarn);CA1838
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs
index f741f0ae77954..cc3e39f8a7309 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs
@@ -33,7 +33,9 @@ internal static IntPtr LoadLibcups()
internal static extern void cupsFreeDests(int num_dests, IntPtr dests);
[DllImport(LibraryName, ExactSpelling = true, CharSet = CharSet.Ansi)]
- internal static extern IntPtr cupsTempFd(StringBuilder sb, int len);
+#pragma warning disable CA1838 // not hot-path enough to worry about the overheads of StringBuilder marshaling
+ internal static extern IntPtr cupsTempFd([Out] StringBuilder sb, int len);
+#pragma warning restore CA1838
[DllImport(LibraryName, ExactSpelling = true)]
internal static extern IntPtr cupsGetDefault();
diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs
index c2b405dc3fba8..40cd1d553723a 100644
--- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs
+++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs
@@ -1406,7 +1406,7 @@ private RendezvousAwaitable InternalSendRequestAsync(WinHttpRequestState st
state.Pin();
if (!Interop.WinHttp.WinHttpSendRequest(
state.RequestHandle,
- null,
+ IntPtr.Zero,
0,
IntPtr.Zero,
0,
diff --git a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/FakeInterop.cs b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/FakeInterop.cs
index 728aacd3eb27c..24e4b717859c2 100644
--- a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/FakeInterop.cs
+++ b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/FakeInterop.cs
@@ -157,7 +157,7 @@ public static SafeWinHttpHandle WinHttpOpenRequest(
public static bool WinHttpSendRequest(
SafeWinHttpHandle requestHandle,
- StringBuilder headers,
+ IntPtr headers,
uint headersLength,
IntPtr optional,
uint optionalLength,