Remove the defunct DiagnosticUtility/Fx classes from DataContractSerialization (...
authorStephen Toub <stoub@microsoft.com>
Tue, 14 Mar 2023 19:41:48 +0000 (15:41 -0400)
committerGitHub <noreply@github.com>
Tue, 14 Mar 2023 19:41:48 +0000 (12:41 -0700)
- Fx.Assert just delegated to Debug.Assert: replace all the call sites with Debug.Assert/Fail.
- DiagnosticUtility.DebugAssert just delegated to Debug.Assert: replace all the call sites with Debug.Assert/Fail.
- DiagnosticUtility.ExceptionUtility.ThrowHelperError didn't throw anything and just returned its argument: removed all uses of it
- DiagnosticUtility.ExceptionUtility.ThrowHelperCallback didn't throw anything and just returned its argument: removed all uses of it.
- DiagnosticUtility.ExceptionUtility.ThrowHelperFatal didn't throw anything and just wrapped its arguments in a new Exception that was then returned: just changed the call sites to create that exception.
- DiagnosticUtility.ExceptionUtility.ThrowHelperArgument{Null} didn't throw anything and just returned new instances of Argument{Null}Exception: just changed the call sites to create that exception.
- Replaced some argument validation with helpers like ThrowIfNegative.
- Fx.IsFatal: moved to ExceptionUtility class

70 files changed:
src/libraries/System.Private.DataContractSerialization/src/Resources/Strings.resx
src/libraries/System.Private.DataContractSerialization/src/System.Private.DataContractSerialization.csproj
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/AccessorBuilder.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Attributes.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/CodeGenerator.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/CollectionDataContract.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContractSerializer.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContractSet.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DateTimeOffsetAdapter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DiagnosticUtility.cs [deleted file]
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/EnumDataContract.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ExceptionUtility.cs [new file with mode: 0644]
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ExtensionDataReader.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/HybridObjectCache.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/DataContractJsonSerializer.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonDataContract.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatReaderGenerator.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/ReflectionJsonFormatReader.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlJsonReader.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlJsonWriter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerReadContextComplexJson.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerWriteContextComplexJson.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/KnownTypeDataContractResolver.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ObjectReferenceStack.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ObjectToIdCache.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ReflectionReader.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/SchemaExporter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/SchemaImporter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XPathQueryGenerator.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlDataContract.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatReaderGenerator.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializer.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerContext.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerReadContext.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerReadContextComplex.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerWriteContext.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerWriteContextComplex.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlReaderDelegator.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlSerializableReader.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlSerializableServices.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlSerializableWriter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlWriterDelegator.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XsdDataContractExporter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Text/Base64Encoding.cs
src/libraries/System.Private.DataContractSerialization/src/System/Text/BinHexEncoding.cs
src/libraries/System.Private.DataContractSerialization/src/System/Text/SurrogateChar.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/ValueHandle.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseReader.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseWriter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBinaryReader.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBinaryReaderSession.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBinaryWriter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBinaryWriterSession.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBufferReader.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlCanonicalWriter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlConverter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryReader.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryReaderQuotas.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryString.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryWriter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlExceptionHelper.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlNodeWriter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlStreamNodeWriter.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlUTF8TextReader.cs

index 4cee84fe5e6392ef5965c4103900116f79fbe59e..fc55a5bcb1b4903f931a5c95c8dcde415d974b57 100644 (file)
   <data name="AttributedTypesCannotInheritFromNonAttributedSerializableTypes" xml:space="preserve">
     <value>Type '{0}' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute.  Consider marking the base type '{1}' with DataContractAttribute or SerializableAttribute, or removing them from the derived type.</value>
   </data>
-  <data name="QuotaMustBePositive" xml:space="preserve">
-    <value>Quota must be a positive value.</value>
-  </data>
   <data name="QuotaIsReadOnly" xml:space="preserve">
     <value>The '{0}' quota is readonly.</value>
   </data>
   <data name="UnknownConstantType" xml:space="preserve">
     <value>Internal Error: Unrecognized constant type {0}.</value>
   </data>
-  <data name="ValueMustBeNonNegative" xml:space="preserve">
-    <value>The value of this argument must be non-negative.</value>
-  </data>
   <data name="ValueTypeCannotBeNull" xml:space="preserve">
     <value>ValueType '{0}' cannot be null.</value>
   </data>
index 75bbe5dba7b630a990a41507b51be400d29a7db3..e5751e432067914b0270087a1648038c956f0f3a 100644 (file)
@@ -25,7 +25,6 @@
     <Compile Include="$(RuntimeSerializationSources)\CollectionDataContract.cs" />
     <Compile Include="$(RuntimeSerializationSources)\DataContract.cs" />
     <Compile Include="$(RuntimeSerializationSources)\DateTimeOffsetAdapter.cs" />
-    <Compile Include="$(RuntimeSerializationSources)\DiagnosticUtility.cs" />
     <Compile Include="$(RuntimeSerializationSources)\DictionaryGlobals.cs" />
     <Compile Include="$(RuntimeSerializationSources)\DataContractResolver.cs" />
     <Compile Include="$(RuntimeSerializationSources)\DataContractSerializer.cs" />
@@ -35,6 +34,7 @@
     <Compile Include="$(RuntimeSerializationSources)\DataContractSurrogateCaller.cs" />
     <Compile Include="$(RuntimeSerializationSources)\DataMember.cs" />
     <Compile Include="$(RuntimeSerializationSources)\EnumDataContract.cs" />
+    <Compile Include="$(RuntimeSerializationSources)\ExceptionUtility.cs" />
     <Compile Include="$(RuntimeSerializationSources)\ExportOptions.cs" />
     <Compile Include="$(RuntimeSerializationSources)\ExtensionDataObject.cs" />
     <Compile Include="$(RuntimeSerializationSources)\ExtensionDataReader.cs" />
index 153e4f3ab238392d4af6ae96cd05ff0811ab44f9..d6cc02e90fbdc45db3b25d65be2164d0abda598f 100644 (file)
@@ -88,7 +88,7 @@ namespace System.Runtime.Serialization
             }
             else
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.InvalidMember, DataContract.GetClrTypeFullName(memberInfo.DeclaringType!), memberInfo.Name)));
+                throw new InvalidOperationException(SR.Format(SR.InvalidMember, DataContract.GetClrTypeFullName(memberInfo.DeclaringType!), memberInfo.Name));
             }
         }
 
@@ -140,7 +140,7 @@ namespace System.Runtime.Serialization
                 }
                 else
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.NoSetMethodForProperty, propInfo.DeclaringType, propInfo.Name)));
+                    throw new InvalidOperationException(SR.Format(SR.NoSetMethodForProperty, propInfo.DeclaringType, propInfo.Name));
                 }
             }
             else if (memberInfo is FieldInfo fieldInfo)
@@ -152,7 +152,7 @@ namespace System.Runtime.Serialization
             }
             else
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.InvalidMember, DataContract.GetClrTypeFullName(memberInfo.DeclaringType!), memberInfo.Name)));
+                throw new InvalidOperationException(SR.Format(SR.InvalidMember, DataContract.GetClrTypeFullName(memberInfo.DeclaringType!), memberInfo.Name));
             }
         }
 
index 1367f3c0dacbfbe425b3d60d32af627c724e5ef5..22c79aabe500d9c8044ecd628d284a6ea6e2e6ce 100644 (file)
@@ -105,7 +105,7 @@ namespace System.Runtime.Serialization
             Id = reader.ReadContentAsString();
             if (string.IsNullOrEmpty(Id))
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidXsIdDefinition, Id)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidXsIdDefinition, Id));
             }
         }
 
@@ -114,7 +114,7 @@ namespace System.Runtime.Serialization
             Ref = reader.ReadContentAsString();
             if (string.IsNullOrEmpty(Ref))
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidXsRefDefinition, Ref)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidXsRefDefinition, Ref));
             }
         }
 
@@ -127,7 +127,7 @@ namespace System.Runtime.Serialization
         {
             ArraySZSize = reader.ReadContentAsInt();
             if (ArraySZSize < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidSizeDefinition, ArraySZSize)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidSizeDefinition, ArraySZSize));
         }
 
         private void ReadXsiType(XmlReaderDelegator reader)
index 8e0141cb41f64fd8fd7094e1e59639c2abf5c271..c85fd6c23a6b848fe75e610e5a47c43fcd1c2951 100644 (file)
@@ -406,11 +406,10 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustDataContractTypeNotPublic,
                                 DataContract.GetClrTypeFullName(UnderlyingType)),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -421,11 +420,10 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustIXmlSerialzableNoPublicConstructor,
                                 DataContract.GetClrTypeFullName(UnderlyingType)),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -434,11 +432,10 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustNonAttributedSerializableTypeNoPublicConstructor,
                                 DataContract.GetClrTypeFullName(UnderlyingType)),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -447,12 +444,11 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustDataContractOnDeserializingNotPublic,
                                 DataContract.GetClrTypeFullName(UnderlyingType),
                                 OnDeserializing!.Name),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -461,12 +457,11 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustDataContractOnDeserializedNotPublic,
                                 DataContract.GetClrTypeFullName(UnderlyingType),
                                 OnDeserialized!.Name),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -481,21 +476,19 @@ namespace System.Runtime.Serialization.DataContracts
                         {
                             if (Members[i].MemberInfo is FieldInfo)
                             {
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                                    new SecurityException(SR.Format(
+                                throw new SecurityException(SR.Format(
                                             SR.PartialTrustDataContractFieldSetNotPublic,
                                             DataContract.GetClrTypeFullName(UnderlyingType),
                                             Members[i].MemberInfo.Name),
-                                        securityException));
+                                        securityException);
                             }
                             else
                             {
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                                    new SecurityException(SR.Format(
+                                throw new SecurityException(SR.Format(
                                             SR.PartialTrustDataContractPropertySetNotPublic,
                                             DataContract.GetClrTypeFullName(UnderlyingType),
                                             Members[i].MemberInfo.Name),
-                                        securityException));
+                                        securityException);
                             }
                         }
                         return true;
@@ -519,11 +512,10 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustDataContractTypeNotPublic,
                                 DataContract.GetClrTypeFullName(UnderlyingType)),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -535,12 +527,11 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustDataContractOnSerializingNotPublic,
                                 DataContract.GetClrTypeFullName(UnderlyingType),
                                 OnSerializing!.Name),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -549,12 +540,11 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustDataContractOnSerializedNotPublic,
                                 DataContract.GetClrTypeFullName(UnderlyingType),
                                 OnSerialized!.Name),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -569,21 +559,19 @@ namespace System.Runtime.Serialization.DataContracts
                         {
                             if (Members[i].MemberInfo is FieldInfo)
                             {
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                                    new SecurityException(SR.Format(
+                                throw new SecurityException(SR.Format(
                                             SR.PartialTrustDataContractFieldGetNotPublic,
                                             DataContract.GetClrTypeFullName(UnderlyingType),
                                             Members[i].MemberInfo.Name),
-                                        securityException));
+                                        securityException);
                             }
                             else
                             {
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                                    new SecurityException(SR.Format(
+                                throw new SecurityException(SR.Format(
                                             SR.PartialTrustDataContractPropertyGetNotPublic,
                                             DataContract.GetClrTypeFullName(UnderlyingType),
                                             Members[i].MemberInfo.Name),
-                                        securityException));
+                                        securityException);
                             }
                         }
                         return true;
@@ -646,7 +634,7 @@ namespace System.Runtime.Serialization.DataContracts
                 if (IsISerializable)
                 {
                     if (HasDataContract)
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.ISerializableCannotHaveDataContract, DataContract.GetClrTypeFullName(type))));
+                        throw new InvalidDataContractException(SR.Format(SR.ISerializableCannotHaveDataContract, DataContract.GetClrTypeFullName(type)));
                     if (baseType != null && !(baseType.IsSerializable && Globals.TypeOfISerializable.IsAssignableFrom(baseType)))
                         baseType = null;
                 }
@@ -665,9 +653,8 @@ namespace System.Runtime.Serialization.DataContracts
 
                     if (BaseClassContract != null && BaseClassContract.IsNonAttributedType && !_isNonAttributedType)
                     {
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError
-                            (new InvalidDataContractException(SR.Format(SR.AttributedTypesCannotInheritFromNonAttributedSerializableTypes,
-                            DataContract.GetClrTypeFullName(type), DataContract.GetClrTypeFullName(baseType))));
+                        throw new InvalidDataContractException(SR.Format(SR.AttributedTypesCannotInheritFromNonAttributedSerializableTypes,
+                            DataContract.GetClrTypeFullName(type), DataContract.GetClrTypeFullName(baseType)));
                     }
                 }
                 else
@@ -678,7 +665,7 @@ namespace System.Runtime.Serialization.DataContracts
                 _hasExtensionData = (Globals.TypeOfIExtensibleDataObject.IsAssignableFrom(type));
                 if (_hasExtensionData && !HasDataContract && !IsNonAttributedType)
                 {
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.OnlyDataContractTypesCanHaveExtensionData, DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.OnlyDataContractTypesCanHaveExtensionData, DataContract.GetClrTypeFullName(type)));
                 }
 
                 if (IsISerializable)
@@ -1252,7 +1239,7 @@ namespace System.Runtime.Serialization.DataContracts
 
                 ConstructorInfo? ctor = UnderlyingType.GetConstructor(Globals.ScanAllMembers, SerInfoCtorArgs);
                 if (ctor == null)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.SerializationInfo_ConstructorNotFound, DataContract.GetClrTypeFullName(UnderlyingType))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.SerializationInfo_ConstructorNotFound, DataContract.GetClrTypeFullName(UnderlyingType)));
 
                 return ctor;
             }
@@ -1269,7 +1256,7 @@ namespace System.Runtime.Serialization.DataContracts
 
                 ConstructorInfo? ctor = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Type.EmptyTypes);
                 if (ctor == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.NonAttributedSerializableTypesMustHaveDefaultConstructor, DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.NonAttributedSerializableTypesMustHaveDefaultConstructor, DataContract.GetClrTypeFullName(type)));
 
                 return ctor;
             }
index 45de843e4e1caff685a9f8c446b6b76d0dbfe7cc..8366258cc00d8bddb3bd666df9602bd6b518a362 100644 (file)
@@ -359,7 +359,7 @@ namespace System.Runtime.Serialization
                 case Cmp.NotEqualTo:
                     return OpCodes.Beq;
                 default:
-                    DiagnosticUtility.DebugAssert(cmp == Cmp.GreaterThanOrEqualTo, "Unexpected cmp");
+                    Debug.Assert(cmp == Cmp.GreaterThanOrEqualTo, "Unexpected cmp");
                     return OpCodes.Blt;
             }
         }
@@ -416,7 +416,7 @@ namespace System.Runtime.Serialization
         internal static void VerifyParameterCount(MethodInfo methodInfo, int expectedCount)
         {
             if (methodInfo.GetParameters().Length != expectedCount)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ParameterCountMismatch, methodInfo.Name, methodInfo.GetParameters().Length, expectedCount)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ParameterCountMismatch, methodInfo.Name, methodInfo.GetParameters().Length, expectedCount));
         }
 
         internal void Call(object? thisObj, MethodInfo methodInfo)
@@ -588,7 +588,7 @@ namespace System.Runtime.Serialization
                 memberType = property.PropertyType;
                 MethodInfo? getMethod = property.GetMethod;
                 if (getMethod == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NoGetMethodForProperty, property.DeclaringType, property)));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NoGetMethodForProperty, property.DeclaringType, property));
                 Call(getMethod);
             }
             else if (memberInfo is MethodInfo method)
@@ -597,7 +597,7 @@ namespace System.Runtime.Serialization
                 Call(method);
             }
             else
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotLoadMemberType, "Unknown", memberInfo.DeclaringType, memberInfo.Name)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotLoadMemberType, "Unknown", memberInfo.DeclaringType, memberInfo.Name));
 
             return memberType;
         }
@@ -619,13 +619,13 @@ namespace System.Runtime.Serialization
             {
                 MethodInfo? setMethod = property.SetMethod;
                 if (setMethod == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NoSetMethodForProperty, property.DeclaringType, property)));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NoSetMethodForProperty, property.DeclaringType, property));
                 Call(setMethod);
             }
             else if (memberInfo is MethodInfo method)
                 Call(method);
             else
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotLoadMemberType, "Unknown")));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotLoadMemberType, "Unknown"));
         }
 
         internal void LoadDefaultValue(Type type)
@@ -692,8 +692,8 @@ namespace System.Runtime.Serialization
                 Stloc(localBuilder);
             else
             {
-                DiagnosticUtility.DebugAssert("Data can only be stored into ArgBuilder or LocalBuilder.");
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CanOnlyStoreIntoArgOrLocGot0, DataContract.GetClrTypeFullName(var.GetType()))));
+                Debug.Fail("Data can only be stored into ArgBuilder or LocalBuilder.");
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CanOnlyStoreIntoArgOrLocGot0, DataContract.GetClrTypeFullName(var.GetType())));
             }
         }
 
@@ -815,8 +815,8 @@ namespace System.Runtime.Serialization
                         Ldc((bool)o);
                         break;
                     case TypeCode.Char:
-                        DiagnosticUtility.DebugAssert("Char is not a valid schema primitive and should be treated as int in DataContract");
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.CharIsInvalidPrimitive));
+                        Debug.Fail("Char is not a valid schema primitive and should be treated as int in DataContract");
+                        throw new NotSupportedException(SR.CharIsInvalidPrimitive);
                     case TypeCode.SByte:
                     case TypeCode.Byte:
                     case TypeCode.Int16:
@@ -850,7 +850,7 @@ namespace System.Runtime.Serialization
                     case TypeCode.Empty:
                     case TypeCode.DBNull:
                     default:
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.UnknownConstantType, DataContract.GetClrTypeFullName(valueType))));
+                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.UnknownConstantType, DataContract.GetClrTypeFullName(valueType)));
                 }
             }
         }
@@ -989,7 +989,7 @@ namespace System.Runtime.Serialization
             {
                 OpCode opCode = GetLdelemOpCode(Type.GetTypeCode(arrayElementType));
                 if (opCode.Equals(OpCodes.Nop))
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayTypeIsNotSupported_GeneratingCode, DataContract.GetClrTypeFullName(arrayElementType))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayTypeIsNotSupported_GeneratingCode, DataContract.GetClrTypeFullName(arrayElementType)));
                 _ilGen.Emit(opCode);
             }
         }
@@ -1027,7 +1027,7 @@ namespace System.Runtime.Serialization
             {
                 OpCode opCode = GetStelemOpCode(Type.GetTypeCode(arrayElementType));
                 if (opCode.Equals(OpCodes.Nop))
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayTypeIsNotSupported_GeneratingCode, DataContract.GetClrTypeFullName(arrayElementType))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayTypeIsNotSupported_GeneratingCode, DataContract.GetClrTypeFullName(arrayElementType)));
                 _ilGen.Emit(opCode);
             }
         }
@@ -1157,7 +1157,7 @@ namespace System.Runtime.Serialization
                 {
                     OpCode opCode = GetConvOpCode(Type.GetTypeCode(target));
                     if (opCode.Equals(OpCodes.Nop))
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NoConversionPossibleTo, DataContract.GetClrTypeFullName(target))));
+                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NoConversionPossibleTo, DataContract.GetClrTypeFullName(target)));
                     else
                     {
                         _ilGen.Emit(opCode);
@@ -1170,7 +1170,7 @@ namespace System.Runtime.Serialization
                         Ldobj(target);
                 }
                 else
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsNotAssignableFrom, DataContract.GetClrTypeFullName(target), DataContract.GetClrTypeFullName(source))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsNotAssignableFrom, DataContract.GetClrTypeFullName(target), DataContract.GetClrTypeFullName(source)));
             }
             else if (target.IsAssignableFrom(source))
             {
@@ -1190,7 +1190,7 @@ namespace System.Runtime.Serialization
                 Castclass(target);
             }
             else
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsNotAssignableFrom, DataContract.GetClrTypeFullName(target), DataContract.GetClrTypeFullName(source))));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsNotAssignableFrom, DataContract.GetClrTypeFullName(target), DataContract.GetClrTypeFullName(source)));
         }
 
         private IfState PopIfState()
@@ -1205,7 +1205,7 @@ namespace System.Runtime.Serialization
         [DoesNotReturn]
         private static void ThrowMismatchException(object expected)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExpectingEnd, expected.ToString())));
+            throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExpectingEnd, expected.ToString()));
         }
 
         internal Label[] Switch(int labelCount)
index a5f0aacc00ae57925e0f25cac2ab101e6609213a..cd600ee2a0a5d392897fd0c95367730b6ff6ab87 100644 (file)
@@ -352,7 +352,7 @@ namespace System.Runtime.Serialization.DataContracts
                         {
                             if (UnderlyingType.IsInterface && (Kind == CollectionKind.Enumerable || Kind == CollectionKind.Collection || Kind == CollectionKind.GenericEnumerable))
                             {
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GetOnlyCollectionMustHaveAddMethod, GetClrTypeFullName(UnderlyingType))));
+                                throw new InvalidDataContractException(SR.Format(SR.GetOnlyCollectionMustHaveAddMethod, GetClrTypeFullName(UnderlyingType)));
                             }
 
                             if (IsReadOnlyContract)
@@ -362,7 +362,7 @@ namespace System.Runtime.Serialization.DataContracts
 
                             if (Kind != CollectionKind.Array && AddMethod == null)
                             {
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GetOnlyCollectionMustHaveAddMethod, GetClrTypeFullName(UnderlyingType))));
+                                throw new InvalidDataContractException(SR.Format(SR.GetOnlyCollectionMustHaveAddMethod, GetClrTypeFullName(UnderlyingType)));
                             }
 
                             XmlFormatGetOnlyCollectionReaderDelegate tempDelegate = CreateXmlFormatGetOnlyCollectionReaderDelegate();
@@ -456,24 +456,24 @@ namespace System.Runtime.Serialization.DataContracts
                         if (collectionContractAttribute.IsItemNameSetExplicitly)
                         {
                             if (collectionContractAttribute.ItemName == null || collectionContractAttribute.ItemName.Length == 0)
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractItemName, DataContract.GetClrTypeFullName(UnderlyingType))));
+                                throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractItemName, DataContract.GetClrTypeFullName(UnderlyingType)));
                             itemName = DataContract.EncodeLocalName(collectionContractAttribute.ItemName);
                             _itemNameSetExplicit = true;
                         }
                         if (collectionContractAttribute.IsKeyNameSetExplicitly)
                         {
                             if (collectionContractAttribute.KeyName == null || collectionContractAttribute.KeyName.Length == 0)
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractKeyName, DataContract.GetClrTypeFullName(UnderlyingType))));
+                                throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractKeyName, DataContract.GetClrTypeFullName(UnderlyingType)));
                             if (!isDictionary)
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractKeyNoDictionary, DataContract.GetClrTypeFullName(UnderlyingType), collectionContractAttribute.KeyName)));
+                                throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractKeyNoDictionary, DataContract.GetClrTypeFullName(UnderlyingType), collectionContractAttribute.KeyName));
                             keyName = DataContract.EncodeLocalName(collectionContractAttribute.KeyName);
                         }
                         if (collectionContractAttribute.IsValueNameSetExplicitly)
                         {
                             if (collectionContractAttribute.ValueName == null || collectionContractAttribute.ValueName.Length == 0)
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractValueName, DataContract.GetClrTypeFullName(UnderlyingType))));
+                                throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractValueName, DataContract.GetClrTypeFullName(UnderlyingType)));
                             if (!isDictionary)
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractValueNoDictionary, DataContract.GetClrTypeFullName(UnderlyingType), collectionContractAttribute.ValueName)));
+                                throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractValueNoDictionary, DataContract.GetClrTypeFullName(UnderlyingType), collectionContractAttribute.ValueName));
                             valueName = DataContract.EncodeLocalName(collectionContractAttribute.ValueName);
                         }
                     }
@@ -504,7 +504,7 @@ namespace System.Runtime.Serialization.DataContracts
                 if (type == Globals.TypeOfArray)
                     type = Globals.TypeOfObjectArray;
                 if (type.GetArrayRank() > 1)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.SupportForMultidimensionalArraysNotPresent));
+                    throw new NotSupportedException(SR.SupportForMultidimensionalArraysNotPresent);
                 XmlName = DataContract.GetXmlName(type);
                 Init(CollectionKind.Array, type.GetElementType(), null);
             }
@@ -529,7 +529,7 @@ namespace System.Runtime.Serialization.DataContracts
                 DataContract itemContract) : base(type)
             {
                 if (type.GetArrayRank() > 1)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.SupportForMultidimensionalArraysNotPresent));
+                    throw new NotSupportedException(SR.SupportForMultidimensionalArraysNotPresent);
                 XmlName = CreateQualifiedName(Globals.ArrayPrefix + itemContract.XmlName.Name, itemContract.XmlName.Namespace);
                 _itemContract = itemContract;
                 Init(CollectionKind.Array, type.GetElementType(), null);
@@ -545,9 +545,9 @@ namespace System.Runtime.Serialization.DataContracts
                 : base(type)
             {
                 if (getEnumeratorMethod == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.CollectionMustHaveGetEnumeratorMethod, GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.CollectionMustHaveGetEnumeratorMethod, GetClrTypeFullName(type)));
                 if (itemType == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.CollectionMustHaveItemType, GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.CollectionMustHaveItemType, GetClrTypeFullName(type)));
 
                 CollectionDataContractAttribute? collectionContractAttribute;
                 XmlName = DataContract.GetCollectionXmlName(type, itemType, out collectionContractAttribute);
@@ -568,7 +568,7 @@ namespace System.Runtime.Serialization.DataContracts
                 : this(type, kind, itemType, getEnumeratorMethod, (string?)null, (string?)null)
             {
                 if (addMethod == null && !type.IsInterface)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.CollectionMustHaveAddMethod, DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.CollectionMustHaveAddMethod, DataContract.GetClrTypeFullName(type)));
 
                 _addMethod = addMethod;
                 _constructor = constructor;
@@ -1247,7 +1247,7 @@ namespace System.Runtime.Serialization.DataContracts
             if (hasCollectionDataContract)
             {
                 if (tryCreate)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(GetInvalidCollectionMessage(message, SR.Format(SR.InvalidCollectionDataContract, DataContract.GetClrTypeFullName(type)), param)));
+                    throw new InvalidDataContractException(GetInvalidCollectionMessage(message, SR.Format(SR.InvalidCollectionDataContract, DataContract.GetClrTypeFullName(type)), param));
                 return true;
             }
 
@@ -1408,7 +1408,7 @@ namespace System.Runtime.Serialization.DataContracts
             }
 
             if (InvalidCollectionInSharedContractMessage != null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(InvalidCollectionInSharedContractMessage));
+                throw new InvalidDataContractException(InvalidCollectionInSharedContractMessage);
             return this;
         }
 
@@ -1416,7 +1416,7 @@ namespace System.Runtime.Serialization.DataContracts
         {
             if (Constructor == null)
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.CollectionTypeDoesNotHaveDefaultCtor, DataContract.GetClrTypeFullName(UnderlyingType))));
+                throw new InvalidDataContractException(SR.Format(SR.CollectionTypeDoesNotHaveDefaultCtor, DataContract.GetClrTypeFullName(UnderlyingType)));
             }
             else
             {
@@ -1440,11 +1440,10 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustCollectionContractTypeNotPublic,
                                 DataContract.GetClrTypeFullName(UnderlyingType)),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -1452,11 +1451,10 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustCollectionContractTypeNotPublic,
                                 DataContract.GetClrTypeFullName(ItemType)),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -1464,11 +1462,10 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustCollectionContractNoPublicConstructor,
                                 DataContract.GetClrTypeFullName(UnderlyingType)),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -1476,12 +1473,11 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                           new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                    SR.PartialTrustCollectionContractAddMethodNotPublic,
                                    DataContract.GetClrTypeFullName(UnderlyingType),
                                    AddMethod!.Name),
-                               securityException));
+                               securityException);
                 }
                 return true;
             }
@@ -1500,11 +1496,10 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustCollectionContractTypeNotPublic,
                                 DataContract.GetClrTypeFullName(UnderlyingType)),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
@@ -1512,11 +1507,10 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(
+                    throw new SecurityException(SR.Format(
                                 SR.PartialTrustCollectionContractTypeNotPublic,
                                 DataContract.GetClrTypeFullName(ItemType)),
-                            securityException));
+                            securityException);
                 }
                 return true;
             }
index 80b9a5b8d8ef0209ba584949ccb29760d3605f9c..3cf45d25769912a5d07e02de93967bd957197c51 100644 (file)
@@ -88,7 +88,7 @@ namespace System.Runtime.Serialization.DataContracts
             dataContract = dataContract.GetValidContract();
             if (dataContract is ClassDataContract)
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(SR.ErrorDeserializing, SR.Format(SR.ErrorTypeInfo, DataContract.GetClrTypeFullName(dataContract.UnderlyingType)), SR.Format(SR.NoSetMethodForProperty, string.Empty, string.Empty))));
+                throw new SerializationException(SR.Format(SR.ErrorDeserializing, SR.Format(SR.ErrorTypeInfo, DataContract.GetClrTypeFullName(dataContract.UnderlyingType)), SR.Format(SR.NoSetMethodForProperty, string.Empty, string.Empty)));
             }
             return dataContract;
         }
@@ -167,26 +167,26 @@ namespace System.Runtime.Serialization.DataContracts
         [RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
         internal virtual void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext? context)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.UnexpectedContractType, DataContract.GetClrTypeFullName(GetType()), DataContract.GetClrTypeFullName(UnderlyingType))));
+            throw new InvalidDataContractException(SR.Format(SR.UnexpectedContractType, DataContract.GetClrTypeFullName(GetType()), DataContract.GetClrTypeFullName(UnderlyingType)));
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
         [RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
         internal virtual object? ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext? context)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.UnexpectedContractType, DataContract.GetClrTypeFullName(GetType()), DataContract.GetClrTypeFullName(UnderlyingType))));
