- 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
<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>
<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" />
<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" />
}
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));
}
}
}
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)
}
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));
}
}
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));
}
}
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));
}
}
{
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)
{
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
{
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;
}
{
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;
}
{
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;
}
{
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;
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;
}
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
_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)
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;
}
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;
}
case Cmp.NotEqualTo:
return OpCodes.Beq;
default:
- DiagnosticUtility.DebugAssert(cmp == Cmp.GreaterThanOrEqualTo, "Unexpected cmp");
+ Debug.Assert(cmp == Cmp.GreaterThanOrEqualTo, "Unexpected cmp");
return OpCodes.Blt;
}
}
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)
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)
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;
}
{
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)
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())));
}
}
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:
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)));
}
}
}
{
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);
}
}
{
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);
}
}
{
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);
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))
{
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()
[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)
{
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)
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();
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);
}
}
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);
}
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);
: 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);
: 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;
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;
}
}
if (InvalidCollectionInSharedContractMessage != null)
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(InvalidCollectionInSharedContractMessage));
+ throw new InvalidDataContractException(InvalidCollectionInSharedContractMessage);
return this;
}
{
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
{
{
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}
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;
}
[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
DataContract dataContract = s_dataContractCache[id];
if (dataContract == null)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.DataContractCacheOverflow));
+ throw new SerializationException(SR.DataContractCacheOverflow);
}
return dataContract;
}
return i;
}
}
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.DataContractCacheOverflow));
+ throw new SerializationException(SR.DataContractCacheOverflow);
}
private static bool ContractMatches(DataContract contract, DataContract cachedContract)
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);
}
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);
}
}
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);
}
}
{
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))
{
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;
}
}
}
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(message));
+ throw new InvalidDataContractException(message);
}
internal DataContractCriticalHelper(
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)
{
{
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);
{
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
{
#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];
}
{
#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);
{
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
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;
}
}
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)
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));
}
}
// 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);
}
}
- if (maxItemsInObjectGraph < 0)
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(maxItemsInObjectGraph), SR.ValueMustBeNonNegative));
+ ArgumentOutOfRangeException.ThrowIfNegative(maxItemsInObjectGraph);
_maxItemsInObjectGraph = maxItemsInObjectGraph;
_ignoreExtensionDataObject = ignoreExtensionDataObject;
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;
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
{
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);
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;
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;
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)]
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));
}
}
}
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);
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);
}
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);
}
}
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;
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)
}
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()));
}
}
}
}
catch (ArgumentException exception)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTimeOffset", exception));
+ throw XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTimeOffset", exception);
}
}
+++ /dev/null
-// 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);
- }
- }
- }
-}
}
// 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)
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);
}
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)
--- /dev/null
+// 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;
+ }
+ }
+}
break;
default:
- Fx.Assert("ExtensionDataReader in invalid state");
+ Debug.Fail("ExtensionDataReader in invalid state");
throw new SerializationException(SR.InvalidStateInExtensionDataReader);
}
_readState = ReadState.Interactive;
{
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;
}
}
{
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;
}
}
{
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;
}
}
{
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;
}
}
{
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;
}
{
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;
}
{
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;
}
}
else
{
- Fx.Assert("ExtensionDataReader ResolveEntity method should only be called for IXmlSerializable");
+ Debug.Fail("ExtensionDataReader ResolveEntity method should only be called for IXmlSerializable");
}
}
{
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;
}
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;
}
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)
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)
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)
}
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))
_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);
}
}
}
- if (maxItemsInObjectGraph < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(maxItemsInObjectGraph), SR.ValueMustBeNonNegative);
- }
+ ArgumentOutOfRangeException.ThrowIfNegative(maxItemsInObjectGraph);
_maxItemsInObjectGraph = maxItemsInObjectGraph;
_ignoreExtensionDataObject = ignoreExtensionDataObject;
_emitTypeInformation = emitTypeInformation;
{
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));
}
}
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);
{
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;
{
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);
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];
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)
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));
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));
{
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));
{
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));
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])));
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
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));
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));
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));
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)
{
// 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)
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));
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();
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)
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()));
}
}
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));
}
}
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
{
// 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;
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;
}
using System;
using System.Xml;
using System.Collections.Generic;
-
+using System.Diagnostics;
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);
}
{
if (_objectDictionary == null)
{
- DiagnosticUtility.DebugAssert("Object reference stack in invalid state");
+ Debug.Fail("Object reference stack in invalid state");
}
_objectDictionary.Remove(obj);
}
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Runtime.CompilerServices;
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)
}
}
// 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)
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();
}
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);
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) =>
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);
}
}
{
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;
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)
{
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)]
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)
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);
}
}
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);
}
}
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);
}
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)
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
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);
}
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)
{
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))
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
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);
}
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);
}
{
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);
{
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;
{
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);
}
[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));
}
}
{
return ProcessClassDataContract((ClassDataContract)contract, context, memberNode);
}
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.QueryGeneratorPathToMemberNotFound));
+ throw XmlObjectSerializer.CreateSerializationException(SR.QueryGeneratorPathToMemberNotFound);
}
[RequiresDynamicCode(DataContract.SerializerAOTWarning)]
return member.MemberTypeContract;
}
}
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.QueryGeneratorPathToMemberNotFound));
+ throw XmlObjectSerializer.CreateSerializationException(SR.QueryGeneratorPathToMemberNotFound);
}
private static IEnumerable<DataMember> GetDataMembers(ClassDataContract contract)
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;
}
else
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IsAnyCannotHaveXmlRoot, DataContract.GetClrTypeFullName(UnderlyingType!))));
+ throw new InvalidDataContractException(SR.Format(SR.IsAnyCannotHaveXmlRoot, DataContract.GetClrTypeFullName(UnderlyingType!)));
}
}
}
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;
}
{
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;
}
{
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;
}
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];
}
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);
}
}
[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)]
}
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);
}
}
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);
}
}
}
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);
}
}
[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)]
}
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);
}
}
}
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);
}
}
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;
}
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)]
{
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);
}
[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)
{
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
{
{
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);
}
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)));
}
}
}
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)]
{
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);
{
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);
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)
{
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;
// 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;
}
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)
{
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];
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)]
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);
}
{
if (nodeType != XmlNodeType.Element)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+ throw CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
}
if (xmlReader.NamespaceURI.Length != 0)
return objNode;
}
default:
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateUnexpectedStateException(XmlNodeType.Element, xmlReader));
+ throw CreateUnexpectedStateException(XmlNodeType.Element, xmlReader);
}
}
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++));
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)
{
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
{
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)
{
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)!);
}
}
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;
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();
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;
}
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
{
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));
}
}
}
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;
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
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();
//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);
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)
{
}
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;
}
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;
}
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
{
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);
}
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);
}
return ReadContentAsQName();
break;
}
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
+ throw CreateInvalidPrimitiveTypeException(valueType);
}
internal IDataNode ReadExtensionData(Type valueType)
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()
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
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,
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;
while (_xmlReader.Depth > _startDepth)
{
if (!_xmlReader.Read())
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.EndElement, _xmlReader));
+ throw XmlObjectSerializerReadContext.CreateUnexpectedStateException(XmlNodeType.EndElement, _xmlReader);
}
}
}
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; } }
{
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());
{
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);
}
}
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;
}
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--;
}
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)
break;
}
if (!handled)
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
+ throw CreateInvalidPrimitiveTypeException(valueType);
}
internal void WriteExtensionData(IDataNode dataNode)
if (!handled)
{
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
+ throw CreateInvalidPrimitiveTypeException(valueType);
}
}
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>
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++)
Export();
}
- catch (Exception ex)
+ catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
{
- if (Fx.IsFatal(ex))
- throw;
-
_dataContractSet = oldValue;
throw;
}
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;
}
AddType(type);
Export();
}
- catch (Exception ex)
+ catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
{
- if (Fx.IsFatal(ex))
- throw;
-
_dataContractSet = oldValue;
throw;
}
{
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);
}
}
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++)
_dataContractSet = oldValue;
return false;
}
- catch (Exception ex)
+ catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
{
- if (Fx.IsFatal(ex))
- throw;
-
_dataContractSet = oldValue;
throw;
}
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();
_dataContractSet = oldValue;
return false;
}
- catch (Exception ex)
+ catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
{
- if (Fx.IsFatal(ex))
- throw;
-
_dataContractSet = oldValue;
throw;
}
_dataContractSet = oldValue;
return false;
}
- catch (Exception ex)
+ catch (Exception ex) when (!ExceptionUtility.IsFatal(ex))
{
- if (Fx.IsFatal(ex))
- throw;
-
_dataContractSet = oldValue;
throw;
}
using System.Diagnostics;
using System.Runtime.Serialization; //For SR
using System.Globalization;
+using System.Reflection;
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;
}
{
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])
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
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;
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])
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
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)
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])
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
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)
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;
}
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
else
{
// 0 trailing bytes
- DiagnosticUtility.DebugAssert(pb - pbMax == 3, "");
+ Debug.Assert(pb - pbMax == 3);
}
}
}
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
else
{
// 0 trailing bytes
- DiagnosticUtility.DebugAssert(pb - pbMax == 3, "");
+ Debug.Assert(pb - pbMax == 3);
}
}
}
{
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;
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);
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)
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);
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;
public void SetValue(PrefixHandleType type)
{
- DiagnosticUtility.DebugAssert(type != PrefixHandleType.Buffer, "");
+ Debug.Assert(type != PrefixHandleType.Buffer);
_type = type;
}
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;
public void ToPrefixHandle(PrefixHandle prefix)
{
- DiagnosticUtility.DebugAssert(_type == StringHandleType.UTF8, "");
+ Debug.Assert(_type == StringHandleType.UTF8);
prefix.SetValue(_offset, _length);
}
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);
}
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);
}
}
else
{
- DiagnosticUtility.DebugAssert(type == StringHandleType.EscapedUTF8, "");
+ Debug.Assert(type == StringHandleType.EscapedUTF8);
byte[] buffer = XmlConverter.ToBytes(_bufferReader.GetEscapedString(_offset, _length));
offset = 0;
length = buffer.Length;
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;
}
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;
}
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;
}
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);
}
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());
}
{
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);
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);
{
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);
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;
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])
{
using System.Runtime.Serialization;
using System.Text;
using System.Diagnostics.CodeAnalysis;
+using System.Diagnostics;
namespace System.Xml
{
case ValueHandleType.TimeSpan:
return typeof(TimeSpan);
default:
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+ throw new InvalidOperationException();
}
}
}
catch (FormatException exception)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(exception.Message, exception.InnerException));
+ throw new XmlException(exception.Message, exception.InnerException);
}
}
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());
case ValueHandleType.ConstString:
return s_constStrings[_offset];
default:
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+ throw new InvalidOperationException();
}
}
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;
case ValueHandleType.TimeSpan:
return ToTimeSpan();
default:
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+ throw new InvalidOperationException();
}
}
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);
}
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
}
catch (FormatException exception)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(bytes, byteOffset, byteCount, exception));
+ throw XmlExceptionHelper.CreateEncodingException(bytes, byteOffset, byteCount, exception);
}
// Advance
}
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);
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);
}
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));
}
}
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];
}
}
else
{
- DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+ Debug.Assert(qnameType == QNameType.Xmlns);
if (_node.Namespace.Prefix.IsEmpty)
_localName = xmlns;
else
}
else
{
- DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+ Debug.Assert(qnameType == QNameType.Xmlns);
for (int j = i + 1; j < attributeCount; j++)
{
XmlAttributeNode attributeNode2 = attributeNodes[j];
}
else
{
- DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+ Debug.Assert(qnameType == QNameType.Xmlns);
_ns = xmlnsNamespace;
}
}
{
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;
}
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;
{
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;
}
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;
{
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)
{
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;
{
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());
{
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;
{
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);
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;
public override void ResolveEntity()
{
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlInvalidOperation));
+ throw new InvalidOperationException(SR.XmlInvalidOperation);
}
public override void Skip()
}
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;
SignEndElement(writer);
break;
default:
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+ throw new InvalidOperationException();
}
}
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();
public override void EndCanonicalization()
{
if (!_signing)
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlCanonicalizationNotStarted));
+ throw new InvalidOperationException(SR.XmlCanonicalizationNotStarted);
_signingWriter!.Flush();
_signingWriter.Close();
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; } }
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
return this.Namespace.Prefix == localName;
}
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
return this.Namespace.Prefix == localName;
}
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
return ns == xmlnsNamespace;
}
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
return ns.Value == xmlnsNamespace;
}
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
return this.Namespace.Prefix == localName && ns == xmlnsNamespace;
}
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
return this.Namespace.Prefix == localName && ns.Value == xmlnsNamespace;
}
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
return prefix == xmlns && this.Namespace.Prefix == localName;
}
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
localName = null;
return false;
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
ns = null;
return false;
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
value = null;
return false;
}
}
else
{
- DiagnosticUtility.DebugAssert(_qnameType == QNameType.Xmlns, "");
+ Debug.Assert(_qnameType == QNameType.Xmlns);
return Namespace.Uri.GetString();
}
}
}
else
{
- DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
+ Debug.Assert(qnameType == QNameType.Xmlns);
i = attribute1.Namespace.Prefix.CompareTo(attribute2.Namespace.Prefix);
}
}
public bool IsUri(string s)
{
- DiagnosticUtility.DebugAssert(s != null, "");
+ Debug.Assert(s != null);
if (object.ReferenceEquals(s, _uriString))
return true;
if (_uri == s)
[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
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)
{
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)
{
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)
{
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;
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;
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)
{
{
// 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);
}
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
}
else
{
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlInvalidXmlSpace, _attributeValue)));
+ throw new ArgumentException(SR.Format(SR.XmlInvalidXmlSpace, _attributeValue));
}
}
else
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();
}
}
else
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.XmlInvalidXmlSpace, _attributeValue)));
+ throw new ArgumentException(SR.Format(SR.XmlInvalidXmlSpace, _attributeValue));
}
}
else
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)
{
}
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();
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();
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;
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)
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);
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)
{
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)
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)
{
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();
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();
}
{
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)
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()
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);
}
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);
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;
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,
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;
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)
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)
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);
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)
{
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)
{
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());
}
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
{
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)
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);
if (IsClosed)
ThrowClosed();
if (!Signing)
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlCanonicalizationNotStarted));
+ throw new InvalidOperationException(SR.XmlCanonicalizationNotStarted);
_signingWriter!.Flush();
_writer = _signingWriter.NodeWriter;
}
public void StartFragment(Stream stream, bool generateSelfContainedTextFragment)
{
if (!CanFragment)
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+ throw new NotSupportedException();
if (IsClosed)
ThrowClosed();
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();
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();
public void WriteFragment(byte[] buffer, int offset, int count)
{
if (!CanFragment)
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
+ throw new NotSupportedException();
if (IsClosed)
ThrowClosed();
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();
{
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);
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;
{
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)
{
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];
// 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;
{
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;
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()
}
else
{
- DiagnosticUtility.DebugAssert(_arrayState == ArrayState.Element, "");
+ Debug.Assert(_arrayState == ArrayState.Element);
nodeType = _arrayNodeType;
_arrayCount--;
_arrayState = ArrayState.Content;
{
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)
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)
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");
}
private void WroteAttributeValue()
{
if (_wroteAttributeValue && !_inList)
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.XmlOnlySingleValue));
+ throw new InvalidOperationException(SR.XmlOnlySingleValue);
_wroteAttributeValue = true;
}
{
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;
}
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)
{
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;
}
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;
}
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);
}
private unsafe void UnsafeWriteText(char* chars, int charCount)
{
// Callers should handle zero
- DiagnosticUtility.DebugAssert(charCount > 0, "");
+ Debug.Assert(charCount > 0);
if (charCount == 1)
{
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);
}
public override void WriteStartListText()
{
- DiagnosticUtility.DebugAssert(!_inList, "");
+ Debug.Assert(!_inList);
_inList = true;
WriteNode(XmlBinaryNodeType.StartListText);
}
public override void WriteEndListText()
{
- DiagnosticUtility.DebugAssert(_inList, "");
+ Debug.Assert(_inList);
_inList = false;
_wroteAttributeValue = true;
WriteNode(XmlBinaryNodeType.EndListText);
{
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;
}
{
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;
}
{
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)
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);
{
if (_stream == null)
return false;
- DiagnosticUtility.DebugAssert(_offsetMax < _windowOffsetMax, "");
+ Debug.Assert(_offsetMax < _windowOffsetMax);
if (_offsetMax >= _buffer.Length)
return TryEnsureBytes(1);
int b = _stream.ReadByte();
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.
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)];
_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;
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];
}
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);
}
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);
}
}
}
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);
}
}
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++)
{
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++)
{
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);
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':
{
XmlBinaryNodeType nodeType = GetNodeType();
SkipNodeType();
- DiagnosticUtility.DebugAssert(nodeType != XmlBinaryNodeType.StartListText, "");
+ Debug.Assert(nodeType != XmlBinaryNodeType.StartListText);
ReadValue(nodeType, _listValue!);
objects[i] = _listValue!.ToObject();
}
{
if (inclusivePrefixes[i] == null)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.InvalidInclusivePrefixListCollection);
+ throw new ArgumentException(SR.InvalidInclusivePrefixListCollection);
}
_inclusivePrefixes[i] = inclusivePrefixes[i];
}
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);
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;
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;
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;
{
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)
{
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);
{
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);
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)
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
catch (ArgumentException exception)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(ToString(value), "DateTime", exception));
+ throw XmlExceptionHelper.CreateConversionException(ToString(value), "DateTime", exception);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
catch (DecoderFallbackException exception)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception));
+ throw XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception);
}
}
}
catch (DecoderFallbackException exception)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception));
+ throw XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception);
}
}
}
catch (DecoderFallbackException exception)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(value, exception));
+ throw XmlExceptionHelper.CreateEncodingException(value, exception);
}
}
}
catch (DecoderFallbackException exception)
{
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception));
+ throw XmlExceptionHelper.CreateEncodingException(buffer, offset, count, exception);
}
}
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();
}
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);
}
{
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;
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';
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;
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';
chars[offset++] = (byte)'Z';
break;
default:
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException());
+ throw new InvalidOperationException();
}
return offset - offsetMin;
}
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()
{
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;
{
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;
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()
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;
}
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();
{
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;
{
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;
}
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
}
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
}
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
{
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)
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
ArgumentNullException.ThrowIfNull(quotas);
if (quotas._readOnly)
- throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.QuotaCopyReadOnly));
+ throw new InvalidOperationException(SR.QuotaCopyReadOnly);
InternalCopyTo(quotas);
}
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;
}
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;
}
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;
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;
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;
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;
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];
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)
{
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
s += " " + SR.Format(SR.XmlLineInfo, lineInfo.LineNumber, lineInfo.LinePosition);
}
- throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(s));
+ throw new XmlException(s);
}
[DoesNotReturn]
{
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)
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();
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)
{
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)
{
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);
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);
using System.Text;
using System.Runtime.Serialization;
using System.Threading.Tasks;
+using System.Diagnostics;
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)
{
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)'<';
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)
{
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)'<';
protected void Advance(int count)
{
- DiagnosticUtility.DebugAssert(_offset + count <= bufferLength, "");
+ Debug.Assert(_offset + count <= bufferLength);
_offset += count;
}
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);
}
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);
}
{
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);
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()
// 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))
{
private int ReadCharRef()
{
- DiagnosticUtility.DebugAssert(BufferReader.GetByte() == '&', "");
+ Debug.Assert(BufferReader.GetByte() == '&');
int charEntityOffset = BufferReader.Offset;
BufferReader.SkipByte();
while (BufferReader.GetByte() != ';')