diff --git a/eng/WpfArcadeSdk/tools/CodeAnalysis.targets b/eng/WpfArcadeSdk/tools/CodeAnalysis.targets
index 17ff34f4b5ec31a28f77f274ac8313959322dccf..dcd84e745ba028306605ef5fd48994e2e121375f 100644
--- a/eng/WpfArcadeSdk/tools/CodeAnalysis.targets
+++ b/eng/WpfArcadeSdk/tools/CodeAnalysis.targets
@@ -6,8 +6,7 @@
-
-
+
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs
index ad25b2ac38bdcb7daa39c270152074e85987e856..5311e04602299e3c1cf9063dae7cc3a655f18fe0 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs
@@ -106,7 +106,7 @@ internal bool EndsEscapeSequence(char ch)
internal bool Match(char start, char end)
{
- return _endChars.IndexOf(end.ToString()) == _startChars.IndexOf(start.ToString());
+ return _endChars.IndexOf(end.ToString(), StringComparison.Ordinal) == _startChars.IndexOf(start.ToString(), StringComparison.Ordinal);
}
internal string StartBracketCharacters
diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs
index 6362ed6d0e38c4c6613414676ce6f5855e737210..83c2b113810f90447c7375e065b91770aa8521b5 100644
--- a/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs
+++ b/src/Microsoft.DotNet.Wpf/src/Shared/System/Windows/Markup/RuntimeIdentifierPropertyAttribute.cs
@@ -48,7 +48,7 @@ public string Name
}
}
- private string _name = null;
+ private string _name;
}
#endif
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/UidPropertyAttribute.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/UidPropertyAttribute.cs
index 9696216f50d638617b41aff2be8da031a31109ab..07a19c167a72b0db18c0240a776620610c6b417d 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/UidPropertyAttribute.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/UidPropertyAttribute.cs
@@ -54,6 +54,6 @@ public string Name
}
// The name of the property that is designated to accept the x:Uid value
- private string _name = null;
+ private string _name;
}
}
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs
index 75934717af34c98d05254a2abd119eded6869b50..b0af7e5f57ce1183c30c540477a48cf0410638e9 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs
@@ -244,6 +244,9 @@ public static ValueSerializer GetSerializerFor(PropertyDescriptor descriptor, IV
///
protected Exception GetConvertToException(object value, Type destinationType)
{
+ if (destinationType == null)
+ throw new ArgumentNullException(nameof(destinationType));
+
string text;
if (value == null)
{
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs
index 21af3d22cf986c4ae3ab069d47b71f9d61815d4b..a50667e1c0626561936374c61b0b9da889858002 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs
@@ -17,7 +17,7 @@ internal class ObjectWriterContext : XamlContext
{
private XamlContextStack _stack;
- private object _rootInstance = null;
+ private object _rootInstance;
ServiceProviderContext _serviceProviderContext;
XamlRuntime _runtime;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs
index d30ddbe68d83522cbd42c526ef567ea995ad3e37..a84dbcd4e11c7f29f686fa3858ce39710c7c9bf5 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/XmlNsInfo.cs
@@ -38,7 +38,7 @@ internal IList NsDefs
}
// Note this, is the only dictionary that we synchronize, because XamlSchemaContext adds to it
- private ConcurrentDictionary> _clrToXmlNs = null;
+ private ConcurrentDictionary> _clrToXmlNs;
internal ConcurrentDictionary> ClrToXmlNs
{
get
@@ -64,7 +64,7 @@ internal ICollection InternalsVisibleTo
}
}
- private Dictionary _oldToNewNs = null;
+ private Dictionary _oldToNewNs;
internal Dictionary OldToNewNs
{
get
@@ -77,7 +77,7 @@ internal ICollection InternalsVisibleTo
}
}
- private Dictionary _prefixes = null;
+ private Dictionary _prefixes;
internal Dictionary Prefixes
{
get
@@ -90,7 +90,7 @@ internal ICollection InternalsVisibleTo
}
}
- private string _rootNamespace = null;
+ private string _rootNamespace;
internal string RootNamespace
{
get
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NamespacePrefixLookup.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NamespacePrefixLookup.cs
index 2a74fbf8dd95e838c7f6ec0a496461396fc8da14..5fbd785e46b2b3d38687af205a4743a4c0bd9a84 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NamespacePrefixLookup.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NamespacePrefixLookup.cs
@@ -20,7 +20,7 @@ public NamespacePrefixLookup(out IEnumerable newNamespaces
#region INamespacePrefixLookup Members
- private int n = 0;
+ private int n;
public string LookupPrefix(string ns)
{
// we really shouldn't generate extraneous new namespaces
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NodeStreamSorter.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NodeStreamSorter.cs
index 92971ec55d25a05ef36d85cbe1d6382a6235c96d..b30d0b006cd2ec56b6b7a7cc8d0cd40884a296ef 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NodeStreamSorter.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/NodeStreamSorter.cs
@@ -33,7 +33,7 @@ class SeenCtorDirectiveFlags
}
List _seenStack = new List();
- int _startObjectDepth = 0;
+ int _startObjectDepth;
List _moveList;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs
index 54e873c07711e23fd2b2df4e4ef45c0bb44814c3..c9798d80ea15d3a99f8deaf1146c6666d06324b3 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlName.cs
@@ -30,7 +30,7 @@ public XamlName(string prefix, string name)
public abstract string ScopedName { get; }
protected string _prefix;
- protected string _namespace = null;
+ protected string _namespace;
public string Prefix { get { return _prefix; } }
public string Namespace { get { return _namespace; } }
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs
index 187c7de0ce39070d80567394871fef21f639be73..66823a8c7a9aefe4a9d8b60fc103e14d10b8eadb 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs
@@ -931,7 +931,7 @@ private XamlNode Logic_StartItemsProperty(XamlType collectionType)
#region Optimizations
private readonly XamlTypeName arrayType = new XamlTypeName(@"http://schemas.microsoft.com/winfx/2006/xaml", "Array");
- private XamlType _arrayExtensionType = null;
+ private XamlType _arrayExtensionType;
private XamlType ArrayExtensionType
{
get
@@ -944,7 +944,7 @@ private XamlType ArrayExtensionType
}
}
- private XamlMember _arrayTypeMember = null;
+ private XamlMember _arrayTypeMember;
private XamlMember ArrayTypeMember
{
get
@@ -957,7 +957,7 @@ private XamlMember ArrayTypeMember
}
}
- private XamlMember _itemsTypeMember = null;
+ private XamlMember _itemsTypeMember;
private XamlMember ItemsTypeMember
{
get
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs
index 26d1000f5862c9f13256f1d2aa49861fa5a10543..960afb1045d96a4b0624d5fdaaee5b57dfd832e9 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/XamlScanner.cs
@@ -29,14 +29,14 @@ class XamlScanner
XamlScannerStack _scannerStack;
XamlParserContext _parserContext;
- XamlText _accumulatedText = null;
+ XamlText _accumulatedText;
List _attributes;
int _nextAttribute;
XamlScannerNode _currentNode;
Queue _readNodesQueue;
XamlXmlReaderSettings _settings;
XamlAttribute _typeArgumentAttribute;
- bool _hasKeyAttribute = false;
+ bool _hasKeyAttribute;
internal XamlScanner(XamlParserContext context, XmlReader xmlReader, XamlXmlReaderSettings settings)
{
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlBackgroundReader.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlBackgroundReader.cs
index 49798482fc777ee0cd7d94009adc41f58d9e51aa..7b01fbb782321fb8f944e9260fc5271732399daf 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlBackgroundReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlBackgroundReader.cs
@@ -29,8 +29,8 @@ public class XamlBackgroundReader : XamlReader, IXamlLineInfo
XamlWriter _writer;
bool _wrappedReaderHasLineInfo;
- int _lineNumber=0;
- int _linePosition=0;
+ int _lineNumber;
+ int _linePosition;
Thread _thread;
Exception _caughtException;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlNodeList.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlNodeList.cs
index 6959d9854cb895bec579cd92646cac053b196277..a5634c6ec0a02e3e15470cb9d573724a8b3eeed6 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlNodeList.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Primitives/XamlNodeList.cs
@@ -16,7 +16,7 @@ namespace System.Xaml
public class XamlNodeList
{
List _nodeList;
- bool _readMode = false;
+ bool _readMode;
XamlWriter _writer;
bool _hasLineInfo;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs
index 3ffd1d9922ac2932e4735949be5b1e5cf2ce6ffd..fd98273cf23c1cce7da3a49a6b992ae93bb2ea39 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/TypeReflector.cs
@@ -13,6 +13,7 @@
namespace System.Xaml.Schema
{
+ [Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2002:Do not lock on objects with weak identity", Justification = "This type is internal.")]
class TypeReflector : Reflector
{
private const XamlCollectionKind XamlCollectionKindInvalid = (XamlCollectionKind)byte.MaxValue;
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs
index d87821796c24de885b36c577566ee75c52701212..7e392514e4e233a310501a2384e0ff73d5350a80 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs
@@ -994,7 +994,7 @@ abstract class ObjectOrValueMarkupInfo : MarkupInfo
class ObjectMarkupInfo : ObjectOrValueMarkupInfo
{
List properties = new List();
- bool? isAttributableMarkupExtension = null;
+ bool? isAttributableMarkupExtension;
public List Properties { get { return properties; } }
public string Name { get; set; }
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs
index 07fc3679d69c40869f65ba9b07b022508fa28284..788933c98a2469c6ebaf83a06edb6ea29e67cd9f 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs
@@ -542,6 +542,9 @@ private string GetCompatibleNamespace(string oldNs)
public virtual XamlType GetXamlType(Type type)
{
+ if (type == null)
+ throw new ArgumentNullException(nameof(type));
+
return GetXamlType(type, XamlLanguage.TypeAlias(type));
}
@@ -683,7 +686,7 @@ internal virtual XamlMember GetAttachableEvent(string name, MethodInfo adder)
#region Settings
// Unchanging, initialized in ctor
- private readonly XamlSchemaContextSettings _settings = null;
+ private readonly XamlSchemaContextSettings _settings;
public bool SupportMarkupExtensionsWithDuplicateArity
{
diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlServices.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlServices.cs
index 7622a2739970229d68a83bb8f097363b67a2512d..3b6883320ac12eca7026c1cb69d4a07886b52396 100644
--- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlServices.cs
+++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlServices.cs
@@ -8,6 +8,7 @@
namespace System.Xaml
{
+ [Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The IDisposable types in this class don't require dispose.")]
public static class XamlServices
{
// The main function is Load(XamlReader)