+            throw new InvalidDataContractException(SR.Format(SR.UnexpectedContractType, DataContract.GetClrTypeFullName(GetType()), DataContract.GetClrTypeFullName(UnderlyingType)));
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
         [RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
         internal virtual void WriteXmlElement(XmlWriterDelegator xmlWriter, object? obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString? ns)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.UnexpectedContractType, DataContract.GetClrTypeFullName(GetType()), DataContract.GetClrTypeFullName(UnderlyingType))));
+            throw new InvalidDataContractException(SR.Format(SR.UnexpectedContractType, DataContract.GetClrTypeFullName(GetType()), DataContract.GetClrTypeFullName(UnderlyingType)));
         }
 
         internal virtual object ReadXmlElement(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.UnexpectedContractType, DataContract.GetClrTypeFullName(GetType()), DataContract.GetClrTypeFullName(UnderlyingType))));
+            throw new InvalidDataContractException(SR.Format(SR.UnexpectedContractType, DataContract.GetClrTypeFullName(GetType()), DataContract.GetClrTypeFullName(UnderlyingType)));
         }
 
         public virtual bool IsValueType
@@ -362,7 +362,7 @@ namespace System.Runtime.Serialization.DataContracts
                 DataContract dataContract = s_dataContractCache[id];
                 if (dataContract == null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.DataContractCacheOverflow));
+                    throw new SerializationException(SR.DataContractCacheOverflow);
                 }
                 return dataContract;
             }
@@ -382,7 +382,7 @@ namespace System.Runtime.Serialization.DataContracts
                         return i;
                     }
                 }
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.DataContractCacheOverflow));
+                throw new SerializationException(SR.DataContractCacheOverflow);
             }
 
             private static bool ContractMatches(DataContract contract, DataContract cachedContract)
@@ -414,8 +414,8 @@ namespace System.Runtime.Serialization.DataContracts
                             int newSize = (nextId < int.MaxValue / 2) ? nextId * 2 : int.MaxValue;
                             if (newSize <= nextId)
                             {
-                                DiagnosticUtility.DebugAssert("DataContract cache overflow");
-                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.DataContractCacheOverflow));
+                                Debug.Fail("DataContract cache overflow");
+                                throw new SerializationException(SR.DataContractCacheOverflow);
                             }
                             Array.Resize<DataContract>(ref s_dataContractCache, newSize);
                         }
@@ -425,12 +425,9 @@ namespace System.Runtime.Serialization.DataContracts
                         return id.Value;
                     }
                 }
-                catch (Exception ex)
+                catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
                 {
-                    if (Fx.IsFatal(ex))
-                        throw;
-
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperFatal(ex.Message, ex);
+                    throw new Exception(ex.Message, ex);
                 }
             }
 
@@ -927,12 +924,9 @@ namespace System.Runtime.Serialization.DataContracts
                         return key;
                     }
                 }
-                catch (Exception ex)
+                catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
                 {
-                    if (Fx.IsFatal(ex))
-                        throw;
-
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperFatal(ex.Message, ex);
+                    throw new Exception(ex.Message, ex);
                 }
             }
 
@@ -948,12 +942,9 @@ namespace System.Runtime.Serialization.DataContracts
                         {
                             s_clrTypeStrings.Add(Globals.TypeOfInt.Assembly.FullName!, s_clrTypeStringsDictionary.Add(Globals.MscorlibAssemblyName));
                         }
-                        catch (Exception ex)
+                        catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
                         {
-                            if (Fx.IsFatal(ex))
-                                throw;
-
-                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperFatal(ex.Message, ex);
+                            throw new Exception(ex.Message, ex);
                         }
                     }
                     if (s_clrTypeStrings.TryGetValue(key, out XmlDictionaryString? value))
@@ -963,12 +954,9 @@ namespace System.Runtime.Serialization.DataContracts
                     {
                         s_clrTypeStrings.Add(key, value);
                     }
-                    catch (Exception ex)
+                    catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
                     {
-                        if (Fx.IsFatal(ex))
-                            throw;
-
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperFatal(ex.Message, ex);
+                        throw new Exception(ex.Message, ex);
                     }
                     return value;
                 }
@@ -994,7 +982,7 @@ namespace System.Runtime.Serialization.DataContracts
                     }
                 }
 
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(message));
+                throw new InvalidDataContractException(message);
             }
 
             internal DataContractCriticalHelper(
@@ -1199,7 +1187,7 @@ namespace System.Runtime.Serialization.DataContracts
                 itemType = itemTypeQueue.Dequeue();
                 if (previousCollectionTypes.Contains(itemType))
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.RecursiveCollectionType, GetClrTypeFullName(itemType))));
+                    throw new InvalidDataContractException(SR.Format(SR.RecursiveCollectionType, GetClrTypeFullName(itemType)));
                 }
                 if (itemType.IsGenericType)
                 {
@@ -1321,7 +1309,7 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 name = dataContractAttribute.Name;
                 if (name == null || name.Length == 0)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidDataContractName, DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.InvalidDataContractName, DataContract.GetClrTypeFullName(type)));
                 if (type.IsGenericType && !type.IsGenericTypeDefinition)
                     name = ExpandGenericParameters(name, type);
                 name = DataContract.EncodeLocalName(name);
@@ -1333,7 +1321,7 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 ns = dataContractAttribute.Namespace;
                 if (ns == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidDataContractNamespace, DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.InvalidDataContractNamespace, DataContract.GetClrTypeFullName(type)));
                 CheckExplicitDataContractNamespaceUri(ns, type);
             }
             else
@@ -1401,7 +1389,7 @@ namespace System.Runtime.Serialization.DataContracts
             {
 #if DEBUG
                 if (dataContractAttributes.Length > 1)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.TooManyDataContracts, DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.TooManyDataContracts, DataContract.GetClrTypeFullName(type)));
 #endif
                 dataContractAttribute = (DataContractAttribute)dataContractAttributes[0];
             }
@@ -1426,14 +1414,14 @@ namespace System.Runtime.Serialization.DataContracts
             {
 #if DEBUG
                 if (collectionContractAttributes.Length > 1)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.TooManyCollectionContracts, DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.TooManyCollectionContracts, DataContract.GetClrTypeFullName(type)));
 #endif
                 collectionContractAttribute = (CollectionDataContractAttribute)collectionContractAttributes[0];
                 if (collectionContractAttribute.IsNameSetExplicitly)
                 {
                     name = collectionContractAttribute.Name;
                     if (name == null || name.Length == 0)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractName, DataContract.GetClrTypeFullName(type))));
+                        throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractName, DataContract.GetClrTypeFullName(type)));
                     if (type.IsGenericType && !type.IsGenericTypeDefinition)
                         name = ExpandGenericParameters(name, type);
                     name = DataContract.EncodeLocalName(name);
@@ -1445,7 +1433,7 @@ namespace System.Runtime.Serialization.DataContracts
                 {
                     ns = collectionContractAttribute.Namespace;
                     if (ns == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractNamespace, DataContract.GetClrTypeFullName(type))));
+                        throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractNamespace, DataContract.GetClrTypeFullName(type)));
                     CheckExplicitDataContractNamespaceUri(ns, type);
                 }
                 else
@@ -1755,9 +1743,9 @@ namespace System.Runtime.Serialization.DataContracts
                 if (clrNsInAttribute == clrNs)
                 {
                     if (nsAttribute.ContractNamespace == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidGlobalDataContractNamespace, clrNs)));
+                        throw new InvalidDataContractException(SR.Format(SR.InvalidGlobalDataContractNamespace, clrNs));
                     if (dataContractNs != null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.DataContractNamespaceAlreadySet, dataContractNs, nsAttribute.ContractNamespace, clrNs)));
+                        throw new InvalidDataContractException(SR.Format(SR.DataContractNamespaceAlreadySet, dataContractNs, nsAttribute.ContractNamespace, clrNs));
                     dataContractNs = nsAttribute.ContractNamespace;
                 }
             }
@@ -1939,7 +1927,7 @@ namespace System.Runtime.Serialization.DataContracts
                         if (format[i] == '}')
                             break;
                     if (i == format.Length)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericNameBraceMismatch, format, genericNameProvider.GetGenericTypeName())));
+                        throw new InvalidDataContractException(SR.Format(SR.GenericNameBraceMismatch, format, genericNameProvider.GetGenericTypeName()));
                     if (format[start] == '#' && i == (start + 1))
                     {
                         if (nestedParameterCounts.Count > 1 || !genericNameProvider.ParametersFromBuiltInNamespaces)
@@ -1957,7 +1945,7 @@ namespace System.Runtime.Serialization.DataContracts
                     else
                     {
                         if (!int.TryParse(format.AsSpan(start, i - start), out int paramIndex) || paramIndex < 0 || paramIndex >= genericNameProvider.GetParameterCount())
-                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericParameterNotValid, format.Substring(start, i - start), genericNameProvider.GetGenericTypeName(), genericNameProvider.GetParameterCount() - 1)));
+                            throw new InvalidDataContractException(SR.Format(SR.GenericParameterNotValid, format.Substring(start, i - start), genericNameProvider.GetGenericTypeName(), genericNameProvider.GetParameterCount() - 1));
                         typeName.Append(genericNameProvider.GetParameterName(paramIndex));
                     }
                 }
@@ -2105,7 +2093,7 @@ namespace System.Runtime.Serialization.DataContracts
                 // The alreadyExistingContract type was used as-is in NetFx. The call to get the appropriate adapter type was added in CoreFx with https://github.com/dotnet/runtime/commit/50c0a70c52fa66fafa1227be552ccdab5e4cf8e4
                 // Don't throw duplicate if its a KeyValuePair<K,T> as it could have been added by Dictionary<K,T>
                 if (DataContractCriticalHelper.GetDataContractAdapterType(alreadyExistingContract.UnderlyingType) != DataContractCriticalHelper.GetDataContractAdapterType(type))
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DupContractInKnownTypes, type, alreadyExistingContract.UnderlyingType, dataContract.XmlName.Namespace, dataContract.XmlName.Name)));
+                    throw new InvalidOperationException(SR.Format(SR.DupContractInKnownTypes, type, alreadyExistingContract.UnderlyingType, dataContract.XmlName.Namespace, dataContract.XmlName.Name));
                 return;
             }
             nameToDataContractTable.Add(dataContract.XmlName, dataContract);
index b98bad5c8cd4c5db1bad688f08832c0e4736292f..dfddcd5566fa1aa1a2b3b49247e36a0bbf490e4d 100644 (file)
@@ -134,8 +134,7 @@ namespace System.Runtime.Serialization
                 }
             }
 
-            if (maxItemsInObjectGraph < 0)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(maxItemsInObjectGraph), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(maxItemsInObjectGraph);
             _maxItemsInObjectGraph = maxItemsInObjectGraph;
 
             _ignoreExtensionDataObject = ignoreExtensionDataObject;
@@ -368,7 +367,7 @@ namespace System.Runtime.Serialization
         internal void InternalWriteObjectContent(XmlWriterDelegator writer, object? graph, DataContractResolver? dataContractResolver)
         {
             if (MaxItemsInObjectGraph == 0)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph));
 
             DataContract contract = RootContract;
             Type declaredType = contract.UnderlyingType;
@@ -384,7 +383,7 @@ namespace System.Runtime.Serialization
             if (graph == null)
             {
                 if (IsRootXmlAny(_rootName, contract))
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsAnyCannotBeNull, declaredType)));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsAnyCannotBeNull, declaredType));
                 WriteNull(writer);
             }
             else
@@ -406,7 +405,7 @@ namespace System.Runtime.Serialization
                 {
                     XmlObjectSerializerWriteContext? context;
                     if (IsRootXmlAny(_rootName, contract))
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsAnyCannotBeSerializedAsDerivedType, graphType, contract.UnderlyingType)));
+                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsAnyCannotBeSerializedAsDerivedType, graphType, contract.UnderlyingType));
 
                     contract = GetDataContract(contract, declaredType, graphType);
                     context = XmlObjectSerializerWriteContext.CreateContext(this, RootContract, dataContractResolver);
@@ -460,7 +459,7 @@ namespace System.Runtime.Serialization
         internal override object? InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName, DataContractResolver? dataContractResolver)
         {
             if (MaxItemsInObjectGraph == 0)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph));
 
             dataContractResolver ??= DataContractResolver;
 
@@ -480,12 +479,12 @@ namespace System.Runtime.Serialization
                         expectedName = _rootName;
                         expectedNs = _rootNamespace;
                     }
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElement, expectedNs, expectedName), xmlReader));
+                    throw XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElement, expectedNs, expectedName), xmlReader);
                 }
             }
             else if (!IsStartElement(xmlReader))
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElementAtDeserialize, XmlNodeType.Element), xmlReader));
+                throw XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElementAtDeserialize, XmlNodeType.Element), xmlReader);
             }
 
             DataContract contract = RootContract;
index 1f1c04e5934d546dafce7667b78d733a5c4e183a..55f7c22c566328967d72450bf3866671481848aa 100644 (file)
@@ -72,7 +72,7 @@ namespace System.Runtime.Serialization.DataContracts
         internal static void EnsureTypeNotGeneric(Type type)
         {
             if (type.ContainsGenericParameters)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericTypeNotExportable, type)));
+                throw new InvalidDataContractException(SR.Format(SR.GenericTypeNotExportable, type));
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
@@ -109,11 +109,11 @@ namespace System.Runtime.Serialization.DataContracts
                 if (!dataContractInSet.Equals(dataContract))
                 {
                     if (dataContract.UnderlyingType == null || dataContractInSet.UnderlyingType == null)
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DupContractInDataContractSet, dataContract.XmlName.Name, dataContract.XmlName.Namespace)));
+                        throw new InvalidOperationException(SR.Format(SR.DupContractInDataContractSet, dataContract.XmlName.Name, dataContract.XmlName.Namespace));
                     else
                     {
                         bool typeNamesEqual = (DataContract.GetClrTypeFullName(dataContract.UnderlyingType) == DataContract.GetClrTypeFullName(dataContractInSet.UnderlyingType));
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DupTypeContractInDataContractSet, (typeNamesEqual ? dataContract.UnderlyingType.AssemblyQualifiedName : DataContract.GetClrTypeFullName(dataContract.UnderlyingType)), (typeNamesEqual ? dataContractInSet.UnderlyingType.AssemblyQualifiedName : DataContract.GetClrTypeFullName(dataContractInSet.UnderlyingType)), dataContract.XmlName.Name, dataContract.XmlName.Namespace)));
+                        throw new InvalidOperationException(SR.Format(SR.DupTypeContractInDataContractSet, (typeNamesEqual ? dataContract.UnderlyingType.AssemblyQualifiedName : DataContract.GetClrTypeFullName(dataContract.UnderlyingType)), (typeNamesEqual ? dataContractInSet.UnderlyingType.AssemblyQualifiedName : DataContract.GetClrTypeFullName(dataContractInSet.UnderlyingType)), dataContract.XmlName.Name, dataContract.XmlName.Namespace));
                     }
                 }
             }
@@ -272,10 +272,10 @@ namespace System.Runtime.Serialization.DataContracts
                         Type dcType = DataContractSurrogateCaller.GetDataContractType(_surrogateProvider, dataMemberType);
                         if (dcType != dataMemberType)
                         {
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.SurrogatesWithGetOnlyCollectionsNotSupported,
+                            throw new InvalidDataContractException(SR.Format(SR.SurrogatesWithGetOnlyCollectionsNotSupported,
                                 DataContract.GetClrTypeFullName(dataMemberType),
                                 (dataMember.MemberInfo.DeclaringType != null) ? DataContract.GetClrTypeFullName(dataMember.MemberInfo.DeclaringType) : dataMember.MemberInfo.DeclaringType,
-                                dataMember.MemberInfo.Name)));
+                                dataMember.MemberInfo.Name));
                         }
                     }
                     return DataContract.GetGetOnlyCollectionDataContract(DataContract.GetId(dataMemberType.TypeHandle), dataMemberType.TypeHandle, dataMemberType);
@@ -324,7 +324,7 @@ namespace System.Runtime.Serialization.DataContracts
                     foreach (Type type in _referencedTypes)
                     {
                         if (type == null)
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.ReferencedTypesCannotContainNull)));
+                            throw new InvalidOperationException(SR.Format(SR.ReferencedTypesCannotContainNull));
 
                         AddReferencedType(_referencedTypesDictionary, type);
                     }
@@ -345,7 +345,7 @@ namespace System.Runtime.Serialization.DataContracts
                     foreach (Type type in _referencedCollectionTypes)
                     {
                         if (type == null)
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.ReferencedCollectionTypesCannotContainNull)));
+                            throw new InvalidOperationException(SR.Format(SR.ReferencedCollectionTypesCannotContainNull));
                         AddReferencedType(_referencedCollectionTypesDictionary, type);
                     }
                 }
@@ -415,14 +415,12 @@ namespace System.Runtime.Serialization.DataContracts
                         CollectionDataContract.IsCollection(type, out _) ||
                         ClassDataContract.IsNonAttributedTypeValidForSerialization(type));
             }
-            catch (Exception ex)
+            catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
             {
                 // An exception can be thrown in the designer when a project has a runtime binding redirection for a referenced assembly or a reference dependent assembly.
                 // Type.IsDefined is known to throw System.IO.FileLoadException.
                 // ClassDataContract.IsNonAttributedTypeValidForSerialization is known to throw System.IO.FileNotFoundException.
                 // We guard against all non-critical exceptions.
-                if (Fx.IsFatal(ex))
-                    throw;
             }
 
             return false;
@@ -447,7 +445,7 @@ namespace System.Runtime.Serialization.DataContracts
 
             XmlQualifiedName genericXmlName = dataContract.GenericInfo.GetExpandedXmlName();
             if (genericXmlName != dataContract.XmlName)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericTypeNameMismatch, dataContract.XmlName.Name, dataContract.XmlName.Namespace, genericXmlName.Name, genericXmlName.Namespace)));
+                throw new InvalidDataContractException(SR.Format(SR.GenericTypeNameMismatch, dataContract.XmlName.Name, dataContract.XmlName.Namespace, genericXmlName.Name, genericXmlName.Namespace));
 
             // This check originally came "here" in the old code. Its tempting to move it up with the GenericInfo check.
             if (!supportGenericTypes.Value)
@@ -600,17 +598,17 @@ namespace System.Runtime.Serialization.DataContracts
                     }
                     if (containsGenericType)
                     {
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(
+                        throw new InvalidOperationException(SR.Format(
                             (useReferencedCollectionTypes ? SR.AmbiguousReferencedCollectionTypes1 : SR.AmbiguousReferencedTypes1),
-                            errorMessage.ToString())));
+                            errorMessage.ToString()));
                     }
                     else
                     {
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(
+                        throw new InvalidOperationException(SR.Format(
                             (useReferencedCollectionTypes ? SR.AmbiguousReferencedCollectionTypes3 : SR.AmbiguousReferencedTypes3),
                             XmlConvert.DecodeName(xmlName.Name),
                             xmlName.Namespace,
-                            errorMessage.ToString())));
+                            errorMessage.ToString()));
                     }
                 }
             }
index b585a4f13f7c0714a99403eeabfada4b09a06e68..60a68c81f70749cf6999b73c99070ca73f1c5369 100644 (file)
@@ -55,7 +55,7 @@ namespace System.Runtime.Serialization
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTimeOffset", exception));
+                throw XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTimeOffset", exception);
             }
         }
 
diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DiagnosticUtility.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DiagnosticUtility.cs
deleted file mode 100644 (file)
index a621725..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-// 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.Diagnostics.CodeAnalysis;
-using System.Reflection;
-using System.Threading;
-
-namespace System.Runtime.Serialization
-{
-    internal static class Fx
-    {
-        [Conditional("DEBUG")]
-        public static void Assert([DoesNotReturnIf(false)] bool condition, string message)
-        {
-            System.Diagnostics.Debug.Assert(condition, message);
-        }
-
-        [Conditional("DEBUG")]
-        [DoesNotReturn]
-        public static void Assert(string message)
-        {
-            Assert(false, message);
-        }
-
-        public static bool IsFatal(Exception exception)
-        {
-            while (exception != null)
-            {
-                // NetFx checked for FatalException and FatalInternalException as well, which were ServiceModel constructs.
-                if ((exception is OutOfMemoryException && !(exception is InsufficientMemoryException)) ||
-                    exception is ThreadAbortException)
-                {
-                    return true;
-                }
-
-                // These exceptions aren't themselves fatal, but since the CLR uses them to wrap other exceptions,
-                // we want to check to see whether they've been used to wrap a fatal exception.  If so, then they
-                // count as fatal.
-                if (exception is TypeInitializationException ||
-                    exception is TargetInvocationException)
-                {
-                    exception = exception.InnerException!;
-                }
-                else if (exception is AggregateException)
-                {
-                    // AggregateExceptions have a collection of inner exceptions, which may themselves be other
-                    // wrapping exceptions (including nested AggregateExceptions).  Recursively walk this
-                    // hierarchy.  The (singular) InnerException is included in the collection.
-                    var innerExceptions = ((AggregateException)exception).InnerExceptions;
-                    foreach (Exception innerException in innerExceptions)
-                    {
-                        if (IsFatal(innerException))
-                        {
-                            return true;
-                        }
-                    }
-
-                    break;
-                }
-                else
-                {
-                    break;
-                }
-            }
-
-            return false;
-        }
-    }
-
-    internal static class DiagnosticUtility
-    {
-        [Conditional("DEBUG")]
-        [DoesNotReturn]
-        public static void DebugAssert(string message)
-        {
-            DebugAssert(false, message);
-        }
-
-        [Conditional("DEBUG")]
-        public static void DebugAssert([DoesNotReturnIf(false)] bool condition, string message)
-        {
-            Debug.Assert(condition, message);
-        }
-
-        internal static class ExceptionUtility
-        {
-            public static Exception ThrowHelperArgumentNull(string message)
-            {
-                return new ArgumentNullException(message);
-            }
-
-            public static Exception ThrowHelperError(Exception e)
-            {
-                return e;
-            }
-
-            public static Exception ThrowHelperArgument(string message)
-            {
-                return new ArgumentException(message);
-            }
-
-            internal static Exception ThrowHelperFatal(string message, Exception innerException)
-            {
-                return ThrowHelperError(new Exception(message, innerException));
-            }
-            internal static Exception ThrowHelperCallback(Exception e)
-            {
-                return ThrowHelperError(e);
-            }
-        }
-    }
-}
index 8e382fe34e3586fc6829abb90b88300abd5faac7..3923fd0ecd9351b9dca89f5dbe52c5d48a83bbcc 100644 (file)
@@ -316,13 +316,13 @@ namespace System.Runtime.Serialization.DataContracts
                 }
                 // enforce that enum value was completely parsed
                 if (longValue != 0)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidEnumValueOnWrite, value, DataContract.GetClrTypeFullName(UnderlyingType))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidEnumValueOnWrite, value, DataContract.GetClrTypeFullName(UnderlyingType)));
 
                 if (noneWritten && zeroIndex >= 0)
                     writer.WriteString(ChildElementNames![zeroIndex].Value);
             }
             else
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidEnumValueOnWrite, value, DataContract.GetClrTypeFullName(UnderlyingType))));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidEnumValueOnWrite, value, DataContract.GetClrTypeFullName(UnderlyingType)));
         }
 
         internal object ReadEnumValue(XmlReaderDelegator reader)
@@ -362,7 +362,7 @@ namespace System.Runtime.Serialization.DataContracts
             else
             {
                 if (stringValue.Length == 0)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidEnumValueOnRead, stringValue, DataContract.GetClrTypeFullName(UnderlyingType))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidEnumValueOnRead, stringValue, DataContract.GetClrTypeFullName(UnderlyingType)));
                 longValue = ReadEnumValue(stringValue, 0, stringValue.Length);
             }
 
@@ -381,7 +381,7 @@ namespace System.Runtime.Serialization.DataContracts
                     return Values![i];
                 }
             }
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidEnumValueOnRead, value.Substring(index, count), DataContract.GetClrTypeFullName(UnderlyingType))));
+            throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.InvalidEnumValueOnRead, value.Substring(index, count), DataContract.GetClrTypeFullName(UnderlyingType)));
         }
 
         internal string GetStringFromEnumValue(long value)
diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ExceptionUtility.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ExceptionUtility.cs
new file mode 100644 (file)
index 0000000..438a545
--- /dev/null
@@ -0,0 +1,55 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Reflection;
+using System.Threading;
+
+namespace System.Runtime.Serialization
+{
+    internal static class ExceptionUtility
+    {
+        public static bool IsFatal(Exception exception)
+        {
+            while (exception != null)
+            {
+                // NetFx checked for FatalException and FatalInternalException as well, which were ServiceModel constructs.
+                if ((exception is OutOfMemoryException && !(exception is InsufficientMemoryException)) ||
+                    exception is ThreadAbortException)
+                {
+                    return true;
+                }
+
+                // These exceptions aren't themselves fatal, but since the CLR uses them to wrap other exceptions,
+                // we want to check to see whether they've been used to wrap a fatal exception.  If so, then they
+                // count as fatal.
+                if (exception is TypeInitializationException ||
+                    exception is TargetInvocationException)
+                {
+                    exception = exception.InnerException!;
+                }
+                else if (exception is AggregateException)
+                {
+                    // AggregateExceptions have a collection of inner exceptions, which may themselves be other
+                    // wrapping exceptions (including nested AggregateExceptions).  Recursively walk this
+                    // hierarchy.  The (singular) InnerException is included in the collection.
+                    var innerExceptions = ((AggregateException)exception).InnerExceptions;
+                    foreach (Exception innerException in innerExceptions)
+                    {
+                        if (IsFatal(innerException))
+                        {
+                            return true;
+                        }
+                    }
+
+                    break;
+                }
+                else
+                {
+                    break;
+                }
+            }
+
+            return false;
+        }
+    }
+}
index 09af18495821d6665022043d43da7d9659ce7886..cc36e1f9aa59e23da108de283037a3924128ad3c 100644 (file)
@@ -337,7 +337,7 @@ namespace System.Runtime.Serialization
                     break;
 
                 default:
-                    Fx.Assert("ExtensionDataReader in invalid state");
+                    Debug.Fail("ExtensionDataReader in invalid state");
                     throw new SerializationException(SR.InvalidStateInExtensionDataReader);
             }
             _readState = ReadState.Interactive;
@@ -352,7 +352,7 @@ namespace System.Runtime.Serialization
                 {
                     return _xmlNodeReader.Name;
                 }
-                Fx.Assert("ExtensionDataReader Name property should only be called for IXmlSerializable");
+                Debug.Fail("ExtensionDataReader Name property should only be called for IXmlSerializable");
                 return string.Empty;
             }
         }
@@ -365,7 +365,7 @@ namespace System.Runtime.Serialization
                 {
                     return _xmlNodeReader.HasValue;
                 }
-                Fx.Assert("ExtensionDataReader HasValue property should only be called for IXmlSerializable");
+                Debug.Fail("ExtensionDataReader HasValue property should only be called for IXmlSerializable");
                 return false;
             }
         }
@@ -378,7 +378,7 @@ namespace System.Runtime.Serialization
                 {
                     return _xmlNodeReader.BaseURI;
                 }
-                Fx.Assert("ExtensionDataReader BaseURI property should only be called for IXmlSerializable");
+                Debug.Fail("ExtensionDataReader BaseURI property should only be called for IXmlSerializable");
                 return string.Empty;
             }
         }
@@ -391,7 +391,7 @@ namespace System.Runtime.Serialization
                 {
                     return _xmlNodeReader.NameTable;
                 }
-                Fx.Assert("ExtensionDataReader NameTable property should only be called for IXmlSerializable");
+                Debug.Fail("ExtensionDataReader NameTable property should only be called for IXmlSerializable");
                 return null;
             }
         }
@@ -402,7 +402,7 @@ namespace System.Runtime.Serialization
             {
                 return _xmlNodeReader.GetAttribute(name);
             }
-            Fx.Assert("ExtensionDataReader GetAttribute method should only be called for IXmlSerializable");
+            Debug.Fail("ExtensionDataReader GetAttribute method should only be called for IXmlSerializable");
             return null;
         }
 
@@ -412,7 +412,7 @@ namespace System.Runtime.Serialization
             {
                 return _xmlNodeReader.GetAttribute(i);
             }
-            Fx.Assert("ExtensionDataReader GetAttribute method should only be called for IXmlSerializable");
+            Debug.Fail("ExtensionDataReader GetAttribute method should only be called for IXmlSerializable");
             return null;
         }
 
@@ -422,7 +422,7 @@ namespace System.Runtime.Serialization
             {
                 return _xmlNodeReader.MoveToAttribute(name);
             }
-            Fx.Assert("ExtensionDataReader MoveToAttribute method should only be called for IXmlSerializable");
+            Debug.Fail("ExtensionDataReader MoveToAttribute method should only be called for IXmlSerializable");
             return false;
         }
 
@@ -434,7 +434,7 @@ namespace System.Runtime.Serialization
             }
             else
             {
-                Fx.Assert("ExtensionDataReader ResolveEntity method should only be called for IXmlSerializable");
+                Debug.Fail("ExtensionDataReader ResolveEntity method should only be called for IXmlSerializable");
             }
         }
 
@@ -444,7 +444,7 @@ namespace System.Runtime.Serialization
             {
                 return _xmlNodeReader.ReadAttributeValue();
             }
-            Fx.Assert("ExtensionDataReader ReadAttributeValue method should only be called for IXmlSerializable");
+            Debug.Fail("ExtensionDataReader ReadAttributeValue method should only be called for IXmlSerializable");
             return false;
         }
 
@@ -471,8 +471,8 @@ namespace System.Runtime.Serialization
                         MoveToDeserializedObject(dataNode!);
                     else
                     {
-                        Fx.Assert("Encountered invalid data node when deserializing unknown data");
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(SR.InvalidStateInExtensionDataReader)));
+                        Debug.Fail("Encountered invalid data node when deserializing unknown data");
+                        throw new SerializationException(SR.Format(SR.InvalidStateInExtensionDataReader));
                     }
                     break;
             }
@@ -534,7 +534,7 @@ namespace System.Runtime.Serialization
         private void MoveNextInClass(ClassDataNode dataNode)
         {
             // Two frames above here in Read(), _element is asserted not null.
-            Fx.Assert(_element != null, "");
+            Debug.Assert(_element != null);
             if (dataNode.Members != null && _element.childElementIndex < dataNode.Members.Count)
             {
                 if (_element.childElementIndex == 0)
@@ -553,7 +553,7 @@ namespace System.Runtime.Serialization
         private void MoveNextInCollection(CollectionDataNode dataNode)
         {
             // Two frames above here in Read(), _element is asserted not null.
-            Fx.Assert(_element != null, "");
+            Debug.Assert(_element != null);
             if (dataNode.Items != null && _element.childElementIndex < dataNode.Items.Count)
             {
                 if (_element.childElementIndex == 0)
@@ -572,7 +572,7 @@ namespace System.Runtime.Serialization
         private void MoveNextInISerializable(ISerializableDataNode dataNode)
         {
             // Two frames above here in Read(), _element is asserted not null.
-            Fx.Assert(_element != null, "");
+            Debug.Assert(_element != null);
             if (dataNode.Members != null && _element.childElementIndex < dataNode.Members.Count)
             {
                 if (_element.childElementIndex == 0)
@@ -649,14 +649,14 @@ namespace System.Runtime.Serialization
                 }
                 else
                 {
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidDataNode, DataContract.GetClrTypeFullName(type))));
+                    throw new XmlException(SR.Format(SR.InvalidDataNode, DataContract.GetClrTypeFullName(type)));
                 }
             }
         }
 
         private bool MoveToText(Type type, IDataNode dataNode, bool isTypedNode)
         {
-            Fx.Assert(dataNode.Value != null, "");
+            Debug.Assert(dataNode.Value != null);
 
             bool handled = true;
             switch (Type.GetTypeCode(type))
index 1ce12d3b6d9d5461907a18bd6b333abdc7ea6065..043746400e5ef5d746dcb0686e223ab3e7430166 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Runtime.Serialization
             _objectDictionary ??= new Dictionary<string, object?>();
 
             if (_objectDictionary.ContainsKey(id))
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.MultipleIdDefinition, id)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.MultipleIdDefinition, id));
             _objectDictionary.Add(id, obj);
         }
 
index 7708ab6d9b88a8ad33ba425c2a8599b694576c42..5072642b0087b264cf62bfab1e8921572a706539 100644 (file)
@@ -599,10 +599,7 @@ namespace System.Runtime.Serialization.Json
                 }
             }
 
-            if (maxItemsInObjectGraph < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(maxItemsInObjectGraph), SR.ValueMustBeNonNegative);
-            }
+            ArgumentOutOfRangeException.ThrowIfNegative(maxItemsInObjectGraph);
             _maxItemsInObjectGraph = maxItemsInObjectGraph;
             _ignoreExtensionDataObject = ignoreExtensionDataObject;
             _emitTypeInformation = emitTypeInformation;
@@ -633,11 +630,10 @@ namespace System.Runtime.Serialization.Json
         {
             if (dataContract.IsReference)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                    XmlObjectSerializer.CreateSerializationException(SR.Format(
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(
                         SR.JsonUnsupportedForIsReference,
                         DataContract.GetClrTypeFullName(dataContract.UnderlyingType),
-                        dataContract.IsReference)));
+                        dataContract.IsReference));
             }
         }
 
index ca7a5e8e6602635a9e29894958945f1f746d3bc8..50db0fd272948b81295958d931c82fbeedc96788 100644 (file)
@@ -200,7 +200,7 @@ namespace System.Runtime.Serialization.Json
                             int newSize = (value < int.MaxValue / 2) ? value * 2 : int.MaxValue;
                             if (newSize <= value)
                             {
-                                Fx.Assert("DataContract cache overflow");
+                                Debug.Fail("DataContract cache overflow");
                                 throw new SerializationException(SR.DataContractCacheOverflow);
                             }
                             Array.Resize<JsonDataContract>(ref s_dataContractCache, newSize);
@@ -210,12 +210,9 @@ namespace System.Runtime.Serialization.Json
                         {
                             s_typeToIDCache.Add(new TypeHandleRef(typeHandle), id);
                         }
-                        catch (Exception ex)
+                        catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
                         {
-                            if (Fx.IsFatal(ex))
-                                throw;
-
-                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperFatal(ex.Message, ex);
+                            throw new Exception(ex.Message, ex);
                         }
                     }
                     return id.Value;
index 786363fadd01dbd990c9cc8bd08cba13b938d0ad..f2437ec8d879a5dfb302b22a10ac56eeecc0be84 100644 (file)
@@ -453,7 +453,7 @@ namespace System.Runtime.Serialization.Json
             {
                 ConstructorInfo? ctor = classContract.UnderlyingType.GetConstructor(Globals.ScanAllMembers, JsonFormatGeneratorStatics.SerInfoCtorArgs);
                 if (ctor == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.SerializationInfo_ConstructorNotFound, DataContract.GetClrTypeFullName(classContract.UnderlyingType))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.SerializationInfo_ConstructorNotFound, DataContract.GetClrTypeFullName(classContract.UnderlyingType)));
                 _ilg.LoadAddress(_objectLocal);
                 _ilg.ConvertAddress(_objectLocal.LocalType, _objectType!);
                 _ilg.Call(_contextArg, XmlFormatGeneratorStatics.ReadSerializationInfoMethod, _xmlReaderArg, classContract.UnderlyingType);
@@ -990,7 +990,7 @@ namespace System.Runtime.Serialization.Json
                     ClassDataContract? keyValuePairContract = DataContract.GetDataContract(value.LocalType) as ClassDataContract;
                     if (keyValuePairContract == null)
                     {
-                        Fx.Assert("Failed to create contract for KeyValuePair type");
+                        Debug.Fail("Failed to create contract for KeyValuePair type");
                     }
                     DataMember keyMember = keyValuePairContract.Members![0];
                     DataMember valueMember = keyValuePairContract.Members[1];
index b1bb653913ec8e8f11f97fe6dcae7c051d76936c..385dd853034ae3fa55e445402a4a4f99c8327fa7 100644 (file)
@@ -177,12 +177,11 @@ namespace System.Runtime.Serialization.Json
 
             if (keyParseMode == KeyParseMode.Fail)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                    new InvalidOperationException(
+                throw new InvalidOperationException(
                         SR.Format(SR.KeyTypeCannotBeParsedInSimpleDictionary,
                             DataContract.GetClrTypeFullName(collectionContract.UnderlyingType),
                             DataContract.GetClrTypeFullName(keyType))
-                    ));
+                    );
             }
 
             while (true)
index e62f45b562261fa901266a45d07fb184f9756c25..d5304a09ecdefb282d997a506a11e8419359b8a5 100644 (file)
@@ -733,18 +733,12 @@ namespace System.Runtime.Serialization.Json
             if (IsAttributeValue)
             {
                 ArgumentNullException.ThrowIfNull(buffer);
-                if (offset < 0)
-                {
-                    throw new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative);
-                }
+                ArgumentOutOfRangeException.ThrowIfNegative(offset);
                 if (offset > buffer.Length)
                 {
                     throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length));
                 }
-                if (count < 0)
-                {
-                    throw new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative);
-                }
+                ArgumentOutOfRangeException.ThrowIfNegative(count);
                 if (count > buffer.Length - offset)
                 {
                     throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset));
@@ -761,18 +755,12 @@ namespace System.Runtime.Serialization.Json
             if (IsAttributeValue)
             {
                 ArgumentNullException.ThrowIfNull(chars);
-                if (offset < 0)
-                {
-                    throw new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative);
-                }
+                ArgumentOutOfRangeException.ThrowIfNegative(offset);
                 if (offset > chars.Length)
                 {
                     throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
                 }
-                if (count < 0)
-                {
-                    throw new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative);
-                }
+                ArgumentOutOfRangeException.ThrowIfNegative(count);
                 if (count > chars.Length - offset)
                 {
                     throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset));
@@ -804,18 +792,12 @@ namespace System.Runtime.Serialization.Json
         {
             ArgumentNullException.ThrowIfNull(buffer);
 
-            if (offset < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative);
-            }
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > buffer.Length)
             {
                 throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.JsonOffsetExceedsBufferSize, buffer.Length));
             }
-            if (count < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative);
-            }
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - offset)
             {
                 throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.JsonSizeExceedsRemainingBufferSpace, buffer.Length - offset));
@@ -851,18 +833,12 @@ namespace System.Runtime.Serialization.Json
         {
             ArgumentNullException.ThrowIfNull(array);
 
-            if (offset < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative);
-            }
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > array.Length)
             {
                 throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, array.Length));
             }
-            if (count < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative);
-            }
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > array.Length - offset)
             {
                 throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, array.Length - offset));
@@ -1615,7 +1591,7 @@ namespace System.Runtime.Serialization.Json
                     i++;
                     sb ??= new StringBuilder();
                     sb.Append(val, startIndex, count);
-                    Fx.Assert(i < val.Length, "Found that an '\' was the last character in a string. ReadServerTypeAttriute validates that the escape sequence is valid when it calls ReadQuotedText and ReadEscapedCharacter");
+                    Debug.Assert(i < val.Length, "Found that an '\' was the last character in a string. ReadServerTypeAttriute validates that the escape sequence is valid when it calls ReadQuotedText and ReadEscapedCharacter");
                     if (i >= val.Length)
                     {
                         XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.JsonEncounteredUnexpectedCharacter, val[i])));
@@ -1675,7 +1651,7 @@ namespace System.Runtime.Serialization.Json
 
         protected override XmlSigningNodeWriter CreateSigningNodeWriter()
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.JsonMethodNotSupported, "CreateSigningNodeWriter")));
+            throw new NotSupportedException(SR.Format(SR.JsonMethodNotSupported, "CreateSigningNodeWriter"));
         }
 
         private static class CharType
index 294913673359b7ffc4423eded5d1ec236286c1cb..13a6bed947046345509b4ea3f5d973478d340d7c 100644 (file)
@@ -358,15 +358,8 @@ namespace System.Runtime.Serialization.Json
             ArgumentNullException.ThrowIfNull(buffer);
 
             // Not checking upper bound because it will be caught by "count".  This is what XmlTextWriter does.
-            if (index < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(index), SR.ValueMustBeNonNegative);
-            }
-
-            if (count < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative);
-            }
+            ArgumentOutOfRangeException.ThrowIfNegative(index);
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - index)
             {
                 throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.JsonSizeExceedsRemainingBufferSpace, buffer.Length - index));
@@ -381,15 +374,8 @@ namespace System.Runtime.Serialization.Json
             ArgumentNullException.ThrowIfNull(buffer);
 
             // Not checking upper bound because it will be caught by "count".  This is what XmlTextWriter does.
-            if (index < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(index), SR.ValueMustBeNonNegative);
-            }
-
-            if (count < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative);
-            }
+            ArgumentOutOfRangeException.ThrowIfNegative(index);
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - index)
             {
                 throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.JsonSizeExceedsRemainingBufferSpace, buffer.Length - index));
@@ -414,15 +400,8 @@ namespace System.Runtime.Serialization.Json
             ArgumentNullException.ThrowIfNull(buffer);
 
             // Not checking upper bound because it will be caught by "count".  This is what XmlTextWriter does.
-            if (index < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(index), SR.ValueMustBeNonNegative);
-            }
-
-            if (count < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative);
-            }
+            ArgumentOutOfRangeException.ThrowIfNegative(index);
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - index)
             {
                 throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.JsonSizeExceedsRemainingBufferSpace, buffer.Length - index));
@@ -452,7 +431,7 @@ namespace System.Runtime.Serialization.Json
                 throw new XmlException(SR.JsonNoMatchingStartAttribute);
             }
 
-            Fx.Assert(!(_isWritingDataTypeAttribute && _isWritingServerTypeAttribute),
+            Debug.Assert(!(_isWritingDataTypeAttribute && _isWritingServerTypeAttribute),
                 "Can not write type attribute and __type attribute at the same time.");
 
             if (_isWritingDataTypeAttribute)
@@ -621,7 +600,7 @@ namespace System.Runtime.Serialization.Json
             {
                 // Assert on only StandaloneText and EndElement because preceding if
                 //    conditions take care of checking for QuotedText and Element.
-                Fx.Assert((_nodeType == JsonNodeType.StandaloneText) || (_nodeType == JsonNodeType.EndElement),
+                Debug.Assert((_nodeType == JsonNodeType.StandaloneText) || (_nodeType == JsonNodeType.EndElement),
                     "nodeType has invalid value " + _nodeType + ". Expected it to be QuotedText, Element, StandaloneText, or EndElement.");
             }
             if (_depth != 0)
@@ -710,15 +689,8 @@ namespace System.Runtime.Serialization.Json
             ArgumentNullException.ThrowIfNull(buffer);
 
             // Not checking upper bound because it will be caught by "count".  This is what XmlTextWriter does.
-            if (index < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(index), SR.ValueMustBeNonNegative);
-            }
-
-            if (count < 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative);
-            }
+            ArgumentOutOfRangeException.ThrowIfNegative(index);
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - index)
             {
                 throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.JsonSizeExceedsRemainingBufferSpace, buffer.Length - index));
index 10b292123dcbce5fbd22a55b6c291c01c8de6153..f49faae9c17d01bdc2195539b922a4188f215568 100644 (file)
@@ -107,8 +107,7 @@ namespace System.Runtime.Serialization.Json
                     dataNode = ReadNumericalPrimitiveExtensionDataValue(xmlReader);
                     break;
                 default:
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        XmlObjectSerializer.CreateSerializationException(SR.Format(SR.JsonUnexpectedAttributeValue, _extensionDataValueType)));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.JsonUnexpectedAttributeValue, _extensionDataValueType));
             }
 
             xmlReader.ReadEndElement();
@@ -311,8 +310,8 @@ namespace System.Runtime.Serialization.Json
 
         public static void ThrowDuplicateMemberException(object obj, XmlDictionaryString[] memberNames, int memberIndex)
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(
-                SR.Format(SR.JsonDuplicateMemberInInput, DataContract.GetClrTypeFullName(obj.GetType()), memberNames[memberIndex])));
+            throw new SerializationException(
+                SR.Format(SR.JsonDuplicateMemberInInput, DataContract.GetClrTypeFullName(obj.GetType()), memberNames[memberIndex]));
         }
 
         public static void ThrowMissingRequiredMembers(object obj, XmlDictionaryString[] memberNames, byte[] expectedElements, byte[] requiredElements)
@@ -332,13 +331,13 @@ namespace System.Runtime.Serialization.Json
 
             if (missingMembersCount == 1)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(
-                 SR.JsonOneRequiredMemberNotFound, DataContract.GetClrTypeFullName(obj.GetType()), stringBuilder.ToString())));
+                throw new SerializationException(SR.Format(
+                 SR.JsonOneRequiredMemberNotFound, DataContract.GetClrTypeFullName(obj.GetType()), stringBuilder.ToString()));
             }
             else
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(
-                    SR.JsonRequiredMembersNotFound, DataContract.GetClrTypeFullName(obj.GetType()), stringBuilder.ToString())));
+                throw new SerializationException(SR.Format(
+                    SR.JsonRequiredMembersNotFound, DataContract.GetClrTypeFullName(obj.GetType()), stringBuilder.ToString()));
             }
         }
 
index 440e960538fcdd289390a9d800f5480a26c7e202..f877c36e33d0b4ad429ef93d084f5a5576c6e734 100644 (file)
@@ -320,12 +320,12 @@ namespace System.Runtime.Serialization.Json
             Type contractType = contract.GetType();
             if ((contractType == typeof(XmlDataContract)) && !Globals.TypeOfIXmlSerializable.IsAssignableFrom(declaredType))
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.XmlObjectAssignedToIncompatibleInterface, graph.GetType(), declaredType)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.XmlObjectAssignedToIncompatibleInterface, graph.GetType(), declaredType));
             }
 
             if ((contractType == typeof(CollectionDataContract)) && !CollectionDataContract.IsCollectionInterface(declaredType))
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CollectionAssignedToIncompatibleInterface, graph.GetType(), declaredType)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CollectionAssignedToIncompatibleInterface, graph.GetType(), declaredType));
             }
         }
 
@@ -338,7 +338,7 @@ namespace System.Runtime.Serialization.Json
             GetObjectData(obj, serInfo, GetStreamingContext());
             if (DataContract.GetClrTypeFullName(objType) != serInfo.FullTypeName)
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ChangingFullTypeNameNotSupported, serInfo.FullTypeName, DataContract.GetClrTypeFullName(objType))));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ChangingFullTypeNameNotSupported, serInfo.FullTypeName, DataContract.GetClrTypeFullName(objType)));
             }
             else
             {
index 69562ba632fffb617212aefb65740751f54280af..c557a70c57015fb9ba3681ea61aa0086311cd7e8 100644 (file)
@@ -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.Diagnostics.CodeAnalysis;
 using System.Runtime.Serialization.DataContracts;
 using System.Xml;
@@ -13,7 +14,7 @@ namespace System.Runtime.Serialization
 
         internal KnownTypeDataContractResolver(XmlObjectSerializerContext context)
         {
-            Fx.Assert(context != null, "KnownTypeDataContractResolver should not be instantiated with a null context");
+            Debug.Assert(context != null, "KnownTypeDataContractResolver should not be instantiated with a null context");
             _context = context;
         }
 
index c6993ad174ced8cda4193304eead731b1ad26e96..3f3414750e96bb9abce4871ecb6eadf08655dd65 100644 (file)
@@ -4,7 +4,7 @@
 using System;
 using System.Xml;
 using System.Collections.Generic;
-
+using System.Diagnostics;
 
 namespace System.Runtime.Serialization
 {
@@ -48,7 +48,7 @@ namespace System.Runtime.Serialization
             {
                 if (_objectDictionary == null)
                 {
-                    DiagnosticUtility.DebugAssert("Object reference stack in invalid state");
+                    Debug.Fail("Object reference stack in invalid state");
                 }
                 _objectDictionary.Remove(obj);
             }
@@ -75,7 +75,7 @@ namespace System.Runtime.Serialization
             {
                 if (_objectDictionary == null)
                 {
-                    DiagnosticUtility.DebugAssert("Object reference stack in invalid state");
+                    Debug.Fail("Object reference stack in invalid state");
                 }
                 _objectDictionary.Remove(obj);
             }
index 9bc1ae31a159a795f0e90e78a7574cf962334a70..ec70b9e5d762400c176c844731c2baf3363e5f9d 100644 (file)
@@ -3,6 +3,7 @@
 
 using System.Collections;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Runtime.CompilerServices;
 
 namespace System.Runtime.Serialization
@@ -88,8 +89,8 @@ namespace System.Runtime.Serialization
                 }
             }
             // m_obj must ALWAYS have at least one slot empty (null).
-            DiagnosticUtility.DebugAssert("Object table overflow");
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.ObjectTableOverflow));
+            Debug.Fail("Object table overflow");
+            throw XmlObjectSerializer.CreateSerializationException(SR.ObjectTableOverflow);
         }
 
         private void RemoveAt(int position)
@@ -127,8 +128,8 @@ namespace System.Runtime.Serialization
                 }
             }
             // m_obj must ALWAYS have at least one slot empty (null).
-            DiagnosticUtility.DebugAssert("Object table overflow");
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.ObjectTableOverflow));
+            Debug.Fail("Object table overflow");
+            throw XmlObjectSerializer.CreateSerializationException(SR.ObjectTableOverflow);
         }
 
         private int ComputeStartPosition(object? o)
index 8664e969981df7316a2bf31d6d3152cceed4b9c5..f0dcbc123013ace1a5017e077f0a56106a3ebaac 100644 (file)
@@ -112,7 +112,7 @@ namespace System.Runtime.Serialization.DataContracts
             Attributes attributes = new Attributes();
             attributes.Read(reader);
             if (attributes.Ref != Globals.NewObjectId)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotDeserializeRefAtTopLevel, attributes.Ref)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotDeserializeRefAtTopLevel, attributes.Ref));
             if (attributes.XsiNil)
             {
                 reader.Skip();
@@ -925,7 +925,7 @@ namespace System.Runtime.Serialization.DataContracts
                 }
                 catch (XmlException xes)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.XmlForObjectCannotHaveContent, localName, ns), xes));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.XmlForObjectCannotHaveContent, localName, ns), xes);
                 }
             }
             return (context == null) ? obj : HandleReadValue(obj, context);
index 49e82ce4baf47de0bac1ef5cf4f312e8c20e01b4..62e5f8bb3dbb5291019d095c78c8dc1aa4885e5e 100644 (file)
@@ -603,7 +603,7 @@ namespace System.Runtime.Serialization
                     MethodInfo? addMethod = collectionContract.AddMethod;
                     if (addMethod == null)
                     {
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.CollectionMustHaveAddMethod, DataContract.GetClrTypeFullName(collectionContract.UnderlyingType))));
+                        throw new InvalidDataContractException(SR.Format(SR.CollectionMustHaveAddMethod, DataContract.GetClrTypeFullName(collectionContract.UnderlyingType)));
                     }
 
                     return (resultCollection, collectionItem, index) =>
index 3a93e66279d2630910f512b60be1bf458e38b537..afd366d024bbc074725dcfe4518eb23e692bc1d5 100644 (file)
@@ -68,7 +68,7 @@ namespace System.Runtime.Serialization
                 StringReader reader = new StringReader(Globals.SerializationSchema);
                 XmlSchema? schema = XmlSchema.Read(new XmlTextReader(reader) { DtdProcessing = DtdProcessing.Prohibit }, null);
                 if (schema == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.CouldNotReadSerializationSchema, Globals.SerializationNamespace)));
+                    throw new InvalidOperationException(SR.Format(SR.CouldNotReadSerializationSchema, Globals.SerializationNamespace));
                 Schemas.Add(schema);
             }
         }
@@ -516,7 +516,7 @@ namespace System.Runtime.Serialization
             {
                 if (!(typeQName.Equals(dataContract.XmlName)))
                 {
-                    Fx.Assert("XML data contract type name does not match schema name");
+                    Debug.Fail("XML data contract type name does not match schema name");
                 }
 
                 XmlSchema? schema;
@@ -533,7 +533,7 @@ namespace System.Runtime.Serialization
                 xsdType = SchemaHelper.GetSchemaType(_schemas, typeQName, out schema);
                 if (anonymousType == null && xsdType == null && typeQName.Namespace != XmlSchema.Namespace)
                 {
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.MissingSchemaType, typeQName, DataContract.GetClrTypeFullName(clrType))));
+                    throw new InvalidDataContractException(SR.Format(SR.MissingSchemaType, typeQName, DataContract.GetClrTypeFullName(clrType)));
                 }
                 if (xsdType != null)
                 {
@@ -597,7 +597,7 @@ namespace System.Runtime.Serialization
             schemas.XmlResolver = null;
             InvokeSchemaProviderMethod(type, schemas, out xmlName, out xsdType, out hasRoot);
             if (xmlName.Name == null || xmlName.Name.Length == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidXmlDataContractName, DataContract.GetClrTypeFullName(type))));
+                throw new InvalidDataContractException(SR.Format(SR.InvalidXmlDataContractName, DataContract.GetClrTypeFullName(type)));
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
@@ -623,24 +623,24 @@ namespace System.Runtime.Serialization
             if (methodName == null || methodName.Length == 0)
             {
                 if (!provider.IsAny)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidGetSchemaMethod, DataContract.GetClrTypeFullName(clrType))));
+                    throw new InvalidDataContractException(SR.Format(SR.InvalidGetSchemaMethod, DataContract.GetClrTypeFullName(clrType)));
                 xmlName = DataContract.GetDefaultXmlName(clrType);
             }
             else
             {
                 MethodInfo? getMethod = clrType.GetMethod(methodName,  /*BindingFlags.DeclaredOnly |*/ BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, new Type[] { typeof(XmlSchemaSet) });
                 if (getMethod == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.MissingGetSchemaMethod, DataContract.GetClrTypeFullName(clrType), methodName)));
+                    throw new InvalidDataContractException(SR.Format(SR.MissingGetSchemaMethod, DataContract.GetClrTypeFullName(clrType), methodName));
 
                 if (!(Globals.TypeOfXmlQualifiedName.IsAssignableFrom(getMethod.ReturnType)) && !(Globals.TypeOfXmlSchemaType.IsAssignableFrom(getMethod.ReturnType)))
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidReturnTypeOnGetSchemaMethod, DataContract.GetClrTypeFullName(clrType), methodName, DataContract.GetClrTypeFullName(getMethod.ReturnType), DataContract.GetClrTypeFullName(Globals.TypeOfXmlQualifiedName), typeof(XmlSchemaType))));
+                    throw new InvalidDataContractException(SR.Format(SR.InvalidReturnTypeOnGetSchemaMethod, DataContract.GetClrTypeFullName(clrType), methodName, DataContract.GetClrTypeFullName(getMethod.ReturnType), DataContract.GetClrTypeFullName(Globals.TypeOfXmlQualifiedName), typeof(XmlSchemaType)));
 
                 object? typeInfo = getMethod.Invoke(null, new object[] { schemas });
 
                 if (provider.IsAny)
                 {
                     if (typeInfo != null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidNonNullReturnValueByIsAny, DataContract.GetClrTypeFullName(clrType), methodName)));
+                        throw new InvalidDataContractException(SR.Format(SR.InvalidNonNullReturnValueByIsAny, DataContract.GetClrTypeFullName(clrType), methodName));
                     xmlName = DataContract.GetDefaultXmlName(clrType);
                 }
                 else if (typeInfo == null)
@@ -678,7 +678,7 @@ namespace System.Runtime.Serialization
                                     break;
                             }
                             if (typeNs == null)
-                                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.MissingSchemaType, typeName, DataContract.GetClrTypeFullName(clrType))));
+                                throw new InvalidDataContractException(SR.Format(SR.MissingSchemaType, typeName, DataContract.GetClrTypeFullName(clrType)));
                             xmlName = new XmlQualifiedName(typeName, typeNs);
                         }
                     }
@@ -703,7 +703,7 @@ namespace System.Runtime.Serialization
             else
             {
                 if (schema.Id == null || schema.Id.Length == 0)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidReturnSchemaOnGetSchemaMethod, DataContract.GetClrTypeFullName(clrType))));
+                    throw new InvalidDataContractException(SR.Format(SR.InvalidReturnSchemaOnGetSchemaMethod, DataContract.GetClrTypeFullName(clrType)));
                 AddDefaultTypedDatasetType(schemas, schema, xmlName.Name, xmlName.Namespace);
             }
         }
index befa4f42087e47f5a37047179181e1b24cb65b95..01ff1b823140aa977f5e752f133ca5df11eabe11 100644 (file)
@@ -52,7 +52,7 @@ namespace System.Runtime.Serialization
                 StringReader reader = new StringReader(Globals.SerializationSchema);
                 XmlSchema? schema = XmlSchema.Read(new XmlTextReader(reader) { DtdProcessing = DtdProcessing.Prohibit }, null);
                 if (schema == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.CouldNotReadSerializationSchema, Globals.SerializationNamespace)));
+                    throw new InvalidOperationException(SR.Format(SR.CouldNotReadSerializationSchema, Globals.SerializationNamespace));
                 _schemaSet.Add(schema);
             }
 
@@ -61,11 +61,9 @@ namespace System.Runtime.Serialization
                 CompileSchemaSet(_schemaSet);
             }
 #pragma warning suppress 56500 // covered by FxCOP
-            catch (Exception ex)
+            catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
             {
-                if (Fx.IsFatal(ex))
-                    throw;
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.CannotImportInvalidSchemas), ex));
+                throw new ArgumentException(SR.Format(SR.CannotImportInvalidSchemas), ex);
             }
 
             if (_typeNames == null)
@@ -74,7 +72,7 @@ namespace System.Runtime.Serialization
                 foreach (object schemaObj in schemaList)
                 {
                     if (schemaObj == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.CannotImportNullSchema)));
+                        throw new ArgumentException(SR.Format(SR.CannotImportNullSchema));
 
                     XmlSchema schema = (XmlSchema)schemaObj;
                     if (schema.TargetNamespace != Globals.SerializationNamespace
@@ -97,7 +95,7 @@ namespace System.Runtime.Serialization
                 foreach (XmlQualifiedName typeName in _typeNames)
                 {
                     if (typeName == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.CannotImportNullDataContractName)));
+                        throw new ArgumentException(SR.Format(SR.CannotImportNullDataContractName));
                     ImportType(typeName);
                 }
 
@@ -372,7 +370,7 @@ namespace System.Runtime.Serialization
                     if (SchemaHelper.GetSchemaType(SchemaObjects, typeQName) == null)
                         break;
                     if (i == int.MaxValue)
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.CannotComputeUniqueName, element.Name)));
+                        throw new InvalidDataContractException(SR.Format(SR.CannotComputeUniqueName, element.Name));
                 }
             }
             if (element.SchemaType == null)
@@ -390,7 +388,7 @@ namespace System.Runtime.Serialization
             {
                 XmlSchemaType? type = SchemaHelper.GetSchemaType(SchemaObjects, typeName);
                 if (type == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.SpecifiedTypeNotFoundInSchema, typeName.Name, typeName.Namespace)));
+                    throw new InvalidDataContractException(SR.Format(SR.SpecifiedTypeNotFoundInSchema, typeName.Name, typeName.Namespace));
                 dataContract = ImportType(type);
             }
             if (IsObjectContract(dataContract))
@@ -990,7 +988,7 @@ namespace System.Runtime.Serialization
             if (!memberTypeContract.IsValueType && !memberIsNullable)
             {
                 if (emitDefaultValueFromAnnotation != null && emitDefaultValueFromAnnotation.Value)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidEmitDefaultAnnotation, memberName, typeName.Name, typeName.Namespace)));
+                    throw new InvalidDataContractException(SR.Format(SR.InvalidEmitDefaultAnnotation, memberName, typeName.Name, typeName.Namespace));
                 memberEmitDefaultValue = false;
             }
             else
@@ -1027,7 +1025,7 @@ namespace System.Runtime.Serialization
                 return null;
             XmlNode? emitDefaultValueAttribute = defaultValueElement.Attributes.GetNamedItem(Globals.EmitDefaultValueAttribute);
             if (emitDefaultValueAttribute?.Value == null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.AnnotationAttributeNotFound, SchemaExporter.DefaultValueAnnotation.Name, typeName.Name, typeName.Namespace, Globals.EmitDefaultValueAttribute)));
+                throw new InvalidDataContractException(SR.Format(SR.AnnotationAttributeNotFound, SchemaExporter.DefaultValueAnnotation.Name, typeName.Name, typeName.Namespace, Globals.EmitDefaultValueAttribute));
             return XmlConvert.ToBoolean(emitDefaultValueAttribute.Value);
         }
 
@@ -1039,10 +1037,10 @@ namespace System.Runtime.Serialization
 
             XmlNode? nameAttribute = actualTypeElement.Attributes.GetNamedItem(Globals.ActualTypeNameAttribute);
             if (nameAttribute?.Value == null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.AnnotationAttributeNotFound, SchemaExporter.ActualTypeAnnotationName.Name, typeName.Name, typeName.Namespace, Globals.ActualTypeNameAttribute)));
+                throw new InvalidDataContractException(SR.Format(SR.AnnotationAttributeNotFound, SchemaExporter.ActualTypeAnnotationName.Name, typeName.Name, typeName.Namespace, Globals.ActualTypeNameAttribute));
             XmlNode? nsAttribute = actualTypeElement.Attributes.GetNamedItem(Globals.ActualTypeNamespaceAttribute);
             if (nsAttribute?.Value == null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.AnnotationAttributeNotFound, SchemaExporter.ActualTypeAnnotationName.Name, typeName.Name, typeName.Namespace, Globals.ActualTypeNamespaceAttribute)));
+                throw new InvalidDataContractException(SR.Format(SR.AnnotationAttributeNotFound, SchemaExporter.ActualTypeAnnotationName.Name, typeName.Name, typeName.Namespace, Globals.ActualTypeNamespaceAttribute));
             return new XmlQualifiedName(nameAttribute.Value, nsAttribute.Value);
         }
 
@@ -1286,10 +1284,10 @@ namespace System.Runtime.Serialization
         {
             string? name = typeElement.Attributes.GetNamedItem(Globals.GenericNameAttribute)?.Value;
             if (name == null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericAnnotationAttributeNotFound, type.Name, Globals.GenericNameAttribute)));
+                throw new InvalidDataContractException(SR.Format(SR.GenericAnnotationAttributeNotFound, type.Name, Globals.GenericNameAttribute));
             string? ns = typeElement.Attributes.GetNamedItem(Globals.GenericNamespaceAttribute)?.Value;
             if (ns == null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericAnnotationAttributeNotFound, type.Name, Globals.GenericNamespaceAttribute)));
+                throw new InvalidDataContractException(SR.Format(SR.GenericAnnotationAttributeNotFound, type.Name, Globals.GenericNamespaceAttribute));
             if (typeElement.ChildNodes.Count > 0) //Generic Type
                 name = DataContract.EncodeLocalName(name);
 
@@ -1301,16 +1299,16 @@ namespace System.Runtime.Serialization
                 {
                     if (argumentElement.LocalName != Globals.GenericParameterLocalName ||
                         argumentElement.NamespaceURI != Globals.SerializationNamespace)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericAnnotationHasInvalidElement, argumentElement.LocalName, argumentElement.NamespaceURI, type.Name)));
+                        throw new InvalidDataContractException(SR.Format(SR.GenericAnnotationHasInvalidElement, argumentElement.LocalName, argumentElement.NamespaceURI, type.Name));
                     XmlNode? nestedLevelAttribute = argumentElement.Attributes.GetNamedItem(Globals.GenericParameterNestedLevelAttribute);
                     int argumentLevel = 0;
                     if (nestedLevelAttribute != null)
                     {
                         if (!int.TryParse(nestedLevelAttribute.Value, out argumentLevel))
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericAnnotationHasInvalidAttributeValue, argumentElement.LocalName, argumentElement.NamespaceURI, type.Name, nestedLevelAttribute.Value, nestedLevelAttribute.LocalName, Globals.TypeOfInt.Name)));
+                            throw new InvalidDataContractException(SR.Format(SR.GenericAnnotationHasInvalidAttributeValue, argumentElement.LocalName, argumentElement.NamespaceURI, type.Name, nestedLevelAttribute.Value, nestedLevelAttribute.LocalName, Globals.TypeOfInt.Name));
                     }
                     if (argumentLevel < currentLevel)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericAnnotationForNestedLevelMustBeIncreasing, argumentElement.LocalName, argumentElement.NamespaceURI, type.Name)));
+                        throw new InvalidDataContractException(SR.Format(SR.GenericAnnotationForNestedLevelMustBeIncreasing, argumentElement.LocalName, argumentElement.NamespaceURI, type.Name));
                     genInfo.Add(ImportGenericInfo(argumentElement, type));
                     genInfo.AddToLevel(argumentLevel, 1);
                     currentLevel = argumentLevel;
@@ -1322,7 +1320,7 @@ namespace System.Runtime.Serialization
             {
                 int nestedLevels;
                 if (!int.TryParse(typeNestedLevelsAttribute.Value, out nestedLevels))
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericAnnotationHasInvalidAttributeValue, typeElement.LocalName, typeElement.NamespaceURI, type.Name, typeNestedLevelsAttribute.Value, typeNestedLevelsAttribute.LocalName, Globals.TypeOfInt.Name)));
+                    throw new InvalidDataContractException(SR.Format(SR.GenericAnnotationHasInvalidAttributeValue, typeElement.LocalName, typeElement.NamespaceURI, type.Name, typeNestedLevelsAttribute.Value, typeNestedLevelsAttribute.LocalName, Globals.TypeOfInt.Name));
                 if ((nestedLevels - 1) > currentLevel)
                     genInfo.AddToLevel(nestedLevels - 1, 0);
             }
@@ -1470,7 +1468,7 @@ namespace System.Runtime.Serialization
         [DoesNotReturn]
         private static void ThrowTypeCannotBeImportedException(string message)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.TypeCannotBeImportedHowToFix, message)));
+            throw new InvalidDataContractException(SR.Format(SR.TypeCannotBeImportedHowToFix, message));
         }
     }
 
index afe290612fab45c6447a3211d2d40193147b0ae4..40b5ffb5114d8b6dc6480a12450effa357c5d985 100644 (file)
@@ -64,7 +64,7 @@ namespace System.Runtime.Serialization
             {
                 return ProcessClassDataContract((ClassDataContract)contract, context, memberNode);
             }
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.QueryGeneratorPathToMemberNotFound));
+            throw XmlObjectSerializer.CreateSerializationException(SR.QueryGeneratorPathToMemberNotFound);
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
@@ -80,7 +80,7 @@ namespace System.Runtime.Serialization
                     return member.MemberTypeContract;
                 }
             }
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.QueryGeneratorPathToMemberNotFound));
+            throw XmlObjectSerializer.CreateSerializationException(SR.QueryGeneratorPathToMemberNotFound);
         }
 
         private static IEnumerable<DataMember> GetDataMembers(ClassDataContract contract)
index 85b6df82804e7d6d606be06e9927e343e189d63a..6017b219bb5d4761b892936577ab4e49133b399c 100644 (file)
@@ -138,9 +138,9 @@ namespace System.Runtime.Serialization.DataContracts
                 Type type) : base(type)
             {
                 if (type.IsDefined(Globals.TypeOfDataContractAttribute, false))
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IXmlSerializableCannotHaveDataContract, DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.IXmlSerializableCannotHaveDataContract, DataContract.GetClrTypeFullName(type)));
                 if (type.IsDefined(Globals.TypeOfCollectionDataContractAttribute, false))
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IXmlSerializableCannotHaveCollectionDataContract, DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.IXmlSerializableCannotHaveCollectionDataContract, DataContract.GetClrTypeFullName(type)));
                 bool hasRoot;
                 XmlSchemaType? xsdType;
                 XmlQualifiedName xmlName;
@@ -174,7 +174,7 @@ namespace System.Runtime.Serialization.DataContracts
                     }
                     else
                     {
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IsAnyCannotHaveXmlRoot, DataContract.GetClrTypeFullName(UnderlyingType!))));
+                        throw new InvalidDataContractException(SR.Format(SR.IsAnyCannotHaveXmlRoot, DataContract.GetClrTypeFullName(UnderlyingType!)));
                     }
                 }
             }
@@ -251,7 +251,7 @@ namespace System.Runtime.Serialization.DataContracts
 
             ConstructorInfo? ctor = UnderlyingType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Type.EmptyTypes);
             if (ctor == null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IXmlSerializableMustHaveDefaultConstructor, DataContract.GetClrTypeFullName(UnderlyingType))));
+                throw new InvalidDataContractException(SR.Format(SR.IXmlSerializableMustHaveDefaultConstructor, DataContract.GetClrTypeFullName(UnderlyingType)));
 
             return ctor;
         }
@@ -340,9 +340,8 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(SR.PartialTrustIXmlSerializableTypeNotPublic, DataContract.GetClrTypeFullName(UnderlyingType)),
-                        securityException));
+                    throw new SecurityException(SR.Format(SR.PartialTrustIXmlSerializableTypeNotPublic, DataContract.GetClrTypeFullName(UnderlyingType)),
+                        securityException);
                 }
                 return true;
             }
@@ -351,9 +350,8 @@ namespace System.Runtime.Serialization.DataContracts
             {
                 if (securityException != null)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        new SecurityException(SR.Format(SR.PartialTrustIXmlSerialzableNoPublicConstructor, DataContract.GetClrTypeFullName(UnderlyingType)),
-                        securityException));
+                    throw new SecurityException(SR.Format(SR.PartialTrustIXmlSerialzableNoPublicConstructor, DataContract.GetClrTypeFullName(UnderlyingType)),
+                        securityException);
                 }
                 return true;
             }
index 028239874b8ffa3a7e2939b0014d913e2c5aedb7..0401f0e410747200704f76dd9f032c2049d5bc2b 100644 (file)
@@ -919,7 +919,7 @@ namespace System.Runtime.Serialization
                     ClassDataContract? keyValuePairContract = DataContract.GetDataContract(value.LocalType) as ClassDataContract;
                     if (keyValuePairContract == null)
                     {
-                        DiagnosticUtility.DebugAssert("Failed to create contract for KeyValuePair type");
+                        Debug.Fail("Failed to create contract for KeyValuePair type");
                     }
                     DataMember keyMember = keyValuePairContract.Members![0];
                     DataMember valueMember = keyValuePairContract.Members[1];
index 6f2de847b58353e0b69c04d0e5a45470828dde6c..db26bf0bd5fd8807f07e4636885f6601e267dbad 100644 (file)
@@ -101,11 +101,11 @@ namespace System.Runtime.Serialization
             }
             catch (XmlException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex);
             }
             catch (FormatException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex);
             }
         }
 
@@ -139,22 +139,22 @@ namespace System.Runtime.Serialization
         [RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
         internal virtual void InternalWriteStartObject(XmlWriterDelegator writer, object? graph)
         {
-            DiagnosticUtility.DebugAssert("XmlObjectSerializer.InternalWriteStartObject should never get called");
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+            Debug.Fail("XmlObjectSerializer.InternalWriteStartObject should never get called");
+            throw new NotSupportedException();
         }
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
         [RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
         internal virtual void InternalWriteObjectContent(XmlWriterDelegator writer, object? graph)
         {
-            DiagnosticUtility.DebugAssert("XmlObjectSerializer.InternalWriteObjectContent should never get called");
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+            Debug.Fail("XmlObjectSerializer.InternalWriteObjectContent should never get called");
+            throw new NotSupportedException();
         }
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
         [RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
         internal virtual void InternalWriteEndObject(XmlWriterDelegator writer)
         {
-            DiagnosticUtility.DebugAssert("XmlObjectSerializer.InternalWriteEndObject should never get called");
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+            Debug.Fail("XmlObjectSerializer.InternalWriteEndObject should never get called");
+            throw new NotSupportedException();
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
@@ -169,11 +169,11 @@ namespace System.Runtime.Serialization
             }
             catch (XmlException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorWriteStartObject, GetSerializeType(graph), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorWriteStartObject, GetSerializeType(graph), ex), ex);
             }
             catch (FormatException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorWriteStartObject, GetSerializeType(graph), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorWriteStartObject, GetSerializeType(graph), ex), ex);
             }
         }
 
@@ -186,16 +186,16 @@ namespace System.Runtime.Serialization
             try
             {
                 if (writer.WriteState != WriteState.Element)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.XmlWriterMustBeInElement, writer.WriteState)));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.XmlWriterMustBeInElement, writer.WriteState));
                 InternalWriteObjectContent(writer, graph);
             }
             catch (XmlException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex);
             }
             catch (FormatException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex);
             }
         }
 
@@ -211,11 +211,11 @@ namespace System.Runtime.Serialization
             }
             catch (XmlException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorWriteEndObject, null, ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorWriteEndObject, null, ex), ex);
             }
             catch (FormatException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorWriteEndObject, null, ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorWriteEndObject, null, ex), ex);
             }
         }
 
@@ -334,8 +334,8 @@ namespace System.Runtime.Serialization
         [RequiresUnreferencedCode(DataContract.SerializerTrimmerWarning)]
         internal virtual bool InternalIsStartObject(XmlReaderDelegator reader)
         {
-            DiagnosticUtility.DebugAssert("XmlObjectSerializer.InternalIsStartObject should never get called");
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+            Debug.Fail("XmlObjectSerializer.InternalIsStartObject should never get called");
+            throw new NotSupportedException();
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
@@ -357,11 +357,11 @@ namespace System.Runtime.Serialization
             }
             catch (XmlException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorDeserializing, GetDeserializeType(), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorDeserializing, GetDeserializeType(), ex), ex);
             }
             catch (FormatException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorDeserializing, GetDeserializeType(), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorDeserializing, GetDeserializeType(), ex), ex);
             }
         }
 
@@ -377,11 +377,11 @@ namespace System.Runtime.Serialization
             }
             catch (XmlException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorIsStartObject, GetDeserializeType(), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorIsStartObject, GetDeserializeType(), ex), ex);
             }
             catch (FormatException ex)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorIsStartObject, GetDeserializeType(), ex), ex));
+                throw XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorIsStartObject, GetDeserializeType(), ex), ex);
             }
         }
 
index 61a3c5f53847aa36c66e9897a99e0ce388fed010..ee2df1d054f29888ccf4338b18e0601e7efe775a 100644 (file)
@@ -71,7 +71,7 @@ namespace System.Runtime.Serialization
         internal void IncrementItemCount(int count)
         {
             if (count > _maxItemsInObjectGraph - _itemCount)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, _maxItemsInObjectGraph)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, _maxItemsInObjectGraph));
             _itemCount += count;
         }
 
@@ -147,7 +147,7 @@ namespace System.Runtime.Serialization
         internal virtual void CheckIfTypeSerializable(Type memberType, bool isMemberTypeSerializable)
         {
             if (!isMemberTypeSerializable)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.TypeNotSerializable, memberType)));
+                throw new InvalidDataContractException(SR.Format(SR.TypeNotSerializable, memberType));
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
@@ -194,7 +194,7 @@ namespace System.Runtime.Serialization
             {
                 Type knownType = knownTypeList[i];
                 if (knownType == null)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.NullKnownType, "knownTypes")));
+                    throw new ArgumentException(SR.Format(SR.NullKnownType, "knownTypes"));
 
                 DataContract.CheckAndAdd(knownType, typesChecked, ref dataContracts);
             }
index c6b5978bf4b06759043fdf47749994e251623f19..130c45d2b55aea9136bfa8c2710d9afad6ea806c 100644 (file)
@@ -57,13 +57,13 @@ namespace System.Runtime.Serialization
         [DoesNotReturn]
         internal static void ThrowNullValueReturnedForGetOnlyCollectionException(Type type)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NullValueReturnedForGetOnlyCollection, DataContract.GetClrTypeFullName(type))));
+            throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NullValueReturnedForGetOnlyCollection, DataContract.GetClrTypeFullName(type)));
         }
 
         [DoesNotReturn]
         internal static void ThrowArrayExceededSizeException(int arraySize, Type type)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayExceededSize, arraySize, DataContract.GetClrTypeFullName(type))));
+            throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayExceededSize, arraySize, DataContract.GetClrTypeFullName(type)));
         }
 
         internal static XmlObjectSerializerReadContext CreateContext(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver? dataContractResolver)
@@ -118,7 +118,7 @@ namespace System.Runtime.Serialization
             {
                 if (_isGetOnlyCollection)
                 {
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ErrorDeserializing, SR.Format(SR.ErrorTypeInfo, DataContract.GetClrTypeFullName(declaredType)), SR.Format(SR.XmlStartElementExpected, Globals.RefLocalName))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ErrorDeserializing, SR.Format(SR.ErrorTypeInfo, DataContract.GetClrTypeFullName(declaredType)), SR.Format(SR.XmlStartElementExpected, Globals.RefLocalName)));
                 }
                 else
                 {
@@ -159,9 +159,9 @@ namespace System.Runtime.Serialization
                 {
                     if (DataContractResolver == null)
                     {
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, SR.Format(SR.DcTypeNotFoundOnDeserialize, attributes.XsiTypeNamespace, attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName))));
+                        throw XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, SR.Format(SR.DcTypeNotFoundOnDeserialize, attributes.XsiTypeNamespace, attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName)));
                     }
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, SR.Format(SR.DcTypeNotResolvedOnDeserialize, attributes.XsiTypeNamespace, attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName))));
+                    throw XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, SR.Format(SR.DcTypeNotResolvedOnDeserialize, attributes.XsiTypeNamespace, attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName)));
                 }
                 dataContract = tempDataContract;
                 knownTypesAddedInCurrentScope = ReplaceScopedKnownTypesTop(dataContract.KnownDataContracts, knownTypesAddedInCurrentScope);
@@ -179,7 +179,7 @@ namespace System.Runtime.Serialization
                     }
                     else
                     {
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.FactoryTypeNotISerializable, DataContract.GetClrTypeFullName(factoryDataContract.UnderlyingType), DataContract.GetClrTypeFullName(dataContract.UnderlyingType))));
+                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.FactoryTypeNotISerializable, DataContract.GetClrTypeFullName(factoryDataContract.UnderlyingType), DataContract.GetClrTypeFullName(dataContract.UnderlyingType)));
                     }
                 }
             }
@@ -258,7 +258,7 @@ namespace System.Runtime.Serialization
                     stringBuilder.Append(" | ");
                 stringBuilder.Append(memberNames[i].Value);
             }
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, SR.Format(SR.UnexpectedElementExpectingElements, xmlReader.NodeType, xmlReader.LocalName, xmlReader.NamespaceURI, stringBuilder.ToString()))));
+            throw XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, SR.Format(SR.UnexpectedElementExpectingElements, xmlReader.NodeType, xmlReader.LocalName, xmlReader.NamespaceURI, stringBuilder.ToString())));
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
@@ -267,7 +267,7 @@ namespace System.Runtime.Serialization
         {
             xmlReader.MoveToContent();
             if (xmlReader.NodeType != XmlNodeType.Element)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+                throw CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
 
             if (IgnoreExtensionDataObject || extensionData == null)
                 SkipUnknownElement(xmlReader);
@@ -366,7 +366,7 @@ namespace System.Runtime.Serialization
                 {
                     string oldType = (oldObj != null) ? DataContract.GetClrTypeFullName(oldObj.GetType()) : SR.UnknownNullType;
                     string newType = (newObj != null) ? DataContract.GetClrTypeFullName(newObj.GetType()) : SR.UnknownNullType;
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.FactoryObjectContainsSelfReference, oldType, newType, id)));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.FactoryObjectContainsSelfReference, oldType, newType, id));
                 }
                 DeserializedObjects.Remove(id);
                 DeserializedObjects.Add(id, newObj);
@@ -382,7 +382,7 @@ namespace System.Runtime.Serialization
             object? retObj = DeserializedObjects.GetObject(id);
 
             if (retObj == null)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.DeserializedObjectWithIdNotFound, id)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.DeserializedObjectWithIdNotFound, id));
 
             if (retObj is IDataNode dataNode)
             {
@@ -396,8 +396,7 @@ namespace System.Runtime.Serialization
             object? retObj = DeserializedObjects.GetObject(id);
             if (retObj == null)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                    XmlObjectSerializer.CreateSerializationException(SR.Format(SR.DeserializedObjectWithIdNotFound, id)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.DeserializedObjectWithIdNotFound, id));
             }
 
             return retObj;
@@ -413,7 +412,7 @@ namespace System.Runtime.Serialization
             // forward references. However, we throw for this case since it allows us to add fix-up support
             // in the future if we need to.
             if (realObj == null)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException("error"));
+                throw XmlObjectSerializer.CreateSerializationException("error");
             ReplaceDeserializedObject(id, obj, realObj);
             return realObj;
         }
@@ -434,7 +433,7 @@ namespace System.Runtime.Serialization
         internal static void Read(XmlReaderDelegator xmlReader)
         {
             if (!xmlReader.Read())
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile));
+                throw XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile);
         }
 
         internal static void ParseQualifiedName(string qname, XmlReaderDelegator xmlReader, out string name, out string? ns, out string prefix)
@@ -453,10 +452,9 @@ namespace System.Runtime.Serialization
             {
                 if (index == int.MaxValue)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
-                        XmlObjectSerializer.CreateSerializationException(
+                    throw XmlObjectSerializer.CreateSerializationException(
                         SR.Format(SR.MaxArrayLengthExceeded, int.MaxValue,
-                        DataContract.GetClrTypeFullName(typeof(T)))));
+                        DataContract.GetClrTypeFullName(typeof(T))));
                 }
                 int newSize = (index < int.MaxValue / 2) ? index * 2 : int.MaxValue;
                 T[] newArray = new T[newSize];
@@ -484,11 +482,11 @@ namespace System.Runtime.Serialization
             while (xmlReader.IsStartElement())
             {
                 if (xmlReader.IsStartElement(itemName, itemNamespace))
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayExceededSizeAttribute, arraySize, itemName.Value, itemNamespace.Value)));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayExceededSizeAttribute, arraySize, itemName.Value, itemNamespace.Value));
                 SkipUnknownElement(xmlReader);
             }
             if (xmlReader.NodeType != XmlNodeType.EndElement)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.EndElement, xmlReader));
+                throw CreateUnexpectedStateException(XmlNodeType.EndElement, xmlReader);
         }
 
         [RequiresDynamicCode(DataContract.SerializerAOTWarning)]
@@ -520,7 +518,7 @@ namespace System.Runtime.Serialization
             if (xmlDataContract.UnderlyingType == Globals.TypeOfXmlElement)
             {
                 if (!xmlReader.IsStartElement())
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+                    throw CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
                 XmlDocument xmlDoc = new XmlDocument();
                 obj = (XmlElement?)xmlDoc.ReadNode(xmlSerializableReader);
             }
@@ -548,7 +546,7 @@ namespace System.Runtime.Serialization
             {
                 if (nodeType != XmlNodeType.Element)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+                    throw CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
                 }
 
                 if (xmlReader.NamespaceURI.Length != 0)
@@ -738,7 +736,7 @@ namespace System.Runtime.Serialization
                         return objNode;
                     }
                 default:
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+                    throw CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
             }
         }
 
@@ -791,7 +789,7 @@ namespace System.Runtime.Serialization
             while ((nodeType = xmlReader.MoveToContent()) != XmlNodeType.EndElement)
             {
                 if (nodeType != XmlNodeType.Element)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+                    throw CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
 
                 dataNode.Members ??= new List<ExtensionDataMember>();
                 dataNode.Members.Add(ReadExtensionDataMember(xmlReader, memberIndex++));
@@ -814,7 +812,7 @@ namespace System.Runtime.Serialization
             while ((nodeType = xmlReader.MoveToContent()) != XmlNodeType.EndElement)
             {
                 if (nodeType != XmlNodeType.Element)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+                    throw CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
 
                 if (dataNode.ItemName == null)
                 {
@@ -837,10 +835,10 @@ namespace System.Runtime.Serialization
                 if (dataNode.Items == null)
                 {
                     if (dataNode.Size > 0)
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArraySizeAttributeIncorrect, arraySize, 0)));
+                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArraySizeAttributeIncorrect, arraySize, 0));
                 }
                 else if (dataNode.Size != dataNode.Items.Count)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArraySizeAttributeIncorrect, arraySize, dataNode.Items.Count)));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArraySizeAttributeIncorrect, arraySize, dataNode.Items.Count));
             }
             else
             {
@@ -873,7 +871,7 @@ namespace System.Runtime.Serialization
             while ((nodeType = xmlReader.MoveToContent()) != XmlNodeType.EndElement)
             {
                 if (nodeType != XmlNodeType.Element)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+                    throw CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
 
                 if (xmlReader.NamespaceURI.Length != 0)
                 {
@@ -922,7 +920,7 @@ namespace System.Runtime.Serialization
             while (xmlReader.MoveToContent() != XmlNodeType.EndElement)
             {
                 if (xmlReader.EOF)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile);
 
                 xmlChildNodes ??= new List<XmlNode>();
                 xmlChildNodes.Add(Document.ReadNode(xmlReader.UnderlyingReader)!);
@@ -981,7 +979,7 @@ namespace System.Runtime.Serialization
                     }
                 }
                 else if (xmlReader.EOF)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile);
                 else if (IsContentNode(xmlReader.NodeType))
                     couldBeClassData = couldBeISerializableData = couldBeCollectionData = false;
 
index 5af6d57016f9968fa3f14413d51aca74b16cadc9..11cbb6a0ac07e8c786de48e20b8c485d6176d49c 100644 (file)
@@ -66,7 +66,7 @@ namespace System.Runtime.Serialization
                 GetDataContract(DataContractSurrogateCaller.GetDataContractType(_serializationSurrogateProvider, declaredType));
             if (this.IsGetOnlyCollection && dataContract.UnderlyingType != declaredType)
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser, DataContract.GetClrTypeFullName(declaredType))));
+                throw new InvalidDataContractException(SR.Format(SR.SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser, DataContract.GetClrTypeFullName(declaredType)));
             }
             ReadAttributes(xmlReader);
             string objectId = GetObjectId();
@@ -87,7 +87,7 @@ namespace System.Runtime.Serialization
                     memberType = memberType.GetElementType()!;
                 memberType = DataContractSurrogateCaller.GetDataContractType(_serializationSurrogateProvider, memberType);
                 if (!DataContract.IsTypeSerializable(memberType))
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.TypeNotSerializable, memberType)));
+                    throw new InvalidDataContractException(SR.Format(SR.TypeNotSerializable, memberType));
                 return;
             }
 
@@ -108,8 +108,8 @@ namespace System.Runtime.Serialization
                 Type surrogateType = DataContractSerializer.GetSurrogatedType(_serializationSurrogateProvider, type);
                 if (this.IsGetOnlyCollection && surrogateType != type)
                 {
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser,
-                        DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser,
+                        DataContract.GetClrTypeFullName(type)));
                 }
                 else
                 {
index b88c4d522954f1f48ef49d2c3ec5bb99634178a9..c0909735e7f04a66e39e57c09ea2e19ab40116ce 100644 (file)
@@ -245,7 +245,7 @@ namespace System.Runtime.Serialization
                     DataContract? knownContract = ResolveDataContractFromKnownTypes(dataContract.XmlName.Name, dataContract.XmlName.Namespace, null /*memberTypeContract*/, declaredType);
                     if (knownContract == null || knownContract.UnderlyingType != dataContract.UnderlyingType)
                     {
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.DcTypeNotFoundOnSerialize, DataContract.GetClrTypeFullName(dataContract.UnderlyingType), dataContract.XmlName.Name, dataContract.XmlName.Namespace)));
+                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.DcTypeNotFoundOnSerialize, DataContract.GetClrTypeFullName(dataContract.UnderlyingType), dataContract.XmlName.Name, dataContract.XmlName.Namespace));
                     }
                 }
             }
@@ -380,7 +380,7 @@ namespace System.Runtime.Serialization
             if (canContainCyclicReference)
             {
                 if (_byValObjectsInScope.Contains(obj))
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotSerializeObjectWithCycles, DataContract.GetClrTypeFullName(obj.GetType()))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotSerializeObjectWithCycles, DataContract.GetClrTypeFullName(obj.GetType())));
                 _byValObjectsInScope.Push(obj);
             }
             return false;
@@ -459,7 +459,7 @@ namespace System.Runtime.Serialization
 
         internal static void ThrowRequiredMemberMustBeEmitted(string memberName, Type type)
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(SR.RequiredMemberMustBeEmitted, memberName, type.FullName)));
+            throw new SerializationException(SR.Format(SR.RequiredMemberMustBeEmitted, memberName, type.FullName));
         }
 
         internal static bool GetHasValue<T>(Nullable<T> value) where T : struct
@@ -496,7 +496,7 @@ namespace System.Runtime.Serialization
                         foreach (XmlNode xmlNode in xmlNodes)
                             xmlNode.WriteTo(xmlSerializableWriter);
                     else
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.UnknownXmlType, DataContract.GetClrTypeFullName(obj.GetType()))));
+                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.UnknownXmlType, DataContract.GetClrTypeFullName(obj.GetType())));
                 }
             }
             xmlSerializableWriter.EndWrite();
@@ -520,7 +520,7 @@ namespace System.Runtime.Serialization
             //if (!UnsafeTypeForwardingEnabled && serInfo.AssemblyName == Globals.MscorlibAssemblyName)
             //{
             //    // Throw if a malicious type tries to set its assembly name to "0" to get deserialized in mscorlib
-            //    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ISerializableAssemblyNameSetToZero, DataContract.GetClrTypeFullName(obj.GetType()))));
+            //    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ISerializableAssemblyNameSetToZero, DataContract.GetClrTypeFullName(obj.GetType())));
             //}
 
             WriteSerializationInfo(xmlWriter, objType, serInfo);
@@ -599,7 +599,7 @@ namespace System.Runtime.Serialization
 
             if (!DataContractResolver.TryResolveType(objectType, declaredType, KnownTypeResolver, out typeName, out typeNamespace))
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ResolveTypeReturnedFalse, DataContract.GetClrTypeFullName(DataContractResolver.GetType()), DataContract.GetClrTypeFullName(objectType))));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ResolveTypeReturnedFalse, DataContract.GetClrTypeFullName(DataContractResolver.GetType()), DataContract.GetClrTypeFullName(objectType)));
             }
             if (typeName == null)
             {
@@ -609,12 +609,12 @@ namespace System.Runtime.Serialization
                 }
                 else
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ResolveTypeReturnedNull, DataContract.GetClrTypeFullName(DataContractResolver.GetType()), DataContract.GetClrTypeFullName(objectType))));
+                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ResolveTypeReturnedNull, DataContract.GetClrTypeFullName(DataContractResolver.GetType()), DataContract.GetClrTypeFullName(objectType)));
                 }
             }
             if (typeNamespace == null)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ResolveTypeReturnedNull, DataContract.GetClrTypeFullName(DataContractResolver.GetType()), DataContract.GetClrTypeFullName(objectType))));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ResolveTypeReturnedNull, DataContract.GetClrTypeFullName(DataContractResolver.GetType()), DataContract.GetClrTypeFullName(objectType)));
             }
             return true;
         }
index 1f3bbe4f0e45c8384d4cd6bf28d1ef8abf8d94bf..a239ece9318d352b269a35e70417446c52229bca 100644 (file)
@@ -185,7 +185,7 @@ namespace System.Runtime.Serialization
                     memberType = memberType.GetElementType()!;
                 memberType = DataContractSurrogateCaller.GetDataContractType(_serializationSurrogateProvider, memberType);
                 if (!DataContract.IsTypeSerializable(memberType))
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.TypeNotSerializable, memberType)));
+                    throw new InvalidDataContractException(SR.Format(SR.TypeNotSerializable, memberType));
                 return;
             }
 
@@ -206,8 +206,8 @@ namespace System.Runtime.Serialization
                 Type surrogateType = DataContractSerializer.GetSurrogatedType(_serializationSurrogateProvider, type);
                 if (this.IsGetOnlyCollection && surrogateType != type)
                 {
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser,
-                        DataContract.GetClrTypeFullName(type))));
+                    throw new InvalidDataContractException(SR.Format(SR.SurrogatesWithGetOnlyCollectionsNotSupportedSerDeser,
+                        DataContract.GetClrTypeFullName(type)));
                 }
                 else
                 {
index 147fca02494fbb9a3ce2bcc5b91957a02dba2b83..4dd01a1fec559ad083179f2a3e33a4ce1a13642a 100644 (file)
@@ -52,7 +52,7 @@ namespace System.Runtime.Serialization
         internal string GetAttribute(int i)
         {
             if (isEndOfEmptyElement)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(i), SR.XmlElementAttributes));
+                throw new ArgumentOutOfRangeException(nameof(i), SR.XmlElementAttributes);
             return reader.GetAttribute(i);
         }
 
@@ -145,7 +145,7 @@ namespace System.Runtime.Serialization
         internal void MoveToAttribute(int i)
         {
             if (isEndOfEmptyElement)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(i), SR.XmlElementAttributes));
+                throw new ArgumentOutOfRangeException(nameof(i), SR.XmlElementAttributes);
             reader.MoveToAttribute(i);
         }
 
@@ -274,7 +274,7 @@ namespace System.Runtime.Serialization
                         return ReadContentAsQName();
                     break;
             }
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
+            throw CreateInvalidPrimitiveTypeException(valueType);
         }
 
         internal IDataNode ReadExtensionData(Type valueType)
@@ -329,19 +329,19 @@ namespace System.Runtime.Serialization
                         return new DataNode<XmlQualifiedName>(ReadContentAsQName());
                     break;
             }
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
+            throw CreateInvalidPrimitiveTypeException(valueType);
         }
 
         [DoesNotReturn]
         private void ThrowConversionException(string value, string type)
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(XmlObjectSerializer.TryAddLineInfo(this, SR.Format(SR.XmlInvalidConversion, value, type))));
+            throw new XmlException(XmlObjectSerializer.TryAddLineInfo(this, SR.Format(SR.XmlInvalidConversion, value, type)));
         }
 
         [DoesNotReturn]
         private static void ThrowNotAtElement()
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.XmlStartElementExpected, "EndElement")));
+            throw new XmlException(SR.Format(SR.XmlStartElementExpected, "EndElement"));
         }
 
         internal virtual char ReadElementContentAsChar()
@@ -485,11 +485,11 @@ namespace System.Runtime.Serialization
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "byte[]", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "byte[]", exception);
             }
         }
 
@@ -686,15 +686,15 @@ namespace System.Runtime.Serialization
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Guid", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Guid", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Guid", exception);
             }
         }
 
@@ -707,15 +707,15 @@ namespace System.Runtime.Serialization
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Guid", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Guid", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Guid", exception);
             }
         }
 
@@ -731,11 +731,11 @@ namespace System.Runtime.Serialization
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Uri", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Uri", exception);
             }
         }
 
@@ -748,11 +748,11 @@ namespace System.Runtime.Serialization
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Uri", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
+                throw XmlExceptionHelper.CreateConversionException(str, "Uri", exception);
             }
         }
 
@@ -796,7 +796,7 @@ namespace System.Runtime.Serialization
         private static void CheckActualArrayLength(int expectedLength, int actualLength, XmlDictionaryString itemName, XmlDictionaryString itemNamespace)
         {
             if (expectedLength != actualLength)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayExceededSizeAttribute, expectedLength, itemName.Value, itemNamespace.Value)));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ArrayExceededSizeAttribute, expectedLength, itemName.Value, itemNamespace.Value));
         }
 
         internal bool TryReadBooleanArray(XmlObjectSerializerReadContext context,
index 7d01b25c192b58b9ed34bcf867d0779cf350d9a5..397156a7f4b1c92ff01116e86fec8c2620f3514d 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Runtime.Serialization
         internal void BeginRead(XmlReaderDelegator xmlReader)
         {
             if (xmlReader.NodeType != XmlNodeType.Element)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+                throw XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
             _xmlReader = xmlReader;
             _startDepth = xmlReader.Depth;
             _innerReader = xmlReader.UnderlyingReader;
@@ -43,7 +43,7 @@ namespace System.Runtime.Serialization
                 while (_xmlReader.Depth > _startDepth)
                 {
                     if (!_xmlReader.Read())
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.EndElement, _xmlReader));
+                        throw XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.EndElement, _xmlReader);
                 }
             }
         }
@@ -64,7 +64,7 @@ namespace System.Runtime.Serialization
 
         public override void Close()
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.IXmlSerializableIllegalOperation));
+            throw XmlObjectSerializer.CreateSerializationException(SR.IXmlSerializableIllegalOperation);
         }
 
         public override XmlReaderSettings? Settings { get { return InnerReader.Settings; } }
index 7bbb47c1bde89058113fab6026dc3dc5e1c1031a..ffa24e873bd9c8339815034d76207d6377c50607 100644 (file)
@@ -23,7 +23,7 @@ namespace System.Runtime.Serialization
                     {
                         XmlNode? node = doc.ReadNode(xmlReader);
                         if (node == null)
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile));
+                            throw XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile);
                         nodeList.Add(node);
                     }
                 } while (xmlReader.MoveToNextAttribute());
@@ -37,7 +37,7 @@ namespace System.Runtime.Serialization
                 {
                     XmlNode? node = doc.ReadNode(xmlReader);
                     if (node == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile));
+                        throw XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile);
                     nodeList.Add(node);
                 }
             }
index 1b9c39249c6ba87ae9098898396bebc621fd4851..6fdc88ff348997fdd4b513577e05b04ff587e43e 100644 (file)
@@ -24,7 +24,7 @@ namespace System.Runtime.Serialization
         internal void EndWrite()
         {
             if (_depth != 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IXmlSerializableMissingEndElements, (_obj == null ? string.Empty : DataContract.GetClrTypeFullName(_obj.GetType())))));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IXmlSerializableMissingEndElements, (_obj == null ? string.Empty : DataContract.GetClrTypeFullName(_obj.GetType()))));
             _obj = null;
         }
 
@@ -53,7 +53,7 @@ namespace System.Runtime.Serialization
         public override void WriteEndElement()
         {
             if (_depth == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IXmlSerializableWritePastSubTree, (_obj == null ? string.Empty : DataContract.GetClrTypeFullName(_obj.GetType())))));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IXmlSerializableWritePastSubTree, (_obj == null ? string.Empty : DataContract.GetClrTypeFullName(_obj.GetType()))));
             _xmlWriter.WriteEndElement();
             _depth--;
         }
@@ -61,14 +61,14 @@ namespace System.Runtime.Serialization
         public override void WriteFullEndElement()
         {
             if (_depth == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IXmlSerializableWritePastSubTree, (_obj == null ? string.Empty : DataContract.GetClrTypeFullName(_obj.GetType())))));
+                throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IXmlSerializableWritePastSubTree, (_obj == null ? string.Empty : DataContract.GetClrTypeFullName(_obj.GetType()))));
             _xmlWriter.WriteFullEndElement();
             _depth--;
         }
 
         public override void Close()
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.IXmlSerializableIllegalOperation));
+            throw XmlObjectSerializer.CreateSerializationException(SR.IXmlSerializableIllegalOperation);
         }
 
         public override void WriteStartAttribute(string? prefix, string localName, string? ns)
index 2682d2ab60d5ef63cb5aa28adb0cd9b264fa4d11..0832b664f65fb00d4870529c0cb92a24c1d73a6c 100644 (file)
@@ -352,7 +352,7 @@ namespace System.Runtime.Serialization
                     break;
             }
             if (!handled)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
+                throw CreateInvalidPrimitiveTypeException(valueType);
         }
 
         internal void WriteExtensionData(IDataNode dataNode)
@@ -433,7 +433,7 @@ namespace System.Runtime.Serialization
 
             if (!handled)
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
+                throw CreateInvalidPrimitiveTypeException(valueType);
             }
         }
 
index 8714679f29024577f655396c1f66b311c27f6677..caf0a365935cad23b6abc4163d30708d7c385494 100644 (file)
@@ -92,7 +92,7 @@ namespace System.Runtime.Serialization
         private static void EnsureTypeNotGeneric(Type type)
         {
             if (type.ContainsGenericParameters)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.GenericTypeNotExportable, type)));
+                throw new InvalidDataContractException(SR.Format(SR.GenericTypeNotExportable, type));
         }
 
         /// <summary>
@@ -111,7 +111,7 @@ namespace System.Runtime.Serialization
                 foreach (Assembly assembly in assemblies)
                 {
                     if (assembly == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.CannotExportNullAssembly, nameof(assemblies))));
+                        throw new ArgumentException(SR.Format(SR.CannotExportNullAssembly, nameof(assemblies)));
 
                     Type[] types = assembly.GetTypes();
                     for (int j = 0; j < types.Length; j++)
@@ -120,11 +120,8 @@ namespace System.Runtime.Serialization
 
                 Export();
             }
-            catch (Exception ex)
+            catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
             {
-                if (Fx.IsFatal(ex))
-                    throw;
-
                 _dataContractSet = oldValue;
                 throw;
             }
@@ -146,17 +143,14 @@ namespace System.Runtime.Serialization
                 foreach (Type type in types)
                 {
                     if (type == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.CannotExportNullType, nameof(types))));
+                        throw new ArgumentException(SR.Format(SR.CannotExportNullType, nameof(types)));
                     AddType(type);
                 }
 
                 Export();
             }
-            catch (Exception ex)
+            catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
             {
-                if (Fx.IsFatal(ex))
-                    throw;
-
                 _dataContractSet = oldValue;
                 throw;
             }
@@ -178,11 +172,8 @@ namespace System.Runtime.Serialization
                 AddType(type);
                 Export();
             }
-            catch (Exception ex)
+            catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
             {
-                if (Fx.IsFatal(ex))
-                    throw;
-
                 _dataContractSet = oldValue;
                 throw;
             }
@@ -299,7 +290,7 @@ namespace System.Runtime.Serialization
                     {
                         Type type = knownTypes[i];
                         if (type == null)
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.CannotExportNullKnownType));
+                            throw new ArgumentException(SR.CannotExportNullKnownType);
                         AddType(type);
                     }
                 }
@@ -323,7 +314,7 @@ namespace System.Runtime.Serialization
                 foreach (Assembly assembly in assemblies)
                 {
                     if (assembly == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.CannotExportNullAssembly, nameof(assemblies))));
+                        throw new ArgumentException(SR.Format(SR.CannotExportNullAssembly, nameof(assemblies)));
 
                     Type[] types = assembly.GetTypes();
                     for (int j = 0; j < types.Length; j++)
@@ -337,11 +328,8 @@ namespace System.Runtime.Serialization
                 _dataContractSet = oldValue;
                 return false;
             }
-            catch (Exception ex)
+            catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
             {
-                if (Fx.IsFatal(ex))
-                    throw;
-
                 _dataContractSet = oldValue;
                 throw;
             }
@@ -364,7 +352,7 @@ namespace System.Runtime.Serialization
                 foreach (Type type in types)
                 {
                     if (type == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.CannotExportNullType, nameof(types))));
+                        throw new ArgumentException(SR.Format(SR.CannotExportNullType, nameof(types)));
                     AddType(type);
                 }
                 AddKnownTypes();
@@ -375,11 +363,8 @@ namespace System.Runtime.Serialization
                 _dataContractSet = oldValue;
                 return false;
             }
-            catch (Exception ex)
+            catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
             {
-                if (Fx.IsFatal(ex))
-                    throw;
-
                 _dataContractSet = oldValue;
                 throw;
             }
@@ -408,11 +393,8 @@ namespace System.Runtime.Serialization
                 _dataContractSet = oldValue;
                 return false;
             }
-            catch (Exception ex)
+            catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
             {
-                if (Fx.IsFatal(ex))
-                    throw;
-
                 _dataContractSet = oldValue;
                 throw;
             }
index 06f13ac58ac0b135ecb5d13e1ea526ad760ed683..d2eca70a51a152fc6abf371566315e25e2cdfb7f 100644 (file)
@@ -5,6 +5,7 @@ using System.Text;
 using System.Diagnostics;
 using System.Runtime.Serialization; //For SR
 using System.Globalization;
+using System.Reflection;
 
 namespace System.Text
 {
@@ -27,10 +28,9 @@ namespace System.Text
 
         public override int GetMaxByteCount(int charCount)
         {
-            if (charCount < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charCount), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(charCount);
             if ((charCount % 4) != 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Length, charCount.ToString())));
+                throw new FormatException(SR.Format(SR.XmlInvalidBase64Length, charCount.ToString()));
             return charCount / 4 * 3;
         }
 
@@ -50,19 +50,17 @@ namespace System.Text
         {
             ArgumentNullException.ThrowIfNull(chars);
 
-            if (index < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(index), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(index);
             if (index > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(index), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(index), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > chars.Length - index)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - index)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - index));
 
             if (count == 0)
                 return 0;
             if ((count % 4) != 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Length, count.ToString())));
+                throw new FormatException(SR.Format(SR.XmlInvalidBase64Length, count.ToString()));
             fixed (byte* _char2val = &Char2val[0])
             {
                 fixed (char* _chars = &chars[index])
@@ -72,14 +70,14 @@ namespace System.Text
                     char* pchMax = _chars + count;
                     while (pch < pchMax)
                     {
-                        DiagnosticUtility.DebugAssert(pch + 4 <= pchMax, "");
+                        Debug.Assert(pch + 4 <= pchMax);
                         char pch0 = pch[0];
                         char pch1 = pch[1];
                         char pch2 = pch[2];
                         char pch3 = pch[3];
 
                         if ((pch0 | pch1 | pch2 | pch3) >= 128)
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, new string(pch, 0, 4), index + (int)(pch - _chars))));
+                            throw new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, new string(pch, 0, 4), index + (int)(pch - _chars)));
 
                         // xx765432 xx107654 xx321076 xx543210
                         // 76543210 76543210 76543210
@@ -89,7 +87,7 @@ namespace System.Text
                         int v4 = _char2val[pch3];
 
                         if (!IsValidLeadBytes(v1, v2, v3, v4) || !IsValidTailBytes(v3, v4))
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, new string(pch, 0, 4), index + (int)(pch - _chars))));
+                            throw new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, new string(pch, 0, 4), index + (int)(pch - _chars)));
 
                         int byteCount = (v4 != 64 ? 3 : (v3 != 64 ? 2 : 1));
                         totalCount += byteCount;
@@ -103,26 +101,23 @@ namespace System.Text
         public override unsafe int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
         {
             ArgumentNullException.ThrowIfNull(chars);
-            if (charIndex < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charIndex), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(charIndex);
             if (charIndex > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
+                throw new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
 
-            if (charCount < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charCount), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(charCount);
             if (charCount > chars.Length - charIndex)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - charIndex)));
+                throw new ArgumentOutOfRangeException(nameof(charCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - charIndex));
 
             ArgumentNullException.ThrowIfNull(bytes);
-            if (byteIndex < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteIndex), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(byteIndex);
             if (byteIndex > bytes.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length)));
+                throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length));
 
             if (charCount == 0)
                 return 0;
             if ((charCount % 4) != 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Length, charCount.ToString())));
+                throw new FormatException(SR.Format(SR.XmlInvalidBase64Length, charCount.ToString()));
             fixed (byte* _char2val = &Char2val[0])
             {
                 fixed (char* _chars = &chars[charIndex])
@@ -135,14 +130,14 @@ namespace System.Text
                         byte* pbMax = _bytes + bytes.Length - byteIndex;
                         while (pch < pchMax)
                         {
-                            DiagnosticUtility.DebugAssert(pch + 4 <= pchMax, "");
+                            Debug.Assert(pch + 4 <= pchMax);
                             char pch0 = pch[0];
                             char pch1 = pch[1];
                             char pch2 = pch[2];
                             char pch3 = pch[3];
 
                             if ((pch0 | pch1 | pch2 | pch3) >= 128)
-                                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, new string(pch, 0, 4), charIndex + (int)(pch - _chars))));
+                                throw new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, new string(pch, 0, 4), charIndex + (int)(pch - _chars)));
                             // xx765432 xx107654 xx321076 xx543210
                             // 76543210 76543210 76543210
 
@@ -152,11 +147,11 @@ namespace System.Text
                             int v4 = _char2val[pch3];
 
                             if (!IsValidLeadBytes(v1, v2, v3, v4) || !IsValidTailBytes(v3, v4))
-                                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, new string(pch, 0, 4), charIndex + (int)(pch - _chars))));
+                                throw new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, new string(pch, 0, 4), charIndex + (int)(pch - _chars)));
 
                             int byteCount = (v4 != 64 ? 3 : (v3 != 64 ? 2 : 1));
                             if (pb + byteCount > pbMax)
-                                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlArrayTooSmall, nameof(bytes)));
+                                throw new ArgumentException(SR.XmlArrayTooSmall, nameof(bytes));
 
                             pb[0] = (byte)((v1 << 2) | ((v2 >> 4) & 0x03));
                             if (byteCount > 1)
@@ -179,26 +174,23 @@ namespace System.Text
         public unsafe int GetBytes(byte[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
         {
             ArgumentNullException.ThrowIfNull(chars);
-            if (charIndex < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charIndex), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(charIndex);
             if (charIndex > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
+                throw new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
 
-            if (charCount < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charCount), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(charCount);
             if (charCount > chars.Length - charIndex)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - charIndex)));
+                throw new ArgumentOutOfRangeException(nameof(charCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - charIndex));
 
             ArgumentNullException.ThrowIfNull(bytes);
-            if (byteIndex < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteIndex), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(byteIndex);
             if (byteIndex > bytes.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length)));
+                throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length));
 
             if (charCount == 0)
                 return 0;
             if ((charCount % 4) != 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Length, charCount.ToString())));
+                throw new FormatException(SR.Format(SR.XmlInvalidBase64Length, charCount.ToString()));
             fixed (byte* _char2val = &Char2val[0])
             {
                 fixed (byte* _chars = &chars[charIndex])
@@ -211,13 +203,13 @@ namespace System.Text
                         byte* pbMax = _bytes + bytes.Length - byteIndex;
                         while (pch < pchMax)
                         {
-                            DiagnosticUtility.DebugAssert(pch + 4 <= pchMax, "");
+                            Debug.Assert(pch + 4 <= pchMax);
                             byte pch0 = pch[0];
                             byte pch1 = pch[1];
                             byte pch2 = pch[2];
                             byte pch3 = pch[3];
                             if ((pch0 | pch1 | pch2 | pch3) >= 128)
-                                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, "?", charIndex + (int)(pch - _chars))));
+                                throw new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, "?", charIndex + (int)(pch - _chars)));
                             // xx765432 xx107654 xx321076 xx543210
                             // 76543210 76543210 76543210
 
@@ -227,11 +219,11 @@ namespace System.Text
                             int v4 = _char2val[pch3];
 
                             if (!IsValidLeadBytes(v1, v2, v3, v4) || !IsValidTailBytes(v3, v4))
-                                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, "?", charIndex + (int)(pch - _chars))));
+                                throw new FormatException(SR.Format(SR.XmlInvalidBase64Sequence, "?", charIndex + (int)(pch - _chars)));
 
                             int byteCount = (v4 != 64 ? 3 : (v3 != 64 ? 2 : 1));
                             if (pb + byteCount > pbMax)
-                                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlArrayTooSmall, nameof(bytes)));
+                                throw new ArgumentException(SR.XmlArrayTooSmall, nameof(bytes));
 
                             pb[0] = (byte)((v1 << 2) | ((v2 >> 4) & 0x03));
                             if (byteCount > 1)
@@ -253,7 +245,7 @@ namespace System.Text
         public override int GetMaxCharCount(int byteCount)
         {
             if (byteCount < 0 || byteCount > int.MaxValue / 4 * 3 - 2)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteCount), SR.Format(SR.ValueMustBeInRange, 0, int.MaxValue / 4 * 3 - 2)));
+                throw new ArgumentOutOfRangeException(nameof(byteCount), SR.Format(SR.ValueMustBeInRange, 0, int.MaxValue / 4 * 3 - 2));
             return ((byteCount + 2) / 3) * 4;
         }
 
@@ -265,23 +257,20 @@ namespace System.Text
         public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
         {
             ArgumentNullException.ThrowIfNull(bytes);
-            if (byteIndex < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteIndex), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(byteIndex);
             if (byteIndex > bytes.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length)));
-            if (byteCount < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteCount), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(byteCount);
             if (byteCount > bytes.Length - byteIndex)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, bytes.Length - byteIndex)));
+                throw new ArgumentOutOfRangeException(nameof(byteCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, bytes.Length - byteIndex));
 
             int charCount = GetCharCount(bytes, byteIndex, byteCount);
             ArgumentNullException.ThrowIfNull(chars);
-            if (charIndex < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charIndex), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(charIndex);
             if (charIndex > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
+                throw new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
             if (charCount < 0 || charCount > chars.Length - charIndex)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlArrayTooSmall, nameof(chars)));
+                throw new ArgumentException(SR.XmlArrayTooSmall, nameof(chars));
 
             // We've computed exactly how many chars there are and verified that
             // there's enough space in the char buffer, so we can proceed without
@@ -339,7 +328,7 @@ namespace System.Text
                             else
                             {
                                 // 0 trailing bytes
-                                DiagnosticUtility.DebugAssert(pb - pbMax == 3, "");
+                                Debug.Assert(pb - pbMax == 3);
                             }
                         }
                     }
@@ -352,24 +341,21 @@ namespace System.Text
         public unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount, byte[] chars, int charIndex)
         {
             ArgumentNullException.ThrowIfNull(bytes);
-            if (byteIndex < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteIndex), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(byteIndex);
             if (byteIndex > bytes.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length)));
-            if (byteCount < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteCount), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(byteCount);
             if (byteCount > bytes.Length - byteIndex)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(byteCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, bytes.Length - byteIndex)));
+                throw new ArgumentOutOfRangeException(nameof(byteCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, bytes.Length - byteIndex));
 
             int charCount = GetCharCount(bytes, byteIndex, byteCount);
             ArgumentNullException.ThrowIfNull(chars);
-            if (charIndex < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charIndex), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(charIndex);
             if (charIndex > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
+                throw new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
 
             if (charCount < 0 || charCount > chars.Length - charIndex)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlArrayTooSmall, nameof(chars)));
+                throw new ArgumentException(SR.XmlArrayTooSmall, nameof(chars));
 
             // We've computed exactly how many chars there are and verified that
             // there's enough space in the char buffer, so we can proceed without
@@ -427,7 +413,7 @@ namespace System.Text
                             else
                             {
                                 // 0 trailing bytes
-                                DiagnosticUtility.DebugAssert(pb - pbMax == 3, "");
+                                Debug.Assert(pb - pbMax == 3);
                             }
                         }
                     }
index 7c2bdb7490b2dd2db77ab854283f96210fdd7924..810e958a341271dde8a25e0836dc4de447c6a72e 100644 (file)
@@ -10,8 +10,7 @@ namespace System.Text
     {
         public override int GetMaxByteCount(int charCount)
         {
-            if (charCount < 0)
-                throw new ArgumentOutOfRangeException(nameof(charCount), SR.ValueMustBeNonNegative);
+            ArgumentOutOfRangeException.ThrowIfNegative(charCount);
             if ((charCount % 2) != 0)
                 throw new FormatException(SR.Format(SR.XmlInvalidBinHexLength, charCount.ToString()));
             return charCount / 2;
@@ -25,17 +24,14 @@ namespace System.Text
         public override unsafe int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
         {
             ArgumentNullException.ThrowIfNull(chars);
-            if (charIndex < 0)
-                throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ValueMustBeNonNegative);
+            ArgumentOutOfRangeException.ThrowIfNegative(charIndex);
             if (charIndex > chars.Length)
                 throw new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
-            if (charCount < 0)
-                throw new ArgumentOutOfRangeException(nameof(charCount), SR.ValueMustBeNonNegative);
+            ArgumentOutOfRangeException.ThrowIfNegative(charCount);
             if (charCount > chars.Length - charIndex)
                 throw new ArgumentOutOfRangeException(nameof(charCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - charIndex));
             ArgumentNullException.ThrowIfNull(bytes);
-            if (byteIndex < 0)
-                throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ValueMustBeNonNegative);
+            ArgumentOutOfRangeException.ThrowIfNegative(byteIndex);
             if (byteIndex > bytes.Length)
                 throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length));
             int byteCount = GetByteCount(chars, charIndex, charCount);
@@ -67,18 +63,15 @@ namespace System.Text
         public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
         {
             ArgumentNullException.ThrowIfNull(bytes);
-            if (byteIndex < 0)
-                throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.ValueMustBeNonNegative);
+            ArgumentOutOfRangeException.ThrowIfNegative(byteIndex);
             if (byteIndex > bytes.Length)
                 throw new ArgumentOutOfRangeException(nameof(byteIndex), SR.Format(SR.OffsetExceedsBufferSize, bytes.Length));
-            if (byteCount < 0)
-                throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ValueMustBeNonNegative);
+            ArgumentOutOfRangeException.ThrowIfNegative(byteCount);
             if (byteCount > bytes.Length - byteIndex)
                 throw new ArgumentOutOfRangeException(nameof(byteCount), SR.Format(SR.SizeExceedsRemainingBufferSpace, bytes.Length - byteIndex));
             int charCount = GetCharCount(bytes, byteIndex, byteCount);
             ArgumentNullException.ThrowIfNull(chars);
-            if (charIndex < 0)
-                throw new ArgumentOutOfRangeException(nameof(charIndex), SR.ValueMustBeNonNegative);
+            ArgumentOutOfRangeException.ThrowIfNegative(charIndex);
             if (charIndex > chars.Length)
                 throw new ArgumentOutOfRangeException(nameof(charIndex), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
             if (charCount < 0 || charCount > chars.Length - charIndex)
index f95a419064989b242248d57b49db9245e34afc13..20fd84abdb28e397e20a314b3b51f0345b91ab10 100644 (file)
@@ -23,7 +23,7 @@ namespace System.Text
         public SurrogateChar(int ch)
         {
             if (ch < MinValue || ch > MaxValue)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlInvalidSurrogate, ch.ToString("X", CultureInfo.InvariantCulture)), nameof(ch)));
+                throw new ArgumentException(SR.Format(SR.XmlInvalidSurrogate, ch.ToString("X", CultureInfo.InvariantCulture)), nameof(ch));
 
             const int mask = ((1 << 10) - 1);
 
@@ -34,10 +34,10 @@ namespace System.Text
         public SurrogateChar(char lowChar, char highChar)
         {
             if (lowChar < surLowMin || lowChar > surLowMax)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlInvalidLowSurrogate, ((int)lowChar).ToString("X", CultureInfo.InvariantCulture)), nameof(lowChar)));
+                throw new ArgumentException(SR.Format(SR.XmlInvalidLowSurrogate, ((int)lowChar).ToString("X", CultureInfo.InvariantCulture)), nameof(lowChar));
 
             if (highChar < surHighMin || highChar > surHighMax)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlInvalidHighSurrogate, ((int)highChar).ToString("X", CultureInfo.InvariantCulture)), nameof(highChar)));
+                throw new ArgumentException(SR.Format(SR.XmlInvalidHighSurrogate, ((int)highChar).ToString("X", CultureInfo.InvariantCulture)), nameof(highChar));
 
             _lowChar = lowChar;
             _highChar = highChar;
index b15f29beb5237993694ae7314545be300a990665..297df4bae42d37d4497548303909108d033a2da5 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Xml
 
         public void SetValue(PrefixHandleType type)
         {
-            DiagnosticUtility.DebugAssert(type != PrefixHandleType.Buffer, "");
+            Debug.Assert(type != PrefixHandleType.Buffer);
             _type = type;
         }
 
@@ -116,19 +116,19 @@ namespace System.Xml
 
         public static string GetString(PrefixHandleType type)
         {
-            DiagnosticUtility.DebugAssert(type != PrefixHandleType.Buffer, "");
+            Debug.Assert(type != PrefixHandleType.Buffer);
             return s_prefixStrings[(int)type];
         }
 
         public static PrefixHandleType GetAlphaPrefix(int index)
         {
-            DiagnosticUtility.DebugAssert(index >= 0 && index < 26, "");
+            Debug.Assert(index >= 0 && index < 26);
             return (PrefixHandleType)(PrefixHandleType.A + index);
         }
 
         public static byte[] GetString(PrefixHandleType type, out int offset, out int length)
         {
-            DiagnosticUtility.DebugAssert(type != PrefixHandleType.Buffer, "");
+            Debug.Assert(type != PrefixHandleType.Buffer);
             if (type == PrefixHandleType.Empty)
             {
                 offset = 0;
index 50dce6014220d3cc1e8c7eedd9c12bc5ba78064b..889a39588d383aeaee5276eed105768c6fc49924 100644 (file)
@@ -100,7 +100,7 @@ namespace System.Xml
 
         public void ToPrefixHandle(PrefixHandle prefix)
         {
-            DiagnosticUtility.DebugAssert(_type == StringHandleType.UTF8, "");
+            Debug.Assert(_type == StringHandleType.UTF8);
             prefix.SetValue(_offset, _length);
         }
 
@@ -114,7 +114,7 @@ namespace System.Xml
             if (type == StringHandleType.ConstString)
                 return nameTable.Add(s_constStrings[_key]);
             // If none of the above, must be StringHandleType.EscapedUTF8
-            DiagnosticUtility.DebugAssert(type == StringHandleType.EscapedUTF8, "Should be EscapedUTF8");
+            Debug.Assert(type == StringHandleType.EscapedUTF8, "Should be EscapedUTF8");
             return _bufferReader.GetEscapedString(_offset, _length, nameTable);
         }
 
@@ -128,7 +128,7 @@ namespace System.Xml
             if (type == StringHandleType.ConstString)
                 return s_constStrings[_key];
             // If none of the above, must be StringHandleType.EscapedUTF8
-            DiagnosticUtility.DebugAssert(type == StringHandleType.EscapedUTF8, "Should be EscapedUTF8");
+            Debug.Assert(type == StringHandleType.EscapedUTF8, "Should be EscapedUTF8");
             return _bufferReader.GetEscapedString(_offset, _length);
         }
 
@@ -157,7 +157,7 @@ namespace System.Xml
             }
             else
             {
-                DiagnosticUtility.DebugAssert(type == StringHandleType.EscapedUTF8, "");
+                Debug.Assert(type == StringHandleType.EscapedUTF8);
                 byte[] buffer = XmlConverter.ToBytes(_bufferReader.GetEscapedString(_offset, _length));
                 offset = 0;
                 length = buffer.Length;
@@ -194,7 +194,7 @@ namespace System.Xml
                 return _bufferReader.Equals2(_key, key2, bufferReader2);
             if (type == StringHandleType.UTF8)
                 return _bufferReader.Equals2(_offset, _length, bufferReader2.GetDictionaryString(key2).Value);
-            DiagnosticUtility.DebugAssert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
+            Debug.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString);
             return GetString() == _bufferReader.GetDictionaryString(key2).Value;
         }
 
@@ -205,7 +205,7 @@ namespace System.Xml
                 return _bufferReader.Equals2(_key, xmlString2);
             if (type == StringHandleType.UTF8)
                 return _bufferReader.Equals2(_offset, _length, xmlString2.ToUTF8());
-            DiagnosticUtility.DebugAssert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
+            Debug.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString);
             return GetString() == xmlString2.Value;
         }
 
@@ -216,7 +216,7 @@ namespace System.Xml
                 return _bufferReader.GetDictionaryString(_key).Value == s2;
             if (type == StringHandleType.UTF8)
                 return _bufferReader.Equals2(_offset, _length, s2);
-            DiagnosticUtility.DebugAssert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
+            Debug.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString);
             return GetString() == s2;
         }
 
@@ -227,7 +227,7 @@ namespace System.Xml
                 return bufferReader2.Equals2(offset2, length2, _bufferReader.GetDictionaryString(_key).Value);
             if (type == StringHandleType.UTF8)
                 return _bufferReader.Equals2(_offset, _length, bufferReader2, offset2, length2);
-            DiagnosticUtility.DebugAssert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
+            Debug.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString);
             return GetString() == _bufferReader.GetString(offset2, length2);
         }
 
@@ -240,7 +240,7 @@ namespace System.Xml
                 return Equals2(other._key, other._bufferReader);
             if (type == StringHandleType.UTF8)
                 return Equals2(other._offset, other._length, other._bufferReader);
-            DiagnosticUtility.DebugAssert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString, "");
+            Debug.Assert(type == StringHandleType.EscapedUTF8 || type == StringHandleType.ConstString);
             return Equals2(other.GetString());
         }
 
index dbda45dc02d7a913f58dd16289825cd1bd684205..4a3a6c1b4e4e42dd78b49703235642a5b6661ac8 100644 (file)
@@ -66,12 +66,11 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(guid);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > guid.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, guid.Length)));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, guid.Length));
             if (guidLength > guid.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlArrayTooSmallInput, guidLength), nameof(guid)));
+                throw new ArgumentException(SR.Format(SR.XmlArrayTooSmallInput, guidLength), nameof(guid));
             fixed (byte* pb = &guid[offset])
             {
                 _idLow = UnsafeGetInt64(pb);
@@ -84,7 +83,7 @@ namespace System.Xml
             ArgumentNullException.ThrowIfNull(value);
 
             if (value.Length == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.XmlInvalidUniqueId));
+                throw new FormatException(SR.XmlInvalidUniqueId);
             fixed (char* pch = value)
             {
                 UnsafeParse(pch, value.Length);
@@ -96,16 +95,14 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(chars);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > chars.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset));
             if (count == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.XmlInvalidUniqueId));
+                throw new FormatException(SR.XmlInvalidUniqueId);
             fixed (char* pch = &chars[offset])
             {
                 UnsafeParse(pch, count);
@@ -204,13 +201,12 @@ namespace System.Xml
 
             int count = CharArrayLength;
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
 
             if (count > chars.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(chars), SR.Format(SR.XmlArrayTooSmallOutput, count)));
+                throw new ArgumentOutOfRangeException(nameof(chars), SR.Format(SR.XmlArrayTooSmallOutput, count));
 
             ToSpan(chars.AsSpan(offset, count));
             return count;
@@ -285,13 +281,12 @@ namespace System.Xml
 
             ArgumentNullException.ThrowIfNull(buffer);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > buffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length)));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length));
 
             if (guidLength > buffer.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(buffer), SR.Format(SR.XmlArrayTooSmallOutput, guidLength)));
+                throw new ArgumentOutOfRangeException(nameof(buffer), SR.Format(SR.XmlArrayTooSmallOutput, guidLength));
 
             fixed (byte* pb = &buffer[offset])
             {
index 171a5e0589d69fbf4be7ca30418be13bb6645d8c..98f7229c0759af69e0512a377f50351fea58c00a 100644 (file)
@@ -4,6 +4,7 @@
 using System.Runtime.Serialization;
 using System.Text;
 using System.Diagnostics.CodeAnalysis;
+using System.Diagnostics;
 
 namespace System.Xml
 {
@@ -196,7 +197,7 @@ namespace System.Xml
                 case ValueHandleType.TimeSpan:
                     return typeof(TimeSpan);
                 default:
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+                    throw new InvalidOperationException();
             }
         }
 
@@ -459,7 +460,7 @@ namespace System.Xml
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(exception.Message, exception.InnerException));
+                throw new XmlException(exception.Message, exception.InnerException);
             }
         }
 
@@ -507,7 +508,7 @@ namespace System.Xml
                     return GetDictionaryString().Value;
                 case ValueHandleType.Base64:
                     byte[] bytes = ToByteArray();
-                    DiagnosticUtility.DebugAssert(bytes != null, "");
+                    Debug.Assert(bytes != null);
                     return DataContractSerializer.Base64Encoding.GetString(bytes, 0, bytes.Length);
                 case ValueHandleType.List:
                     return XmlConverter.ToString(ToList());
@@ -522,7 +523,7 @@ namespace System.Xml
                 case ValueHandleType.ConstString:
                     return s_constStrings[_offset];
                 default:
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+                    throw new InvalidOperationException();
             }
         }
 
@@ -538,7 +539,7 @@ namespace System.Xml
             byte[] buffer = _bufferReader.Buffer;
             for (int i = 0; i < _length; ++i)
             {
-                DiagnosticUtility.DebugAssert(str[i] < 128, "");
+                Debug.Assert(str[i] < 128);
                 byte ch = buffer[i + _offset];
                 if (ch == str[i])
                     continue;
@@ -651,7 +652,7 @@ namespace System.Xml
                 case ValueHandleType.TimeSpan:
                     return ToTimeSpan();
                 default:
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+                    throw new InvalidOperationException();
             }
         }
 
@@ -686,7 +687,7 @@ namespace System.Xml
 
         public bool TryReadChars(char[] chars, int offset, int count, out int actual)
         {
-            DiagnosticUtility.DebugAssert(offset + count <= chars.Length, string.Format("offset '{0}' + count '{1}' MUST BE <= chars.Length '{2}'", offset, count, chars.Length));
+            Debug.Assert(offset + count <= chars.Length, string.Format("offset '{0}' + count '{1}' MUST BE <= chars.Length '{2}'", offset, count, chars.Length));
 
             if (_type == ValueHandleType.Unicode)
                 return TryReadUnicodeChars(chars, offset, count, out actual);
@@ -769,7 +770,7 @@ namespace System.Xml
                             }
                             else
                             {
-                                DiagnosticUtility.DebugAssert(byteOffset + actualByteCount < bytes.Length,
+                                Debug.Assert(byteOffset + actualByteCount < bytes.Length,
                                     $"byteOffset {byteOffset} + actualByteCount {actualByteCount} MUST BE < bytes.Length {bytes.Length}");
 
                                 // Request a few more bytes to get at least one character
@@ -784,7 +785,7 @@ namespace System.Xml
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(bytes, byteOffset, byteCount, exception));
+                    throw XmlExceptionHelper.CreateEncodingException(bytes, byteOffset, byteCount, exception);
                 }
 
                 // Advance
@@ -841,7 +842,7 @@ namespace System.Xml
         }
         private string GetCharsText()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.UTF8, "");
+            Debug.Assert(_type == ValueHandleType.UTF8);
             if (_length == 1 && _bufferReader.GetByte(_offset) == '1')
                 return "1";
             return _bufferReader.GetString(_offset, _length);
@@ -849,13 +850,13 @@ namespace System.Xml
 
         private string GetUnicodeCharsText()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Unicode, "");
+            Debug.Assert(_type == ValueHandleType.Unicode);
             return _bufferReader.GetUnicodeString(_offset, _length);
         }
 
         private string GetEscapedCharsText()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.EscapedUTF8, "");
+            Debug.Assert(_type == ValueHandleType.EscapedUTF8);
             return _bufferReader.GetEscapedString(_offset, _length);
         }
 
@@ -874,85 +875,85 @@ namespace System.Xml
 
         private int GetChar()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Char, "");
+            Debug.Assert(_type == ValueHandleType.Char);
             return _offset;
         }
 
         private int GetInt8()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Int8, "");
+            Debug.Assert(_type == ValueHandleType.Int8);
             return _bufferReader.GetInt8(_offset);
         }
 
         private int GetInt16()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Int16, "");
+            Debug.Assert(_type == ValueHandleType.Int16);
             return _bufferReader.GetInt16(_offset);
         }
 
         private int GetInt32()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Int32, "");
+            Debug.Assert(_type == ValueHandleType.Int32);
             return _bufferReader.GetInt32(_offset);
         }
 
         private long GetInt64()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Int64 || _type == ValueHandleType.TimeSpan || _type == ValueHandleType.DateTime, "");
+            Debug.Assert(_type == ValueHandleType.Int64 || _type == ValueHandleType.TimeSpan || _type == ValueHandleType.DateTime);
             return _bufferReader.GetInt64(_offset);
         }
 
         private ulong GetUInt64()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.UInt64, "");
+            Debug.Assert(_type == ValueHandleType.UInt64);
             return _bufferReader.GetUInt64(_offset);
         }
 
         private float GetSingle()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Single, "");
+            Debug.Assert(_type == ValueHandleType.Single);
             return _bufferReader.GetSingle(_offset);
         }
 
         private double GetDouble()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Double, "");
+            Debug.Assert(_type == ValueHandleType.Double);
             return _bufferReader.GetDouble(_offset);
         }
 
         private decimal GetDecimal()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Decimal, "");
+            Debug.Assert(_type == ValueHandleType.Decimal);
             return _bufferReader.GetDecimal(_offset);
         }
 
         private UniqueId GetUniqueId()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.UniqueId, "");
+            Debug.Assert(_type == ValueHandleType.UniqueId);
             return _bufferReader.GetUniqueId(_offset);
         }
 
         private Guid GetGuid()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Guid, "");
+            Debug.Assert(_type == ValueHandleType.Guid);
             return _bufferReader.GetGuid(_offset);
         }
 
         private void GetBase64(byte[] buffer, int offset, int count)
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Base64, "");
+            Debug.Assert(_type == ValueHandleType.Base64);
             _bufferReader.GetBase64(_offset, buffer, offset, count);
         }
 
         private XmlDictionaryString GetDictionaryString()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.Dictionary, "");
+            Debug.Assert(_type == ValueHandleType.Dictionary);
             return _bufferReader.GetDictionaryString(_offset);
         }
 
         private string GetQNameDictionaryText()
         {
-            DiagnosticUtility.DebugAssert(_type == ValueHandleType.QName, "");
+            Debug.Assert(_type == ValueHandleType.QName);
             return string.Concat(PrefixHandle.GetString(PrefixHandle.GetAlphaPrefix(_length)), ":", _bufferReader.GetDictionaryString(_offset));
         }
     }
index 3291da8d4d15a5155fbf2e87927da9ff3e5644ca..d3f75f8d482d31d6821123919aa043e8f7fca505 100644 (file)
@@ -499,11 +499,10 @@ namespace System.Xml
         private XmlAttributeNode GetAttributeNode(int index)
         {
             if (!_node.CanGetAttribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(index), SR.XmlElementAttributes));
-            if (index < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(index), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(index), SR.XmlElementAttributes);
+            ArgumentOutOfRangeException.ThrowIfNegative(index);
             if (index >= _attributeCount)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(index), SR.Format(SR.OffsetExceedsBufferSize, _attributeCount)));
+                throw new ArgumentOutOfRangeException(nameof(index), SR.Format(SR.OffsetExceedsBufferSize, _attributeCount));
             return _attributeNodes![index];
         }
 
@@ -659,7 +658,7 @@ namespace System.Xml
                     }
                     else
                     {
-                        DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+                        Debug.Assert(qnameType == QNameType.Xmlns);
                         if (_node.Namespace.Prefix.IsEmpty)
                             _localName = xmlns;
                         else
@@ -747,7 +746,7 @@ namespace System.Xml
                         }
                         else
                         {
-                            DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+                            Debug.Assert(qnameType == QNameType.Xmlns);
                             for (int j = i + 1; j < attributeCount; j++)
                             {
                                 XmlAttributeNode attributeNode2 = attributeNodes[j];
@@ -890,7 +889,7 @@ namespace System.Xml
                     }
                     else
                     {
-                        DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+                        Debug.Assert(qnameType == QNameType.Xmlns);
                         _ns = xmlnsNamespace;
                     }
                 }
@@ -1057,7 +1056,7 @@ namespace System.Xml
                     {
                         string value = localNames[i];
                         if (value == null)
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull($"localNames[{i}]");
+                            throw new ArgumentNullException($"localNames[{i}]");
                         if (localName == value)
                         {
                             return i;
@@ -1066,13 +1065,13 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(qnameType == QNameType.Xmlns);
                     PrefixHandle prefix = _node.Namespace.Prefix;
                     for (int i = 0; i < localNames.Length; i++)
                     {
                         string value = localNames[i];
                         if (value == null)
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull($"localNames[{i}]");
+                            throw new ArgumentNullException($"localNames[{i}]");
                         if (prefix == value)
                         {
                             return i;
@@ -1098,7 +1097,7 @@ namespace System.Xml
                     {
                         XmlDictionaryString value = localNames[i];
                         if (value == null)
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull($"localNames[{i}]");
+                            throw new ArgumentNullException($"localNames[{i}]");
                         if (localName == value)
                         {
                             return i;
@@ -1107,13 +1106,13 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(qnameType == QNameType.Xmlns);
                     PrefixHandle prefix = _node.Namespace.Prefix;
                     for (int i = 0; i < localNames.Length; i++)
                     {
                         XmlDictionaryString value = localNames[i];
                         if (value == null)
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull($"localNames[{i}]");
+                            throw new ArgumentNullException($"localNames[{i}]");
                         if (prefix == value)
                         {
                             return i;
@@ -1128,14 +1127,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(chars);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > chars.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset));
             int actual;
 
             if (_value == null)
@@ -1158,14 +1155,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(buffer);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > buffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset));
             if (count == 0)
                 return 0;
             int actual;
@@ -1256,7 +1251,7 @@ namespace System.Xml
             {
                 int nodeDepth = _node.NodeType == XmlNodeType.Element ? _depth - 1 : _depth;
                 if (nodeDepth == 0)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlEndElementNoOpenNodes));
+                    throw new InvalidOperationException(SR.XmlEndElementNoOpenNodes);
                 // If depth is non-zero, then the document isn't what was expected
                 XmlElementNode elementNode = _elementNodes![nodeDepth];
                 XmlExceptionHelper.ThrowEndElementExpected(this, elementNode.LocalName.GetString(), elementNode.Namespace.Uri.GetString());
@@ -1348,14 +1343,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(buffer);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > buffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset));
             if (count == 0)
                 return 0;
             int actual;
@@ -1386,14 +1379,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(buffer);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > buffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset));
             if (count == 0)
                 return 0;
             return ReadBytes(DataContractSerializer.BinHexEncoding, 1, 2, buffer, offset, Math.Min(count, 512), true);
@@ -1518,7 +1509,7 @@ namespace System.Xml
                     if (newCount == charCount)
                     {
                         // No spaces, so don't try again
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(exception.Message, exception.InnerException));
+                        throw new XmlException(exception.Message, exception.InnerException);
                     }
 
                     charCount = newCount;
@@ -1725,7 +1716,7 @@ namespace System.Xml
 
         public override void ResolveEntity()
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlInvalidOperation));
+            throw new InvalidOperationException(SR.XmlInvalidOperation);
         }
 
         public override void Skip()
@@ -1936,7 +1927,7 @@ namespace System.Xml
             }
             else
             {
-                Fx.Assert(qnameType == QNameType.Xmlns, "");
+                Debug.Assert(qnameType == QNameType.Xmlns);
                 int prefixOffset, prefixLength;
                 byte[] prefixBuffer = attributeNode.Namespace.Prefix.GetString(out prefixOffset, out prefixLength);
                 int nsOffset, nsLength;
@@ -1982,7 +1973,7 @@ namespace System.Xml
                     SignEndElement(writer);
                     break;
                 default:
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+                    throw new InvalidOperationException();
             }
         }
 
@@ -2013,7 +2004,7 @@ namespace System.Xml
         public override void StartCanonicalization(Stream stream, bool includeComments, string[]? inclusivePrefixes)
         {
             if (_signing)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlCanonicalizationStarted));
+                throw new InvalidOperationException(SR.XmlCanonicalizationStarted);
 
             _signingWriter ??= CreateSigningNodeWriter();
 
@@ -2025,7 +2016,7 @@ namespace System.Xml
         public override void EndCanonicalization()
         {
             if (!_signing)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlCanonicalizationNotStarted));
+                throw new InvalidOperationException(SR.XmlCanonicalizationNotStarted);
 
             _signingWriter!.Flush();
             _signingWriter.Close();
@@ -2110,13 +2101,13 @@ namespace System.Xml
 
             public bool HasValue { get { return _hasValue; } }
             public ReadState ReadState { get { return _readState; } }
-            public StringHandle LocalName { get { DiagnosticUtility.DebugAssert(_qnameType != QNameType.Xmlns, ""); return _localName; } }
-            public PrefixHandle Prefix { get { DiagnosticUtility.DebugAssert(_qnameType != QNameType.Xmlns, ""); return _prefix; } }
+            public StringHandle LocalName { get { Debug.Assert(_qnameType != QNameType.Xmlns); return _localName; } }
+            public PrefixHandle Prefix { get { Debug.Assert(_qnameType != QNameType.Xmlns); return _prefix; } }
             public bool CanGetAttribute { get { return _canGetAttribute; } }
             public bool CanMoveToElement { get { return _canMoveToElement; } }
             public XmlAttributeTextNode? AttributeText { get { return _attributeTextNode; } }
             public bool SkipValue { get { return _skipValue; } }
-            public ValueHandle Value { get { DiagnosticUtility.DebugAssert(_qnameType != QNameType.Xmlns, ""); return _value; } }
+            public ValueHandle Value { get { Debug.Assert(_qnameType != QNameType.Xmlns); return _value; } }
             public int DepthDelta { get { return _depthDelta; } }
             public bool HasContent { get { return _hasContent; } }
 
@@ -2212,7 +2203,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     return this.Namespace.Prefix == localName;
                 }
             }
@@ -2225,7 +2216,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     return this.Namespace.Prefix == localName;
                 }
             }
@@ -2238,7 +2229,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     return ns == xmlnsNamespace;
                 }
             }
@@ -2251,7 +2242,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     return ns.Value == xmlnsNamespace;
                 }
             }
@@ -2264,7 +2255,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     return this.Namespace.Prefix == localName && ns == xmlnsNamespace;
                 }
             }
@@ -2277,7 +2268,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     return this.Namespace.Prefix == localName && ns.Value == xmlnsNamespace;
                 }
             }
@@ -2290,7 +2281,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     return prefix == xmlns && this.Namespace.Prefix == localName;
                 }
             }
@@ -2303,7 +2294,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     localName = null;
                     return false;
                 }
@@ -2317,7 +2308,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     ns = null;
                     return false;
                 }
@@ -2331,7 +2322,7 @@ namespace System.Xml
                 }
                 else
                 {
-                    DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                    Debug.Assert(_qnameType == QNameType.Xmlns);
                     value = null;
                     return false;
                 }
@@ -2346,7 +2337,7 @@ namespace System.Xml
                     }
                     else
                     {
-                        DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+                        Debug.Assert(_qnameType == QNameType.Xmlns);
                         return Namespace.Uri.GetString();
                     }
                 }
@@ -2687,7 +2678,7 @@ namespace System.Xml
                     }
                     else
                     {
-                        DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+                        Debug.Assert(qnameType == QNameType.Xmlns);
                         i = attribute1.Namespace.Prefix.CompareTo(attribute2.Namespace.Prefix);
                     }
                 }
@@ -3073,7 +3064,7 @@ namespace System.Xml
 
             public bool IsUri(string s)
             {
-                DiagnosticUtility.DebugAssert(s != null, "");
+                Debug.Assert(s != null);
                 if (object.ReferenceEquals(s, _uriString))
                     return true;
                 if (_uri == s)
index 5ced565e20c39719797cb670c669bee3039dc059..ff1572fcd7c6014e8976cbc729ca4275b9153e50 100644 (file)
@@ -117,7 +117,7 @@ namespace System.Xml
         [DoesNotReturn]
         protected static void ThrowClosed()
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlWriterClosed));
+            throw new InvalidOperationException(SR.XmlWriterClosed);
         }
 
         public override string? XmlLang
@@ -152,7 +152,7 @@ namespace System.Xml
             ArgumentNullException.ThrowIfNull(ns);
 
             if (_writeState != WriteState.Element)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteXmlnsAttribute", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteXmlnsAttribute", WriteState.ToString()));
 
             if (prefix == null)
             {
@@ -176,7 +176,7 @@ namespace System.Xml
             ArgumentNullException.ThrowIfNull(ns);
 
             if (_writeState != WriteState.Element)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteXmlnsAttribute", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteXmlnsAttribute", WriteState.ToString()));
 
             if (prefix == null)
             {
@@ -201,10 +201,10 @@ namespace System.Xml
                 WriteEndAttribute();
 
             if (localName == null || (localName.Length == 0 && prefix != "xmlns"))
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName));
+                throw new ArgumentNullException(nameof(localName));
 
             if (_writeState != WriteState.Element)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartAttribute", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartAttribute", WriteState.ToString()));
 
             if (prefix == null)
             {
@@ -228,7 +228,7 @@ namespace System.Xml
             if (prefix == "xml")
             {
                 if (ns != null && ns != xmlNamespace)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlPrefixBoundToNamespace, "xml", xmlNamespace, ns), nameof(ns)));
+                    throw new ArgumentException(SR.Format(SR.XmlPrefixBoundToNamespace, "xml", xmlNamespace, ns), nameof(ns));
                 _isXmlAttribute = true;
                 _attributeValue = string.Empty;
                 _attributeLocalName = localName;
@@ -236,7 +236,7 @@ namespace System.Xml
             else if (prefix == "xmlns")
             {
                 if (ns != null && ns != xmlnsNamespace)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlPrefixBoundToNamespace, "xmlns", xmlnsNamespace, ns), nameof(ns)));
+                    throw new ArgumentException(SR.Format(SR.XmlPrefixBoundToNamespace, "xmlns", xmlnsNamespace, ns), nameof(ns));
                 _isXmlnsAttribute = true;
                 _attributeValue = string.Empty;
                 _attributeLocalName = localName;
@@ -250,14 +250,14 @@ namespace System.Xml
                     ns = _nsMgr.LookupNamespace(prefix);
 
                     if (ns == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlUndefinedPrefix, prefix), nameof(prefix)));
+                        throw new ArgumentException(SR.Format(SR.XmlUndefinedPrefix, prefix), nameof(prefix));
                 }
             }
             else if (ns.Length == 0)
             {
                 // An empty namespace means no namespace; prefix must be empty
                 if (prefix.Length != 0)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlEmptyNamespaceRequiresNullPrefix, nameof(prefix)));
+                    throw new ArgumentException(SR.XmlEmptyNamespaceRequiresNullPrefix, nameof(prefix));
             }
             else if (prefix.Length == 0)
             {
@@ -269,9 +269,9 @@ namespace System.Xml
                 {
                     // Watch for special values
                     if (ns.Length == xmlnsNamespace.Length && ns == xmlnsNamespace)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlSpecificBindingNamespace, "xmlns", ns)));
+                        throw new ArgumentException(SR.Format(SR.XmlSpecificBindingNamespace, "xmlns", ns));
                     if (ns.Length == xmlNamespace.Length && ns == xmlNamespace)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlSpecificBindingNamespace, "xml", ns)));
+                        throw new ArgumentException(SR.Format(SR.XmlSpecificBindingNamespace, "xml", ns));
 
                     tempPrefix = GeneratePrefix(ns, xNs);
                 }
@@ -308,7 +308,7 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_writeState != WriteState.Attribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteEndAttribute", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteEndAttribute", WriteState.ToString()));
 
             FlushBase64();
             try
@@ -331,7 +331,7 @@ namespace System.Xml
                         }
                         else
                         {
-                            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlInvalidXmlSpace, _attributeValue)));
+                            throw new ArgumentException(SR.Format(SR.XmlInvalidXmlSpace, _attributeValue));
                         }
                     }
                     else
@@ -367,7 +367,7 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_writeState != WriteState.Attribute)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteEndAttribute", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteEndAttribute", WriteState.ToString()));
 
             return WriteEndAttributeAsyncImpl();
         }
@@ -395,7 +395,7 @@ namespace System.Xml
                         }
                         else
                         {
-                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlInvalidXmlSpace, _attributeValue)));
+                            throw new ArgumentException(SR.Format(SR.XmlInvalidXmlSpace, _attributeValue));
                         }
                     }
                     else
@@ -431,7 +431,7 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_writeState == WriteState.Attribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteComment", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteComment", WriteState.ToString()));
 
             if (text == null)
             {
@@ -439,7 +439,7 @@ namespace System.Xml
             }
             else if (text.Contains("--") || text.EndsWith('-'))
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlInvalidCommentChars, nameof(text)));
+                throw new ArgumentException(SR.XmlInvalidCommentChars, nameof(text));
             }
 
             StartComment();
@@ -457,7 +457,7 @@ namespace System.Xml
                 WriteEndAttribute();
 
             if (_writeState != WriteState.Element && _writeState != WriteState.Content)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteFullEndElement", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteFullEndElement", WriteState.ToString()));
 
             AutoComplete(WriteState.Content);
             WriteEndElement();
@@ -469,7 +469,7 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_writeState == WriteState.Attribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteCData", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteCData", WriteState.ToString()));
 
             text ??= string.Empty;
 
@@ -484,7 +484,7 @@ namespace System.Xml
 
         public override void WriteDocType(string name, string? pubid, string? sysid, string? subset)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.XmlMethodNotSupported, "WriteDocType")));
+            throw new NotSupportedException(SR.Format(SR.XmlMethodNotSupported, "WriteDocType"));
         }
 
         private void StartElement(ref string? prefix, string localName, string? ns, XmlDictionaryString? xNs)
@@ -493,12 +493,12 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_documentState == DocumentState.Epilog)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlOnlyOneRoot));
+                throw new InvalidOperationException(SR.XmlOnlyOneRoot);
             ArgumentNullException.ThrowIfNull(localName);
             if (localName.Length == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.InvalidLocalNameEmpty, nameof(localName)));
+                throw new ArgumentException(SR.InvalidLocalNameEmpty, nameof(localName));
             if (_writeState == WriteState.Attribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartElement", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartElement", WriteState.ToString()));
 
             FlushBase64();
             AutoComplete(WriteState.Element);
@@ -510,7 +510,7 @@ namespace System.Xml
                 ns = _nsMgr.LookupNamespace(prefix);
 
                 if (ns == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlUndefinedPrefix, prefix), nameof(prefix)));
+                    throw new ArgumentException(SR.Format(SR.XmlUndefinedPrefix, prefix), nameof(prefix));
             }
             else if (prefix == null)
             {
@@ -536,10 +536,10 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_documentState == DocumentState.Epilog)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlOnlyOneRoot));
+                throw new InvalidOperationException(SR.XmlOnlyOneRoot);
             ArgumentException.ThrowIfNullOrEmpty(localName);
             if (_writeState == WriteState.Attribute)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartElement", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartElement", WriteState.ToString()));
         }
 
         private async Task StartElementAndWriteStartElementAsync(string? prefix, string localName, string? namespaceUri)
@@ -560,7 +560,7 @@ namespace System.Xml
                 ns = _nsMgr.LookupNamespace(prefix);
 
                 if (ns == null)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlUndefinedPrefix, prefix), nameof(prefix)));
+                    throw new ArgumentException(SR.Format(SR.XmlUndefinedPrefix, prefix), nameof(prefix));
             }
             else if (prefix == null)
             {
@@ -606,7 +606,7 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_depth == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidDepth, "WriteEndElement", _depth.ToString(CultureInfo.InvariantCulture))));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidDepth, "WriteEndElement", _depth.ToString(CultureInfo.InvariantCulture)));
 
             if (_writeState == WriteState.Attribute)
                 WriteEndAttribute();
@@ -633,7 +633,7 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_depth == 0)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidDepth, "WriteEndElement", _depth.ToString(CultureInfo.InvariantCulture))));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidDepth, "WriteEndElement", _depth.ToString(CultureInfo.InvariantCulture)));
 
             return WriteEndElementAsyncImpl();
         }
@@ -717,14 +717,14 @@ namespace System.Xml
         {
             FlushElement();
             if (_depth == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlIllegalOutsideRoot));
+                throw new InvalidOperationException(SR.XmlIllegalOutsideRoot);
         }
 
         protected async Task StartContentAsync()
         {
             await FlushElementAsync().ConfigureAwait(false);
             if (_depth == 0)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlIllegalOutsideRoot));
+                throw new InvalidOperationException(SR.XmlIllegalOutsideRoot);
         }
 
         protected void StartContent(char ch)
@@ -751,19 +751,19 @@ namespace System.Xml
         private static void VerifyWhitespace(char ch)
         {
             if (!XmlConverter.IsWhitespace(ch))
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlIllegalOutsideRoot));
+                throw new InvalidOperationException(SR.XmlIllegalOutsideRoot);
         }
 
         private static void VerifyWhitespace(string s)
         {
             if (!XmlConverter.IsWhitespace(s))
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlIllegalOutsideRoot));
+                throw new InvalidOperationException(SR.XmlIllegalOutsideRoot);
         }
 
         private static void VerifyWhitespace(char[] chars, int offset, int count)
         {
             if (!XmlConverter.IsWhitespace(chars.AsSpan(offset, count)))
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlIllegalOutsideRoot));
+                throw new InvalidOperationException(SR.XmlIllegalOutsideRoot);
         }
 
         protected static void EndContent()
@@ -816,7 +816,7 @@ namespace System.Xml
             if (prefix == null)
             {
                 if (_writeState != WriteState.Attribute)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlNamespaceNotFound, namespaceUri), nameof(namespaceUri)));
+                    throw new ArgumentException(SR.Format(SR.XmlNamespaceNotFound, namespaceUri), nameof(namespaceUri));
 
                 prefix = GeneratePrefix(namespaceUri, xNs);
             }
@@ -844,7 +844,7 @@ namespace System.Xml
                 ThrowClosed();
             ArgumentNullException.ThrowIfNull(localName);
             if (localName.Value.Length == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.InvalidLocalNameEmpty, nameof(localName)));
+                throw new ArgumentException(SR.InvalidLocalNameEmpty, nameof(localName));
             namespaceUri ??= XmlDictionaryString.Empty;
             string prefix = GetQualifiedNamePrefix(namespaceUri.Value, namespaceUri);
 
@@ -866,7 +866,7 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_writeState != WriteState.Start)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartDocument", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartDocument", WriteState.ToString()));
 
             _writeState = WriteState.Prolog;
             _documentState = DocumentState.Document;
@@ -888,10 +888,10 @@ namespace System.Xml
                 ThrowClosed();
 
             if (name != "xml")
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlProcessingInstructionNotSupported, nameof(name)));
+                throw new ArgumentException(SR.XmlProcessingInstructionNotSupported, nameof(name));
 
             if (_writeState != WriteState.Start)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlInvalidDeclaration));
+                throw new InvalidOperationException(SR.XmlInvalidDeclaration);
 
             // The only thing the text can legitimately contain is version, encoding, and standalone.
             // We only support version 1.0, we can only write whatever encoding we were supplied,
@@ -918,7 +918,7 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_writeState == WriteState.Start || _writeState == WriteState.Prolog)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlNoRootElement));
+                throw new InvalidOperationException(SR.XmlNoRootElement);
 
             FinishDocument();
             _writeState = WriteState.Start;
@@ -939,7 +939,7 @@ namespace System.Xml
 
         public override void WriteEntityRef(string name)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.XmlMethodNotSupported, "WriteEntityRef")));
+            throw new NotSupportedException(SR.Format(SR.XmlMethodNotSupported, "WriteEntityRef"));
         }
 
         public override void WriteName(string name)
@@ -952,7 +952,7 @@ namespace System.Xml
 
         public override void WriteNmToken(string name)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.Format(SR.XmlMethodNotSupported, "WriteNmToken")));
+            throw new NotSupportedException(SR.Format(SR.XmlMethodNotSupported, "WriteNmToken"));
         }
 
         public override void WriteWhitespace(string? whitespace)
@@ -964,7 +964,7 @@ namespace System.Xml
 
             if (whitespace.AsSpan().IndexOfAnyExcept(" \t\r\n") >= 0)
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlOnlyWhitespace, nameof(whitespace)));
+                throw new ArgumentException(SR.XmlOnlyWhitespace, nameof(whitespace));
             }
 
             WriteString(whitespace);
@@ -1024,13 +1024,10 @@ namespace System.Xml
             ArgumentNullException.ThrowIfNull(chars);
 
             // Not checking upper bound because it will be caught by "count".  This is what XmlTextWriter does.
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
-
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > chars.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset));
 
             if (count > 0)
             {
@@ -1079,13 +1076,10 @@ namespace System.Xml
             ArgumentNullException.ThrowIfNull(chars);
 
             // Not checking upper bound because it will be caught by "count".  This is what XmlTextWriter does.
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
-
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > chars.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset));
 
             if (count > 0)
             {
@@ -1109,7 +1103,7 @@ namespace System.Xml
                 ThrowClosed();
 
             if (ch >= 0xd800 && ch <= 0xdfff)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlMissingLowSurrogate, nameof(ch)));
+                throw new ArgumentException(SR.XmlMissingLowSurrogate, nameof(ch));
 
             if (_attributeValue != null)
                 WriteAttributeText(ch.ToString());
@@ -1231,7 +1225,7 @@ namespace System.Xml
             }
             else if (value.GetType().IsArray)
             {
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlNestedArraysNotSupported, nameof(value)));
+                throw new ArgumentException(SR.XmlNestedArraysNotSupported, nameof(value));
             }
             else
             {
@@ -1446,13 +1440,10 @@ namespace System.Xml
             ArgumentNullException.ThrowIfNull(buffer);
 
             // Not checking upper bound because it will be caught by "count".  This is what XmlTextWriter does.
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
-
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset));
         }
 
         public override void WriteBinHex(byte[] buffer, int offset, int count)
@@ -1598,7 +1589,7 @@ namespace System.Xml
             if (IsClosed)
                 ThrowClosed();
             if (Signing)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlCanonicalizationStarted));
+                throw new InvalidOperationException(SR.XmlCanonicalizationStarted);
             FlushElement();
             _signingWriter ??= CreateSigningNodeWriter();
             _signingWriter.SetOutput(_writer, stream, includeComments, inclusivePrefixes);
@@ -1611,7 +1602,7 @@ namespace System.Xml
             if (IsClosed)
                 ThrowClosed();
             if (!Signing)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlCanonicalizationNotStarted));
+                throw new InvalidOperationException(SR.XmlCanonicalizationNotStarted);
             _signingWriter!.Flush();
             _writer = _signingWriter.NodeWriter;
         }
@@ -1629,7 +1620,7 @@ namespace System.Xml
         public void StartFragment(Stream stream, bool generateSelfContainedTextFragment)
         {
             if (!CanFragment)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+                throw new NotSupportedException();
 
             if (IsClosed)
                 ThrowClosed();
@@ -1637,9 +1628,9 @@ namespace System.Xml
             ArgumentNullException.ThrowIfNull(stream);
 
             if (_oldStream != null || _oldWriter != null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+                throw new InvalidOperationException();
             if (WriteState == WriteState.Attribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "StartFragment", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "StartFragment", WriteState.ToString()));
 
             FlushElement();
             _writer.Flush();
@@ -1689,9 +1680,9 @@ namespace System.Xml
                 ThrowClosed();
 
             if (_oldStream == null && _oldWriter == null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+                throw new InvalidOperationException();
             if (WriteState == WriteState.Attribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "EndFragment", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "EndFragment", WriteState.ToString()));
 
             FlushElement();
             _writer.Flush();
@@ -1718,7 +1709,7 @@ namespace System.Xml
         public void WriteFragment(byte[] buffer, int offset, int count)
         {
             if (!CanFragment)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+                throw new NotSupportedException();
 
             if (IsClosed)
                 ThrowClosed();
@@ -1726,10 +1717,10 @@ namespace System.Xml
             EnsureBufferBounds(buffer, offset, count);
 
             if (WriteState == WriteState.Attribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteFragment", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteFragment", WriteState.ToString()));
 
             if (_writer != _nodeWriter)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+                throw new InvalidOperationException();
 
             FlushElement();
             FlushBase64();
@@ -1824,18 +1815,18 @@ namespace System.Xml
         {
             FlushBase64();
             if (_documentState == DocumentState.Epilog)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlOnlyOneRoot));
+                throw new InvalidOperationException(SR.XmlOnlyOneRoot);
             if (_documentState == DocumentState.Document && count > 1 && _depth == 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlOnlyOneRoot));
+                throw new InvalidOperationException(SR.XmlOnlyOneRoot);
             if (_writeState == WriteState.Attribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartElement", WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidWriteState, "WriteStartElement", WriteState.ToString()));
             AutoComplete(WriteState.Content);
         }
 
         private string GeneratePrefix(string ns, XmlDictionaryString? xNs)
         {
             if (_writeState != WriteState.Element && _writeState != WriteState.Attribute)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.XmlInvalidPrefixState, WriteState.ToString())));
+                throw new InvalidOperationException(SR.Format(SR.XmlInvalidPrefixState, WriteState.ToString()));
 
             string? prefix = _nsMgr.AddNamespace(ns, xNs);
 
@@ -2157,7 +2148,7 @@ namespace System.Xml
                             return;
                         if (prefix == "xmlns" && uri == xmlnsNamespace)
                             return;
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlReservedPrefix, nameof(prefix)));
+                        throw new ArgumentException(SR.XmlReservedPrefix, nameof(prefix));
                     }
                 }
                 Namespace nameSpace;
@@ -2170,16 +2161,16 @@ namespace System.Xml
                     {
                         if (nameSpace.Uri == uri)
                             return;
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlPrefixBoundToNamespace, prefix, nameSpace.Uri, uri), nameof(prefix)));
+                        throw new ArgumentException(SR.Format(SR.XmlPrefixBoundToNamespace, prefix, nameSpace.Uri, uri), nameof(prefix));
                     }
                 }
                 if (prefix.Length != 0 && uri.Length == 0)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.XmlEmptyNamespaceRequiresNullPrefix, nameof(prefix)));
+                    throw new ArgumentException(SR.XmlEmptyNamespaceRequiresNullPrefix, nameof(prefix));
                 if (uri.Length == xmlnsNamespace.Length && uri == xmlnsNamespace)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlSpecificBindingNamespace, "xmlns", uri)));
+                    throw new ArgumentException(SR.Format(SR.XmlSpecificBindingNamespace, "xmlns", uri));
                 // The addressing namespace and the xmlNamespace are the same length, so add a quick check to try to disambiguate
                 if (uri.Length == xmlNamespace.Length && uri[18] == 'X' && uri == xmlNamespace)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlSpecificBindingNamespace, "xml", uri)));
+                    throw new ArgumentException(SR.Format(SR.XmlSpecificBindingNamespace, "xml", uri));
 
                 if (_namespaces!.Length == _nsCount)
                 {
@@ -2380,7 +2371,7 @@ namespace System.Xml
             public void Sign(XmlCanonicalWriter signingWriter)
             {
                 int nsCount = _nsCount;
-                Fx.Assert(nsCount >= 1 && _namespaces![0].Prefix!.Length == 0 && _namespaces[0].Uri!.Length == 0, "");
+                Debug.Assert(nsCount >= 1 && _namespaces![0].Prefix!.Length == 0 && _namespaces[0].Uri!.Length == 0);
                 for (int i = 1; i < nsCount; i++)
                 {
                     Namespace nameSpace = _namespaces[i];
index e6602e6b69e638fa40c4e6e17b433439f7cbf0d8..339f2cdc2e2d78485476b12ae0cf5fff7d12c14f 100644 (file)
@@ -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.Diagnostics.CodeAnalysis;
 using System.IO;
 using System.Runtime.InteropServices;
@@ -44,14 +45,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(buffer);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > buffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset));
             MoveToInitial(quotas, onClose);
             BufferReader.SetBuffer(buffer, offset, count, dictionary, session);
             _buffered = true;
@@ -84,17 +83,7 @@ namespace System.Xml
             base.Close();
             OnXmlDictionaryReaderClose? onClose = _onClose;
             _onClose = null;
-            if (onClose != null)
-            {
-                try
-                {
-                    onClose(this);
-                }
-                catch (Exception e)
-                {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
-                }
-            }
+            onClose?.Invoke(this);
         }
 
         public override string ReadElementContentAsString()
@@ -423,7 +412,7 @@ namespace System.Xml
             }
             else
             {
-                DiagnosticUtility.DebugAssert(_arrayState == ArrayState.Element, "");
+                Debug.Assert(_arrayState == ArrayState.Element);
                 nodeType = _arrayNodeType;
                 _arrayCount--;
                 _arrayState = ArrayState.Content;
@@ -1237,14 +1226,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(array);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > array.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, array.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, array.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > array.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, array.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, array.Length - offset));
         }
 
         private unsafe int ReadArray(bool[] array, int offset, int count)
index 1ddadff2f519c3c1ec573f4e48e431edc6da9db6..a940cb6f35d30c56839b8189b7d8aed5e6af3fb6 100644 (file)
@@ -23,11 +23,11 @@ namespace System.Xml
         public XmlDictionaryString Add(int id, string value)
         {
             if (id < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(id), SR.XmlInvalidID));
+                throw new ArgumentOutOfRangeException(nameof(id), SR.XmlInvalidID);
             ArgumentNullException.ThrowIfNull(value);
             XmlDictionaryString? xmlString;
             if (TryLookup(id, out _))
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlIDDefined));
+                throw new InvalidOperationException(SR.XmlIDDefined);
 
             xmlString = new XmlDictionaryString(this, value, id);
             if (id >= MaxArrayEntries)
index cd2975c3f2c9a0adf7c2e24582425873261286ab..556c38edcdf93ca0dcf4bf4895d7000196f18a34 100644 (file)
@@ -35,7 +35,7 @@ namespace System.Xml
         public XmlBinaryNodeWriter()
         {
             // Sanity check on node values
-            DiagnosticUtility.DebugAssert(XmlBinaryNodeType.MaxAttribute < XmlBinaryNodeType.MinElement &&
+            Debug.Assert(XmlBinaryNodeType.MaxAttribute < XmlBinaryNodeType.MinElement &&
                                           XmlBinaryNodeType.MaxElement < XmlBinaryNodeType.MinText &&
                                           (int)XmlBinaryNodeType.MaxText < 256, "NodeTypes enumeration messed up");
         }
@@ -60,7 +60,7 @@ namespace System.Xml
         private void WroteAttributeValue()
         {
             if (_wroteAttributeValue && !_inList)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlOnlySingleValue));
+                throw new InvalidOperationException(SR.XmlOnlySingleValue);
             _wroteAttributeValue = true;
         }
 
@@ -68,7 +68,7 @@ namespace System.Xml
         {
             if (_inAttribute)
                 WroteAttributeValue();
-            DiagnosticUtility.DebugAssert(nodeType >= XmlBinaryNodeType.MinText && nodeType <= XmlBinaryNodeType.MaxText && ((byte)nodeType & 1) == 0, "Invalid nodeType");
+            Debug.Assert(nodeType >= XmlBinaryNodeType.MinText && nodeType <= XmlBinaryNodeType.MaxText && ((byte)nodeType & 1) == 0, "Invalid nodeType");
             WriteByte((byte)nodeType);
             _textNodeOffset = this.BufferOffset - 1;
         }
@@ -84,7 +84,7 @@ namespace System.Xml
 
         private void WriteTextNodeWithLength(XmlBinaryNodeType nodeType, int length)
         {
-            DiagnosticUtility.DebugAssert(nodeType == XmlBinaryNodeType.Chars8Text || nodeType == XmlBinaryNodeType.Bytes8Text || nodeType == XmlBinaryNodeType.UnicodeChars8Text, "");
+            Debug.Assert(nodeType == XmlBinaryNodeType.Chars8Text || nodeType == XmlBinaryNodeType.Bytes8Text || nodeType == XmlBinaryNodeType.UnicodeChars8Text);
             int offset;
             byte[] buffer = GetTextNodeBuffer(5, out offset);
             if (length < 256)
@@ -224,7 +224,7 @@ namespace System.Xml
             {
                 byte[] buffer = this.StreamBuffer;
                 XmlBinaryNodeType nodeType = (XmlBinaryNodeType)buffer[_textNodeOffset];
-                DiagnosticUtility.DebugAssert(nodeType >= XmlBinaryNodeType.MinText && nodeType <= XmlBinaryNodeType.MaxText && ((byte)nodeType & 1) == 0, "");
+                Debug.Assert(nodeType >= XmlBinaryNodeType.MinText && nodeType <= XmlBinaryNodeType.MaxText && ((byte)nodeType & 1) == 0);
                 buffer[_textNodeOffset] = (byte)(nodeType + 1);
                 _textNodeOffset = -1;
             }
@@ -353,7 +353,7 @@ namespace System.Xml
             XmlDictionaryString? t;
             if (_dictionary != null && _dictionary.TryLookup(s, out t))
             {
-                DiagnosticUtility.DebugAssert(t.Dictionary == _dictionary, "");
+                Debug.Assert(t.Dictionary == _dictionary);
                 key = t.Key * 2;
                 return true;
             }
@@ -402,7 +402,7 @@ namespace System.Xml
                 int offset;
                 byte[] buffer = GetBuffer(1 + charCount * maxBytesPerChar, out offset);
                 int length = UnsafeGetUTF8Chars(chars, charCount, buffer, offset + 1);
-                DiagnosticUtility.DebugAssert(length < 128, "");
+                Debug.Assert(length < 128);
                 buffer[offset] = (byte)length;
                 Advance(1 + length);
             }
@@ -656,7 +656,7 @@ namespace System.Xml
         private unsafe void UnsafeWriteText(char* chars, int charCount)
         {
             // Callers should handle zero
-            DiagnosticUtility.DebugAssert(charCount > 0, "");
+            Debug.Assert(charCount > 0);
 
             if (charCount == 1)
             {
@@ -692,7 +692,7 @@ namespace System.Xml
                     length = UnsafeGetUnicodeChars(chars, charCount, buffer, offset + 2);
                 }
                 _textNodeOffset = offset;
-                DiagnosticUtility.DebugAssert(length <= byte.MaxValue, "");
+                Debug.Assert(length <= byte.MaxValue);
                 buffer[offset + 1] = (byte)length;
                 Advance(2 + length);
             }
@@ -847,7 +847,7 @@ namespace System.Xml
 
         public override void WriteStartListText()
         {
-            DiagnosticUtility.DebugAssert(!_inList, "");
+            Debug.Assert(!_inList);
             _inList = true;
             WriteNode(XmlBinaryNodeType.StartListText);
         }
@@ -858,7 +858,7 @@ namespace System.Xml
 
         public override void WriteEndListText()
         {
-            DiagnosticUtility.DebugAssert(_inList, "");
+            Debug.Assert(_inList);
             _inList = false;
             _wroteAttributeValue = true;
             WriteNode(XmlBinaryNodeType.EndListText);
@@ -1101,7 +1101,7 @@ namespace System.Xml
                 {
                     ArraySegment<byte> arraySegment;
                     bool result = _captureStream.TryGetBuffer(out arraySegment);
-                    DiagnosticUtility.DebugAssert(result, "");
+                    Debug.Assert(result);
                     _captureText = DataContractSerializer.Base64Encoding.GetString(arraySegment.Array!, arraySegment.Offset, arraySegment.Count);
                     _captureStream = null;
                 }
@@ -1171,7 +1171,7 @@ namespace System.Xml
                 {
                     ArraySegment<byte> arraySegment;
                     bool result = _captureStream.TryGetBuffer(out arraySegment);
-                    DiagnosticUtility.DebugAssert(result, "");
+                    Debug.Assert(result);
                     writer.WriteBase64Text(null, 0, arraySegment.Array!, arraySegment.Offset, arraySegment.Count);
                     _captureStream = null;
                 }
@@ -1300,14 +1300,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(array);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > array.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, array.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, array.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > array.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, array.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, array.Length - offset));
         }
 
         public override unsafe void WriteArray(string? prefix, string localName, string? namespaceUri, bool[] array, int offset, int count)
index e091403af295bb88822003601ced42160c75452b..ebe151d77b387aae45c645243391c28af9350b69 100644 (file)
@@ -38,7 +38,7 @@ namespace System.Xml
                 if (key != -1)
                 {
                     // If the key is already set, then something is wrong
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlKeyAlreadyExists));
+                    throw new InvalidOperationException(SR.XmlKeyAlreadyExists);
                 }
 
                 key = Add(value.Value);
index 34bf2427ee3915621ffd59397cb85025d6cfa9cf..4b35d9675819035a6d83abec4e647ca3d81affa9 100644 (file)
@@ -190,7 +190,7 @@ namespace System.Xml
         {
             if (_stream == null)
                 return false;
-            DiagnosticUtility.DebugAssert(_offsetMax < _windowOffsetMax, "");
+            Debug.Assert(_offsetMax < _windowOffsetMax);
             if (_offsetMax >= _buffer.Length)
                 return TryEnsureBytes(1);
             int b = _stream.ReadByte();
@@ -211,7 +211,7 @@ namespace System.Xml
             if (_stream == null)
                 return false;
 
-            DiagnosticUtility.DebugAssert(_offset <= int.MaxValue - count, "");
+            Debug.Assert(_offset <= int.MaxValue - count);
 
             // The data could be coming from an untrusted source, so we use a standard
             // "multiply by 2" growth algorithm to avoid overly large memory utilization.
@@ -222,7 +222,7 @@ namespace System.Xml
                 int newOffsetMax = _offset + count;
                 if (newOffsetMax <= _offsetMax)
                     return true;
-                DiagnosticUtility.DebugAssert(newOffsetMax <= _windowOffsetMax, "");
+                Debug.Assert(newOffsetMax <= _windowOffsetMax);
                 if (newOffsetMax > _buffer.Length)
                 {
                     byte[] newBuffer = new byte[Math.Max(256, _buffer.Length * 2)];
@@ -232,7 +232,7 @@ namespace System.Xml
                     _streamBuffer = newBuffer;
                 }
                 int needed = newOffsetMax - _offsetMax;
-                DiagnosticUtility.DebugAssert(needed > 0, "");
+                Debug.Assert(needed > 0);
                 int read = _stream.ReadAtLeast(_buffer.AsSpan(_offsetMax, needed), needed, throwOnEndOfStream: false);
                 _offsetMax += read;
 
@@ -245,13 +245,13 @@ namespace System.Xml
 
         public void Advance(int count)
         {
-            DiagnosticUtility.DebugAssert(_offset + count <= _offsetMax, "");
+            Debug.Assert(_offset + count <= _offsetMax);
             _offset += count;
         }
 
         public void InsertBytes(byte[] buffer, int offset, int count)
         {
-            DiagnosticUtility.DebugAssert(_stream != null, "");
+            Debug.Assert(_stream != null);
             if (_offsetMax > buffer.Length - count)
             {
                 byte[] newBuffer = new byte[_offsetMax + count];
@@ -292,14 +292,14 @@ namespace System.Xml
             }
             set
             {
-                DiagnosticUtility.DebugAssert(value >= _offsetMin && value <= _offsetMax, "");
+                Debug.Assert(value >= _offsetMin && value <= _offsetMax);
                 _offset = value;
             }
         }
 
         public int ReadBytes(int count)
         {
-            DiagnosticUtility.DebugAssert(count >= 0, "");
+            Debug.Assert(count >= 0);
             int offset = _offset;
             if (offset > _offsetMax - count)
                 EnsureBytes(count);
@@ -428,15 +428,15 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTime", exception));
+                throw XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTime", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTime", exception));
+                throw XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTime", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTime", exception));
+                throw XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTime", exception);
             }
         }
 
@@ -450,15 +450,15 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "TimeSpan", exception));
+                throw XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "TimeSpan", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "TimeSpan", exception));
+                throw XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "TimeSpan", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "TimeSpan", exception));
+                throw XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "TimeSpan", exception);
             }
         }
 
@@ -703,9 +703,9 @@ namespace System.Xml
         private int GetDecimalCharEntity(int offset, int length)
         {
             byte[] buffer = _buffer;
-            DiagnosticUtility.DebugAssert(buffer[offset + 0] == '&', "");
-            DiagnosticUtility.DebugAssert(buffer[offset + 1] == '#', "");
-            DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', "");
+            Debug.Assert(buffer[offset + 0] == '&');
+            Debug.Assert(buffer[offset + 1] == '#');
+            Debug.Assert(buffer[offset + length - 1] == ';');
             int value = 0;
             for (int i = 2; i < length - 1; i++)
             {
@@ -722,10 +722,10 @@ namespace System.Xml
         private int GetHexCharEntity(int offset, int length)
         {
             byte[] buffer = _buffer;
-            DiagnosticUtility.DebugAssert(buffer[offset + 0] == '&', "");
-            DiagnosticUtility.DebugAssert(buffer[offset + 1] == '#', "");
-            DiagnosticUtility.DebugAssert(buffer[offset + 2] == 'x', "");
-            DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', "");
+            Debug.Assert(buffer[offset + 0] == '&');
+            Debug.Assert(buffer[offset + 1] == '#');
+            Debug.Assert(buffer[offset + 2] == 'x');
+            Debug.Assert(buffer[offset + length - 1] == ';');
             int value = 0;
             for (int i = 3; i < length - 1; i++)
             {
@@ -733,7 +733,7 @@ namespace System.Xml
                 int digit = HexConverter.FromChar(ch);
                 if (digit == 0xFF)
                     XmlExceptionHelper.ThrowInvalidCharRef(_reader);
-                DiagnosticUtility.DebugAssert(digit >= 0 && digit < 16, "");
+                Debug.Assert(digit >= 0 && digit < 16);
                 value = value * 16 + digit;
                 if (value > SurrogateChar.MaxValue)
                     XmlExceptionHelper.ThrowInvalidCharRef(_reader);
@@ -746,8 +746,8 @@ namespace System.Xml
             if (length < 3)
                 XmlExceptionHelper.ThrowInvalidCharRef(_reader);
             byte[] buffer = _buffer;
-            DiagnosticUtility.DebugAssert(buffer[offset] == '&', "");
-            DiagnosticUtility.DebugAssert(buffer[offset + length - 1] == ';', "");
+            Debug.Assert(buffer[offset] == '&');
+            Debug.Assert(buffer[offset + length - 1] == ';');
             switch (buffer[offset + 1])
             {
                 case (byte)'l':
@@ -1022,7 +1022,7 @@ namespace System.Xml
                 {
                     XmlBinaryNodeType nodeType = GetNodeType();
                     SkipNodeType();
-                    DiagnosticUtility.DebugAssert(nodeType != XmlBinaryNodeType.StartListText, "");
+                    Debug.Assert(nodeType != XmlBinaryNodeType.StartListText);
                     ReadValue(nodeType, _listValue!);
                     objects[i] = _listValue!.ToObject();
                 }
index fa040004e0b9cc77788b64dc41bc8f2800c9c5bc..ad144673eb071317819e74bfaf3343cf9758fb77 100644 (file)
@@ -95,7 +95,7 @@ namespace System.Xml
                 {
                     if (inclusivePrefixes[i] == null)
                     {
-                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.InvalidInclusivePrefixListCollection);
+                        throw new ArgumentException(SR.InvalidInclusivePrefixListCollection);
                     }
                     _inclusivePrefixes[i] = inclusivePrefixes[i];
                 }
@@ -205,24 +205,20 @@ namespace System.Xml
         public void WriteStartElement(byte[] prefixBuffer, int prefixOffset, int prefixLength, byte[] localNameBuffer, int localNameOffset, int localNameLength)
         {
             ArgumentNullException.ThrowIfNull(prefixBuffer);
-            if (prefixOffset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixOffset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(prefixOffset);
             if (prefixOffset > prefixBuffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixOffset), SR.Format(SR.OffsetExceedsBufferSize, prefixBuffer.Length)));
-            if (prefixLength < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixLength), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(prefixOffset), SR.Format(SR.OffsetExceedsBufferSize, prefixBuffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(prefixLength);
             if (prefixLength > prefixBuffer.Length - prefixOffset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, prefixBuffer.Length - prefixOffset)));
+                throw new ArgumentOutOfRangeException(nameof(prefixLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, prefixBuffer.Length - prefixOffset));
 
             ArgumentNullException.ThrowIfNull(localNameBuffer);
-            if (localNameOffset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameOffset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(localNameOffset);
             if (localNameOffset > localNameBuffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameOffset), SR.Format(SR.OffsetExceedsBufferSize, localNameBuffer.Length)));
-            if (localNameLength < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameLength), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(localNameOffset), SR.Format(SR.OffsetExceedsBufferSize, localNameBuffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(localNameLength);
             if (localNameLength > localNameBuffer.Length - localNameOffset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, localNameBuffer.Length - localNameOffset)));
+                throw new ArgumentOutOfRangeException(nameof(localNameLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, localNameBuffer.Length - localNameOffset));
             ThrowIfClosed();
             bool isRootElement = (_depth == 0);
 
@@ -365,10 +361,10 @@ namespace System.Xml
 
             ThrowIfClosed();
             if (prefix.Length > int.MaxValue - ns.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(ns), SR.Format(SR.CombinedPrefixNSLength, int.MaxValue / maxBytesPerChar)));
+                throw new ArgumentOutOfRangeException(nameof(ns), SR.Format(SR.CombinedPrefixNSLength, int.MaxValue / maxBytesPerChar));
             int totalLength = prefix.Length + ns.Length;
             if (totalLength > int.MaxValue / maxBytesPerChar)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(ns), SR.Format(SR.CombinedPrefixNSLength, int.MaxValue / maxBytesPerChar)));
+                throw new ArgumentOutOfRangeException(nameof(ns), SR.Format(SR.CombinedPrefixNSLength, int.MaxValue / maxBytesPerChar));
             EnsureXmlnsBuffer(totalLength * maxBytesPerChar);
             XmlnsAttribute xmlnsAttribute;
             xmlnsAttribute.prefixOffset = _xmlnsOffset;
@@ -385,27 +381,23 @@ namespace System.Xml
         public void WriteXmlnsAttribute(byte[] prefixBuffer, int prefixOffset, int prefixLength, byte[] nsBuffer, int nsOffset, int nsLength)
         {
             ArgumentNullException.ThrowIfNull(prefixBuffer);
-            if (prefixOffset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixOffset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(prefixOffset);
             if (prefixOffset > prefixBuffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixOffset), SR.Format(SR.OffsetExceedsBufferSize, prefixBuffer.Length)));
-            if (prefixLength < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixLength), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(prefixOffset), SR.Format(SR.OffsetExceedsBufferSize, prefixBuffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(prefixLength);
             if (prefixLength > prefixBuffer.Length - prefixOffset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, prefixBuffer.Length - prefixOffset)));
+                throw new ArgumentOutOfRangeException(nameof(prefixLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, prefixBuffer.Length - prefixOffset));
 
             ArgumentNullException.ThrowIfNull(nsBuffer);
-            if (nsOffset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(nsOffset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(nsOffset);
             if (nsOffset > nsBuffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(nsOffset), SR.Format(SR.OffsetExceedsBufferSize, nsBuffer.Length)));
-            if (nsLength < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(nsLength), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(nsOffset), SR.Format(SR.OffsetExceedsBufferSize, nsBuffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(nsLength);
             if (nsLength > nsBuffer.Length - nsOffset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(nsLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, nsBuffer.Length - nsOffset)));
+                throw new ArgumentOutOfRangeException(nameof(nsLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, nsBuffer.Length - nsOffset));
             ThrowIfClosed();
             if (prefixLength > int.MaxValue - nsLength)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(nsLength), SR.Format(SR.CombinedPrefixNSLength, int.MaxValue)));
+                throw new ArgumentOutOfRangeException(nameof(nsLength), SR.Format(SR.CombinedPrefixNSLength, int.MaxValue));
             EnsureXmlnsBuffer(prefixLength + nsLength);
             XmlnsAttribute xmlnsAttribute;
             xmlnsAttribute.prefixOffset = _xmlnsOffset;
@@ -440,24 +432,20 @@ namespace System.Xml
         public void WriteStartAttribute(byte[] prefixBuffer, int prefixOffset, int prefixLength, byte[] localNameBuffer, int localNameOffset, int localNameLength)
         {
             ArgumentNullException.ThrowIfNull(prefixBuffer);
-            if (prefixOffset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixOffset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(prefixOffset);
             if (prefixOffset > prefixBuffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixOffset), SR.Format(SR.OffsetExceedsBufferSize, prefixBuffer.Length)));
-            if (prefixLength < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixLength), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(prefixOffset), SR.Format(SR.OffsetExceedsBufferSize, prefixBuffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(prefixLength);
             if (prefixLength > prefixBuffer.Length - prefixOffset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(prefixLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, prefixBuffer.Length - prefixOffset)));
+                throw new ArgumentOutOfRangeException(nameof(prefixLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, prefixBuffer.Length - prefixOffset));
 
             ArgumentNullException.ThrowIfNull(localNameBuffer);
-            if (localNameOffset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameOffset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(localNameOffset);
             if (localNameOffset > localNameBuffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameOffset), SR.Format(SR.OffsetExceedsBufferSize, localNameBuffer.Length)));
-            if (localNameLength < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameLength), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(localNameOffset), SR.Format(SR.OffsetExceedsBufferSize, localNameBuffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(localNameLength);
             if (localNameLength > localNameBuffer.Length - localNameOffset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(localNameLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, localNameBuffer.Length - localNameOffset)));
+                throw new ArgumentOutOfRangeException(nameof(localNameLength), SR.Format(SR.SizeExceedsRemainingBufferSpace, localNameBuffer.Length - localNameOffset));
             ThrowIfClosed();
             _attribute.offset = _elementWriter.Position;
             _attribute.length = 0;
@@ -515,14 +503,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(chars);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > chars.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset));
             ThrowIfClosed();
             // Skip all white spaces before the start of root element.
             if (_depth > 0)
@@ -572,14 +558,12 @@ namespace System.Xml
         {
             ThrowIfClosed();
             ArgumentNullException.ThrowIfNull(chars);
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > chars.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset));
             if (_inStartElement)
             {
                 _elementWriter.WriteText(chars, offset, count);
@@ -611,14 +595,12 @@ namespace System.Xml
         {
             ThrowIfClosed();
             ArgumentNullException.ThrowIfNull(chars);
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > chars.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, chars.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > chars.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, chars.Length - offset));
             if (_inStartElement)
             {
                 _elementWriter.WriteText(chars, offset, count);
@@ -631,13 +613,7 @@ namespace System.Xml
 
         private void ThrowIfClosed()
         {
-            if (_writer == null)
-                ThrowClosed();
-        }
-
-        private void ThrowClosed()
-        {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(this.GetType().ToString()));
+            ObjectDisposedException.ThrowIf(_writer is null, this);
         }
 
         private void WriteXmlnsAttribute(ref XmlnsAttribute xmlnsAttribute)
@@ -804,7 +780,7 @@ namespace System.Xml
             else
             {
                 // These should've been set when we added the prefix
-                Fx.Assert(attribute.nsOffset == 0 && attribute.nsLength == 0, "");
+                Debug.Assert(attribute.nsOffset == 0 && attribute.nsLength == 0);
             }
         }
 
index 3420846d339a2655e27e5b5249ec314bf47b6c06..59c5aebd4e39f79331554f2efc1480e230067ddd 100644 (file)
@@ -42,11 +42,11 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Boolean", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Boolean", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Boolean", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Boolean", exception);
             }
         }
 
@@ -71,15 +71,15 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Int32", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Int32", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Int32", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Int32", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Int32", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Int32", exception);
             }
         }
 
@@ -99,15 +99,15 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Int64", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Int64", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Int64", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Int64", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Int64", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Int64", exception);
             }
         }
 
@@ -127,15 +127,15 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "float", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "float", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "float", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "float", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "float", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "float", exception);
             }
         }
 
@@ -155,15 +155,15 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "double", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "double", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "double", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "double", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "double", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "double", exception);
             }
         }
 
@@ -183,15 +183,15 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "decimal", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "decimal", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "decimal", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "decimal", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "decimal", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "decimal", exception);
             }
         }
 
@@ -208,7 +208,7 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(ToString(value), "DateTime", exception));
+                throw XmlExceptionHelper.CreateConversionException(ToString(value), "DateTime", exception);
             }
         }
 
@@ -220,11 +220,11 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "DateTime", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "DateTime", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "DateTime", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "DateTime", exception);
             }
         }
 
@@ -244,11 +244,11 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UniqueId", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "UniqueId", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UniqueId", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "UniqueId", exception);
             }
         }
 
@@ -265,15 +265,15 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "TimeSpan", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "TimeSpan", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "TimeSpan", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "TimeSpan", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "TimeSpan", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "TimeSpan", exception);
             }
         }
 
@@ -290,15 +290,15 @@ namespace System.Xml
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Guid", exception);
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Guid", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "Guid", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "Guid", exception);
             }
         }
 
@@ -315,15 +315,15 @@ namespace System.Xml
             }
             catch (ArgumentException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "UInt64", exception);
             }
             catch (FormatException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "UInt64", exception);
             }
             catch (OverflowException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value, "UInt64", exception));
+                throw XmlExceptionHelper.CreateConversionException(value, "UInt64", exception);
             }
         }
 
@@ -340,7 +340,7 @@ namespace System.Xml
             }
             catch (DecoderFallbackException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception));
+                throw XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception);
             }
         }
 
@@ -352,7 +352,7 @@ namespace System.Xml
             }
             catch (DecoderFallbackException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception));
+                throw XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception);
             }
         }
 
@@ -365,7 +365,7 @@ namespace System.Xml
             }
             catch (DecoderFallbackException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(value, exception));
+                throw XmlExceptionHelper.CreateEncodingException(value, exception);
             }
         }
 
@@ -377,7 +377,7 @@ namespace System.Xml
             }
             catch (DecoderFallbackException exception)
             {
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception));
+                throw XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception);
             }
         }
 
@@ -456,7 +456,7 @@ namespace System.Xml
             else
             {
                 if (index == qname.Length - 1)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.XmlInvalidQualifiedName, qname)));
+                    throw new XmlException(SR.Format(SR.XmlInvalidQualifiedName, qname));
                 prefix = qname.Substring(0, index).Trim();
                 localName = qname.Substring(index + 1).Trim();
             }
@@ -703,7 +703,7 @@ namespace System.Xml
                     value = valueDiv10;
                 }
             }
-            Fx.Assert(value >= int.MinValue && value <= int.MaxValue, "");
+            Debug.Assert(value >= int.MinValue && value <= int.MaxValue);
             return count + ToCharsR((int)value, chars, offset);
         }
 
@@ -785,7 +785,7 @@ namespace System.Xml
         {
             for (int i = 0; i < s.Length; i++)
             {
-                DiagnosticUtility.DebugAssert(s[i] < 128, "");
+                Debug.Assert(s[i] < 128);
                 buffer[offset++] = (byte)s[i];
             }
             return s.Length;
@@ -1001,7 +1001,7 @@ namespace System.Xml
 
         private static int ToCharsD2(int value, byte[] chars, int offset)
         {
-            DiagnosticUtility.DebugAssert(value >= 0 && value < 100, "");
+            Debug.Assert(value >= 0 && value < 100);
             if (value < 10)
             {
                 chars[offset + 0] = (byte)'0';
@@ -1018,7 +1018,7 @@ namespace System.Xml
 
         private static int ToCharsD4(int value, byte[] chars, int offset)
         {
-            DiagnosticUtility.DebugAssert(value >= 0 && value < 10000, "");
+            Debug.Assert(value >= 0 && value < 10000);
             ToCharsD2(value / 100, chars, offset + 0);
             ToCharsD2(value % 100, chars, offset + 2);
             return 4;
@@ -1026,7 +1026,7 @@ namespace System.Xml
 
         private static int ToCharsD7(int value, byte[] chars, int offset)
         {
-            DiagnosticUtility.DebugAssert(value >= 0 && value < 10000000, "");
+            Debug.Assert(value >= 0 && value < 10000000);
             int zeroCount = 7 - ToCharsR(value, chars, offset + 7);
             for (int i = 0; i < zeroCount; i++)
                 chars[offset + i] = (byte)'0';
@@ -1079,7 +1079,7 @@ namespace System.Xml
                     chars[offset++] = (byte)'Z';
                     break;
                 default:
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+                    throw new InvalidOperationException();
             }
             return offset - offsetMin;
         }
index d065ef92957b4bccd777498fdcd7b6c04822267a..25b550a44906a79b2327255fe2c9d544b6c28ef0 100644 (file)
@@ -185,12 +185,12 @@ namespace System.Xml
 
         public virtual void StartCanonicalization(Stream stream, bool includeComments, string[]? inclusivePrefixes)
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+            throw new NotSupportedException();
         }
 
         public virtual void EndCanonicalization()
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+            throw new NotSupportedException();
         }
 
         public virtual void MoveToStartElement()
@@ -298,7 +298,7 @@ namespace System.Xml
                 {
                     string value = localNames[i];
                     if (value == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull($"localNames[{i}]");
+                        throw new ArgumentNullException($"localNames[{i}]");
                     if (localName == value)
                     {
                         return i;
@@ -321,7 +321,7 @@ namespace System.Xml
                 {
                     XmlDictionaryString value = localNames[i];
                     if (value == null)
-                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull($"localNames[{i}]");
+                        throw new ArgumentNullException($"localNames[{i}]");
                     if (localName == value.Value)
                     {
                         return i;
@@ -345,7 +345,7 @@ namespace System.Xml
 
         public virtual int ReadValueAsBase64(byte[] buffer, int offset, int count)
         {
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+            throw new NotSupportedException();
         }
 
         public virtual byte[] ReadContentAsBase64()
@@ -461,7 +461,7 @@ namespace System.Xml
                 if (this.IsEmptyElement)
                     return string.Empty;
                 if (!Read())
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlInvalidOperation));
+                    throw new InvalidOperationException(SR.XmlInvalidOperation);
                 if (this.NodeType == XmlNodeType.EndElement)
                     return string.Empty;
             }
@@ -482,7 +482,7 @@ namespace System.Xml
                     sb.Append(value);
                 }
                 if (!Read())
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlInvalidOperation));
+                    throw new InvalidOperationException(SR.XmlInvalidOperation);
             }
             if (sb != null)
                 result = sb.ToString();
@@ -616,7 +616,7 @@ namespace System.Xml
             {
                 string value = strings[i];
                 if (value == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull($"strings[{i}]");
+                    throw new ArgumentNullException($"strings[{i}]");
                 if (value == s)
                 {
                     index = i;
@@ -636,7 +636,7 @@ namespace System.Xml
             {
                 XmlDictionaryString value = strings[i];
                 if (value == null)
-                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull($"strings[{i}]");
+                    throw new ArgumentNullException($"strings[{i}]");
                 if (value.Value == s)
                 {
                     index = i;
@@ -835,11 +835,11 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(string.Empty, "DateTime", exception));
+                    throw XmlExceptionHelper.CreateConversionException(string.Empty, "DateTime", exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(string.Empty, "DateTime", exception));
+                    throw XmlExceptionHelper.CreateConversionException(string.Empty, "DateTime", exception);
                 }
             }
             else
@@ -866,11 +866,11 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(string.Empty, "UniqueId", exception));
+                    throw XmlExceptionHelper.CreateConversionException(string.Empty, "UniqueId", exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(string.Empty, "UniqueId", exception));
+                    throw XmlExceptionHelper.CreateConversionException(string.Empty, "UniqueId", exception);
                 }
             }
             else
@@ -897,15 +897,15 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(string.Empty, "Guid", exception));
+                    throw XmlExceptionHelper.CreateConversionException(string.Empty, "Guid", exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(string.Empty, "Guid", exception));
+                    throw XmlExceptionHelper.CreateConversionException(string.Empty, "Guid", exception);
                 }
                 catch (OverflowException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(string.Empty, "Guid", exception));
+                    throw XmlExceptionHelper.CreateConversionException(string.Empty, "Guid", exception);
                 }
             }
             else
@@ -1006,14 +1006,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(array);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > array.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, array.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, array.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > array.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, array.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, array.Length - offset));
         }
 
         public virtual bool IsStartArray([NotNullWhen(true)] out Type? type)
@@ -1662,11 +1660,11 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Boolean), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Boolean), exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Boolean), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Boolean), exception);
                 }
             }
 
@@ -1683,15 +1681,15 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Decimal), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Decimal), exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Decimal), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Decimal), exception);
                 }
                 catch (OverflowException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Decimal), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Decimal), exception);
                 }
             }
 
@@ -1703,15 +1701,15 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Double), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Double), exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Double), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Double), exception);
                 }
                 catch (OverflowException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Double), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Double), exception);
                 }
             }
 
@@ -1723,15 +1721,15 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Int32), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Int32), exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Int32), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Int32), exception);
                 }
                 catch (OverflowException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Int32), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Int32), exception);
                 }
             }
 
@@ -1743,15 +1741,15 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Int64), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Int64), exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Int64), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Int64), exception);
                 }
                 catch (OverflowException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Int64), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Int64), exception);
                 }
             }
 
@@ -1763,15 +1761,15 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Single), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Single), exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Single), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Single), exception);
                 }
                 catch (OverflowException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(Single), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(Single), exception);
                 }
             }
 
@@ -1783,11 +1781,11 @@ namespace System.Xml
                 }
                 catch (ArgumentException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(String), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(String), exception);
                 }
                 catch (FormatException exception)
                 {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(nameof(String), exception));
+                    throw XmlExceptionHelper.CreateConversionException(nameof(String), exception);
                 }
             }
 
index 7d451ecbba92719e6fbdb07453ff7d33239ca427..dc662b39229771ff151f4fe962f30ec4035899f3 100644 (file)
@@ -67,7 +67,7 @@ namespace System.Xml
             ArgumentNullException.ThrowIfNull(quotas);
 
             if (quotas._readOnly)
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.QuotaCopyReadOnly));
+                throw new InvalidOperationException(SR.QuotaCopyReadOnly);
 
             InternalCopyTo(quotas);
         }
@@ -92,9 +92,8 @@ namespace System.Xml
             set
             {
                 if (_readOnly)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxStringContentLength")));
-                if (value <= 0)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.QuotaMustBePositive, nameof(value)));
+                    throw new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxStringContentLength"));
+                ArgumentOutOfRangeException.ThrowIfNegativeOrZero(value);
                 _maxStringContentLength = value;
                 _modifiedQuotas |= XmlDictionaryReaderQuotaTypes.MaxStringContentLength;
             }
@@ -110,9 +109,8 @@ namespace System.Xml
             set
             {
                 if (_readOnly)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxArrayLength")));
-                if (value <= 0)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.QuotaMustBePositive, nameof(value)));
+                    throw new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxArrayLength"));
+                ArgumentOutOfRangeException.ThrowIfNegativeOrZero(value);
                 _maxArrayLength = value;
                 _modifiedQuotas |= XmlDictionaryReaderQuotaTypes.MaxArrayLength;
             }
@@ -128,9 +126,8 @@ namespace System.Xml
             set
             {
                 if (_readOnly)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxBytesPerRead")));
-                if (value <= 0)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.QuotaMustBePositive, nameof(value)));
+                    throw new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxBytesPerRead"));
+                ArgumentOutOfRangeException.ThrowIfNegativeOrZero(value);
 
                 _maxBytesPerRead = value;
                 _modifiedQuotas |= XmlDictionaryReaderQuotaTypes.MaxBytesPerRead;
@@ -147,9 +144,8 @@ namespace System.Xml
             set
             {
                 if (_readOnly)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxDepth")));
-                if (value <= 0)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.QuotaMustBePositive, nameof(value)));
+                    throw new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxDepth"));
+                ArgumentOutOfRangeException.ThrowIfNegativeOrZero(value);
 
                 _maxDepth = value;
                 _modifiedQuotas |= XmlDictionaryReaderQuotaTypes.MaxDepth;
@@ -166,9 +162,8 @@ namespace System.Xml
             set
             {
                 if (_readOnly)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxNameTableCharCount")));
-                if (value <= 0)
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.QuotaMustBePositive, nameof(value)));
+                    throw new InvalidOperationException(SR.Format(SR.QuotaIsReadOnly, "MaxNameTableCharCount"));
+                ArgumentOutOfRangeException.ThrowIfNegativeOrZero(value);
 
                 _maxNameTableCharCount = value;
                 _modifiedQuotas |= XmlDictionaryReaderQuotaTypes.MaxNameTableCharCount;
index dcce9e1094ccdeb7975e216e522a777cedcd4966..6b858e16e62a59af40de1fb5bce935d589d38b46 100644 (file)
@@ -27,7 +27,7 @@ namespace System.Xml
             ArgumentNullException.ThrowIfNull(value);
 
             if (key < MinKey || key > MaxKey)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(key), SR.Format(SR.ValueMustBeInRange, MinKey, MaxKey)));
+                throw new ArgumentOutOfRangeException(nameof(key), SR.Format(SR.ValueMustBeInRange, MinKey, MaxKey));
             _dictionary = dictionary;
             _value = value;
             _key = key;
index e6112443ba30656e435c9d1162c29469b120acbd..668f7b8bb2bfe1d3a82f0e0ab1da25a0499bf57b 100644 (file)
@@ -194,7 +194,7 @@ namespace System.Xml
 
             Stream stream = value.GetStream();
             if (stream == null)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.XmlInvalidStream));
+                throw new XmlException(SR.XmlInvalidStream);
             int blockSize = 256;
             int bytesRead;
             byte[] block = new byte[blockSize];
@@ -230,12 +230,12 @@ namespace System.Xml
 
         public virtual void StartCanonicalization(Stream stream, bool includeComments, string[]? inclusivePrefixes)
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+            throw new NotSupportedException();
         }
 
         public virtual void EndCanonicalization()
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+            throw new NotSupportedException();
         }
 
         private void WriteElementNode(XmlDictionaryReader reader, bool defattr)
@@ -437,14 +437,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(array);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > array.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, array.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, array.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > array.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, array.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, array.Length - offset));
         }
 
         // bool
index 8e0a93997099892acb5a3505d0de1a6bfc9563a2..5b1462eda97c2886336ca6c7c66b229d0d2a8899 100644 (file)
@@ -36,7 +36,7 @@ namespace System.Xml
                 s += " " + SR.Format(SR.XmlLineInfo, lineInfo.LineNumber, lineInfo.LinePosition);
             }
 
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(s));
+            throw new XmlException(s);
         }
 
         [DoesNotReturn]
@@ -47,7 +47,7 @@ namespace System.Xml
             {
                 s += " " + SR.Format(SR.XmlLineInfo, lineInfo.LineNumber, lineInfo.LinePosition);
             }
-            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(s));
+            throw new XmlException(s);
         }
 
         private static string GetName(string prefix, string localName)
index 3cd4abcae7048877a283a48956a732d25e65ca25..9014d83109af836ede7d59eb8f895fa71f6023a4 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Xml
         public abstract void Flush();
         public virtual Task FlushAsync()
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(NotImplemented.ByDesign);
+            throw NotImplemented.ByDesign;
         }
         public abstract void Close();
         public abstract void WriteDeclaration();
@@ -30,7 +30,7 @@ namespace System.Xml
         public abstract void WriteStartElement(string? prefix, string localName);
         public virtual Task WriteStartElementAsync(string? prefix, string localName)
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(NotImplemented.ByDesign);
+            throw NotImplemented.ByDesign;
         }
         public virtual void WriteStartElement(byte[] prefixBuffer, int prefixOffset, int prefixLength, byte[] localNameBuffer, int localNameOffset, int localNameLength)
         {
@@ -40,12 +40,12 @@ namespace System.Xml
         public abstract void WriteEndStartElement(bool isEmpty);
         public virtual Task WriteEndStartElementAsync(bool isEmpty)
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(NotImplemented.ByDesign);
+            throw NotImplemented.ByDesign;
         }
         public abstract void WriteEndElement(string? prefix, string localName);
         public virtual Task WriteEndElementAsync(string? prefix, string localName)
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(NotImplemented.ByDesign);
+            throw NotImplemented.ByDesign;
         }
         public virtual void WriteEndElement(byte[] prefixBuffer, int prefixOffset, int prefixLength, byte[] localNameBuffer, int localNameOffset, int localNameLength)
         {
@@ -66,7 +66,7 @@ namespace System.Xml
         public abstract void WriteEndAttribute();
         public virtual Task WriteEndAttributeAsync()
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(NotImplemented.ByDesign);
+            throw NotImplemented.ByDesign;
         }
         public abstract void WriteCharEntity(int ch);
         public abstract void WriteEscapedText(string value);
@@ -94,7 +94,7 @@ namespace System.Xml
         public abstract void WriteBase64Text(byte[] trailBuffer, int trailCount, byte[] buffer, int offset, int count);
         public virtual Task WriteBase64TextAsync(byte[] trailBuffer, int trailCount, byte[] buffer, int offset, int count)
         {
-            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(NotImplemented.ByDesign);
+            throw NotImplemented.ByDesign;
         }
         public abstract void WriteQualifiedName(string prefix, XmlDictionaryString localName);
 
index b83e56a243a1abcf275ce99961ce4ad6fa4ba903..b144c751fe9383d923e3f20ca8e83464a39e1cf8 100644 (file)
@@ -5,6 +5,7 @@ using System.IO;
 using System.Text;
 using System.Runtime.Serialization;
 using System.Threading.Tasks;
+using System.Diagnostics;
 
 namespace System.Xml
 {
@@ -62,7 +63,7 @@ namespace System.Xml
 
         protected byte[] GetBuffer(int count, out int offset)
         {
-            DiagnosticUtility.DebugAssert(count >= 0 && count <= bufferLength, "");
+            Debug.Assert(count >= 0 && count <= bufferLength);
             int bufferOffset = _offset;
             if (bufferOffset + count <= bufferLength)
             {
@@ -74,7 +75,7 @@ namespace System.Xml
                 offset = 0;
             }
 #if DEBUG
-            DiagnosticUtility.DebugAssert(offset + count <= bufferLength, "");
+            Debug.Assert(offset + count <= bufferLength);
             for (int i = 0; i < count; i++)
             {
                 _buffer[offset + i] = (byte)'<';
@@ -86,7 +87,7 @@ namespace System.Xml
         protected async Task<BytesWithOffset> GetBufferAsync(int count)
         {
             int offset;
-            DiagnosticUtility.DebugAssert(count >= 0 && count <= bufferLength, "");
+            Debug.Assert(count >= 0 && count <= bufferLength);
             int bufferOffset = _offset;
             if (bufferOffset + count <= bufferLength)
             {
@@ -98,7 +99,7 @@ namespace System.Xml
                 offset = 0;
             }
 #if DEBUG
-            DiagnosticUtility.DebugAssert(offset + count <= bufferLength, "");
+            Debug.Assert(offset + count <= bufferLength);
             for (int i = 0; i < count; i++)
             {
                 _buffer[offset + i] = (byte)'<';
@@ -109,7 +110,7 @@ namespace System.Xml
 
         protected void Advance(int count)
         {
-            DiagnosticUtility.DebugAssert(_offset + count <= bufferLength, "");
+            Debug.Assert(_offset + count <= bufferLength);
             _offset += count;
         }
 
@@ -148,13 +149,13 @@ namespace System.Xml
 
         protected void WriteByte(char ch)
         {
-            DiagnosticUtility.DebugAssert(ch < 0x80, "");
+            Debug.Assert(ch < 0x80);
             WriteByte((byte)ch);
         }
 
         protected Task WriteByteAsync(char ch)
         {
-            DiagnosticUtility.DebugAssert(ch < 0x80, "");
+            Debug.Assert(ch < 0x80);
             return WriteByteAsync((byte)ch);
         }
 
@@ -195,13 +196,13 @@ namespace System.Xml
 
         protected void WriteBytes(char ch1, char ch2)
         {
-            DiagnosticUtility.DebugAssert(ch1 < 0x80 && ch2 < 0x80, "");
+            Debug.Assert(ch1 < 0x80 && ch2 < 0x80);
             WriteBytes((byte)ch1, (byte)ch2);
         }
 
         protected Task WriteBytesAsync(char ch1, char ch2)
         {
-            DiagnosticUtility.DebugAssert(ch1 < 0x80 && ch2 < 0x80, "");
+            Debug.Assert(ch1 < 0x80 && ch2 < 0x80);
             return WriteBytesAsync((byte)ch1, (byte)ch2);
         }
 
index 30a6fb5a6eb6c8efa31279725e83e8c6da46301e..90b855f5ef30ee842f36cfa6ff790ac129f2ea16 100644 (file)
@@ -557,14 +557,12 @@ namespace System.Xml
         {
             ArgumentNullException.ThrowIfNull(buffer);
 
-            if (offset < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.ValueMustBeNonNegative));
+            ArgumentOutOfRangeException.ThrowIfNegative(offset);
             if (offset > buffer.Length)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length)));
-            if (count < 0)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.ValueMustBeNonNegative));
+                throw new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.OffsetExceedsBufferSize, buffer.Length));
+            ArgumentOutOfRangeException.ThrowIfNegative(count);
             if (count > buffer.Length - offset)
-                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset)));
+                throw new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset));
             MoveToInitial(quotas, onClose);
             ArraySegment<byte> seg = EncodingStreamWrapper.ProcessBuffer(buffer, offset, count, encoding);
             BufferReader.SetBuffer(seg.Array!, seg.Offset, seg.Count, null, null);
@@ -594,17 +592,7 @@ namespace System.Xml
             base.Close();
             OnXmlDictionaryReaderClose? onClose = _onClose;
             _onClose = null;
-            if (onClose != null)
-            {
-                try
-                {
-                    onClose(this);
-                }
-                catch (Exception e)
-                {
-                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
-                }
-            }
+            onClose?.Invoke(this);
         }
 
         private void SkipWhitespace()
@@ -888,7 +876,7 @@ namespace System.Xml
         // 0xFFFE and 0xFFFF are not valid characters per Unicode specification. The first byte in the UTF8 representation is 0xEF.
         private static bool IsNextCharacterNonFFFE(byte[] buffer, int offset)
         {
-            Fx.Assert(buffer[offset] == 0xEF, "buffer[offset] MUST be 0xEF.");
+            Debug.Assert(buffer[offset] == 0xEF, "buffer[offset] MUST be 0xEF.");
 
             if (buffer[offset + 1] == 0xBF && (buffer[offset + 2] == 0xBE || buffer[offset + 2] == 0xBF))
             {
@@ -1097,7 +1085,7 @@ namespace System.Xml
 
         private int ReadCharRef()
         {
-            DiagnosticUtility.DebugAssert(BufferReader.GetByte() == '&', "");
+            Debug.Assert(BufferReader.GetByte() == '&');
             int charEntityOffset = BufferReader.Offset;
             BufferReader.SkipByte();
             while (BufferReader.GetByte() != ';')