| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Buffers; |
| | | 5 | | using System.Collections; |
| | | 6 | | using System.Collections.Generic; |
| | | 7 | | using System.Diagnostics; |
| | | 8 | | using System.Diagnostics.CodeAnalysis; |
| | | 9 | | using System.Globalization; |
| | | 10 | | using System.IO.Pipelines; |
| | | 11 | | using System.Reflection; |
| | | 12 | | using System.Text.Json.Serialization; |
| | | 13 | | using System.Text.Json.Serialization.Metadata; |
| | | 14 | | |
| | | 15 | | namespace System.Text.Json |
| | | 16 | | { |
| | | 17 | | internal static partial class ThrowHelper |
| | | 18 | | { |
| | | 19 | | [DoesNotReturn] |
| | | 20 | | public static void ThrowArgumentException_DeserializeWrongType(Type type, object value) |
| | 0 | 21 | | { |
| | 0 | 22 | | throw new ArgumentException(SR.Format(SR.DeserializeWrongType, type, value.GetType())); |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | [DoesNotReturn] |
| | | 26 | | public static void ThrowArgumentException_SerializerDoesNotSupportComments(string paramName) |
| | 0 | 27 | | { |
| | 0 | 28 | | throw new ArgumentException(SR.JsonSerializerDoesNotSupportComments, paramName); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | [DoesNotReturn] |
| | | 32 | | public static void ThrowNotSupportedException_SerializationNotSupported(Type propertyType) |
| | 0 | 33 | | { |
| | 0 | 34 | | throw new NotSupportedException(SR.Format(SR.SerializationNotSupportedType, propertyType)); |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | [DoesNotReturn] |
| | | 38 | | public static void ThrowNotSupportedException_TypeRequiresAsyncSerialization(Type propertyType) |
| | 0 | 39 | | { |
| | 0 | 40 | | throw new NotSupportedException(SR.Format(SR.TypeRequiresAsyncSerialization, propertyType)); |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | [DoesNotReturn] |
| | | 44 | | public static void ThrowNotSupportedException_DictionaryKeyTypeNotSupported(Type keyType, JsonConverter converte |
| | 0 | 45 | | { |
| | 0 | 46 | | throw new NotSupportedException(SR.Format(SR.DictionaryKeyTypeNotSupported, keyType, converter.GetType())); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | [DoesNotReturn] |
| | | 50 | | public static void ThrowJsonException_DeserializeUnableToConvertValue(Type propertyType) |
| | 1434 | 51 | | { |
| | 1434 | 52 | | throw new JsonException(SR.Format(SR.DeserializeUnableToConvertValue, propertyType)) { AppendPathInformation |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | [DoesNotReturn] |
| | | 56 | | public static void ThrowInvalidCastException_DeserializeUnableToAssignValue(Type typeOfValue, Type declaredType) |
| | 0 | 57 | | { |
| | 0 | 58 | | throw new InvalidCastException(SR.Format(SR.DeserializeUnableToAssignValue, typeOfValue, declaredType)); |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | [DoesNotReturn] |
| | | 62 | | public static void ThrowInvalidOperationException_DeserializeUnableToAssignNull(Type declaredType) |
| | 0 | 63 | | { |
| | 0 | 64 | | throw new InvalidOperationException(SR.Format(SR.DeserializeUnableToAssignNull, declaredType)); |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | [DoesNotReturn] |
| | | 68 | | public static void ThrowJsonException_PropertyGetterDisallowNull(string propertyName, Type declaringType) |
| | 0 | 69 | | { |
| | 0 | 70 | | throw new JsonException(SR.Format(SR.PropertyGetterDisallowNull, propertyName, declaringType)) { AppendPathI |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | [DoesNotReturn] |
| | | 74 | | public static void ThrowJsonException_PropertySetterDisallowNull(string propertyName, Type declaringType) |
| | 0 | 75 | | { |
| | 0 | 76 | | throw new JsonException(SR.Format(SR.PropertySetterDisallowNull, propertyName, declaringType)) { AppendPathI |
| | | 77 | | } |
| | | 78 | | |
| | | 79 | | [DoesNotReturn] |
| | | 80 | | public static void ThrowJsonException_ConstructorParameterDisallowNull(string parameterName, Type declaringType) |
| | 0 | 81 | | { |
| | 0 | 82 | | throw new JsonException(SR.Format(SR.ConstructorParameterDisallowNull, parameterName, declaringType)) { Appe |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | [DoesNotReturn] |
| | | 86 | | public static void ThrowInvalidOperationException_ObjectCreationHandlingPopulateNotSupportedByConverter(JsonProp |
| | 0 | 87 | | { |
| | 0 | 88 | | throw new InvalidOperationException(SR.Format(SR.ObjectCreationHandlingPopulateNotSupportedByConverter, prop |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | [DoesNotReturn] |
| | | 92 | | public static void ThrowInvalidOperationException_ObjectCreationHandlingPropertyMustHaveAGetter(JsonPropertyInfo |
| | 0 | 93 | | { |
| | 0 | 94 | | throw new InvalidOperationException(SR.Format(SR.ObjectCreationHandlingPropertyMustHaveAGetter, propertyInfo |
| | | 95 | | } |
| | | 96 | | |
| | | 97 | | [DoesNotReturn] |
| | | 98 | | public static void ThrowInvalidOperationException_ObjectCreationHandlingPropertyValueTypeMustHaveASetter(JsonPro |
| | 0 | 99 | | { |
| | 0 | 100 | | throw new InvalidOperationException(SR.Format(SR.ObjectCreationHandlingPropertyValueTypeMustHaveASetter, pro |
| | | 101 | | } |
| | | 102 | | |
| | | 103 | | [DoesNotReturn] |
| | | 104 | | public static void ThrowInvalidOperationException_ObjectCreationHandlingPropertyCannotAllowPolymorphicDeserializ |
| | 0 | 105 | | { |
| | 0 | 106 | | throw new InvalidOperationException(SR.Format(SR.ObjectCreationHandlingPropertyCannotAllowPolymorphicDeseria |
| | | 107 | | } |
| | | 108 | | |
| | | 109 | | [DoesNotReturn] |
| | | 110 | | public static void ThrowInvalidOperationException_ObjectCreationHandlingPropertyCannotAllowReadOnlyMember(JsonPr |
| | 0 | 111 | | { |
| | 0 | 112 | | throw new InvalidOperationException(SR.Format(SR.ObjectCreationHandlingPropertyCannotAllowReadOnlyMember, pr |
| | | 113 | | } |
| | | 114 | | |
| | | 115 | | [DoesNotReturn] |
| | | 116 | | public static void ThrowInvalidOperationException_ObjectCreationHandlingPropertyCannotAllowReferenceHandling() |
| | 0 | 117 | | { |
| | 0 | 118 | | throw new InvalidOperationException(SR.ObjectCreationHandlingPropertyCannotAllowReferenceHandling); |
| | | 119 | | } |
| | | 120 | | |
| | | 121 | | [DoesNotReturn] |
| | | 122 | | public static void ThrowNotSupportedException_ObjectCreationHandlingPropertyDoesNotSupportParameterizedConstruct |
| | 0 | 123 | | { |
| | 0 | 124 | | throw new NotSupportedException(SR.ObjectCreationHandlingPropertyDoesNotSupportParameterizedConstructors); |
| | | 125 | | } |
| | | 126 | | |
| | | 127 | | [DoesNotReturn] |
| | | 128 | | public static void ThrowJsonException_SerializationConverterRead(JsonConverter? converter) |
| | 0 | 129 | | { |
| | 0 | 130 | | throw new JsonException(SR.Format(SR.SerializationConverterRead, converter)) { AppendPathInformation = true |
| | | 131 | | } |
| | | 132 | | |
| | | 133 | | [DoesNotReturn] |
| | | 134 | | public static void ThrowJsonException_SerializationConverterWrite(JsonConverter? converter) |
| | 0 | 135 | | { |
| | 0 | 136 | | throw new JsonException(SR.Format(SR.SerializationConverterWrite, converter)) { AppendPathInformation = true |
| | | 137 | | } |
| | | 138 | | |
| | | 139 | | [DoesNotReturn] |
| | | 140 | | public static void ThrowJsonException_SerializerCycleDetected(int maxDepth) |
| | 0 | 141 | | { |
| | 0 | 142 | | throw new JsonException(SR.Format(SR.SerializerCycleDetected, maxDepth)) { AppendPathInformation = true }; |
| | | 143 | | } |
| | | 144 | | |
| | | 145 | | [DoesNotReturn] |
| | | 146 | | public static void ThrowJsonException(string? message = null) |
| | 1128 | 147 | | { |
| | 1128 | 148 | | throw new JsonException(message) { AppendPathInformation = true }; |
| | | 149 | | } |
| | | 150 | | |
| | | 151 | | [DoesNotReturn] |
| | | 152 | | public static void ThrowArgumentException_CannotSerializeInvalidType(string paramName, Type typeToConvert, Type? |
| | 0 | 153 | | { |
| | 0 | 154 | | if (declaringType == null) |
| | 0 | 155 | | { |
| | 0 | 156 | | Debug.Assert(propertyName == null); |
| | 0 | 157 | | throw new ArgumentException(SR.Format(SR.CannotSerializeInvalidType, typeToConvert), paramName); |
| | | 158 | | } |
| | | 159 | | |
| | 0 | 160 | | Debug.Assert(propertyName != null); |
| | 0 | 161 | | throw new ArgumentException(SR.Format(SR.CannotSerializeInvalidMember, typeToConvert, propertyName, declarin |
| | | 162 | | } |
| | | 163 | | |
| | | 164 | | [DoesNotReturn] |
| | | 165 | | public static void ThrowInvalidOperationException_CannotSerializeInvalidType(Type typeToConvert, Type? declaring |
| | 0 | 166 | | { |
| | 0 | 167 | | if (declaringType == null) |
| | 0 | 168 | | { |
| | 0 | 169 | | Debug.Assert(memberInfo == null); |
| | 0 | 170 | | throw new InvalidOperationException(SR.Format(SR.CannotSerializeInvalidType, typeToConvert)); |
| | | 171 | | } |
| | | 172 | | |
| | 0 | 173 | | Debug.Assert(memberInfo != null); |
| | 0 | 174 | | throw new InvalidOperationException(SR.Format(SR.CannotSerializeInvalidMember, typeToConvert, memberInfo.Nam |
| | | 175 | | } |
| | | 176 | | |
| | | 177 | | [DoesNotReturn] |
| | | 178 | | public static void ThrowInvalidOperationException_SerializationConverterNotCompatible(Type converterType, Type t |
| | 0 | 179 | | { |
| | 0 | 180 | | throw new InvalidOperationException(SR.Format(SR.SerializationConverterNotCompatible, converterType, type)); |
| | | 181 | | } |
| | | 182 | | |
| | | 183 | | [DoesNotReturn] |
| | | 184 | | public static void ThrowInvalidOperationException_ResolverTypeNotCompatible(Type requestedType, Type actualType) |
| | 0 | 185 | | { |
| | 0 | 186 | | throw new InvalidOperationException(SR.Format(SR.ResolverTypeNotCompatible, actualType, requestedType)); |
| | | 187 | | } |
| | | 188 | | |
| | | 189 | | [DoesNotReturn] |
| | | 190 | | public static void ThrowInvalidOperationException_ResolverTypeInfoOptionsNotCompatible() |
| | 0 | 191 | | { |
| | 0 | 192 | | throw new InvalidOperationException(SR.ResolverTypeInfoOptionsNotCompatible); |
| | | 193 | | } |
| | | 194 | | |
| | | 195 | | [DoesNotReturn] |
| | | 196 | | public static void ThrowInvalidOperationException_JsonSerializerOptionsNoTypeInfoResolverSpecified() |
| | 0 | 197 | | { |
| | 0 | 198 | | throw new InvalidOperationException(SR.JsonSerializerOptionsNoTypeInfoResolverSpecified); |
| | | 199 | | } |
| | | 200 | | |
| | | 201 | | [DoesNotReturn] |
| | | 202 | | public static void ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled() |
| | 0 | 203 | | { |
| | 0 | 204 | | throw new InvalidOperationException(SR.JsonSerializerIsReflectionDisabled); |
| | | 205 | | } |
| | | 206 | | |
| | | 207 | | [DoesNotReturn] |
| | | 208 | | public static void ThrowInvalidOperationException_SerializationConverterOnAttributeInvalid(Type classType, Membe |
| | 0 | 209 | | { |
| | 0 | 210 | | string location = classType.ToString(); |
| | 0 | 211 | | if (memberInfo != null) |
| | 0 | 212 | | { |
| | 0 | 213 | | location += $".{memberInfo.Name}"; |
| | 0 | 214 | | } |
| | | 215 | | |
| | 0 | 216 | | throw new InvalidOperationException(SR.Format(SR.SerializationConverterOnAttributeInvalid, location)); |
| | | 217 | | } |
| | | 218 | | |
| | | 219 | | [DoesNotReturn] |
| | | 220 | | public static void ThrowInvalidOperationException_SerializationConverterOnAttributeNotCompatible(Type classTypeA |
| | 0 | 221 | | { |
| | 0 | 222 | | string location = classTypeAttributeIsOn.ToString(); |
| | | 223 | | |
| | 0 | 224 | | if (memberInfo != null) |
| | 0 | 225 | | { |
| | 0 | 226 | | location += $".{memberInfo.Name}"; |
| | 0 | 227 | | } |
| | | 228 | | |
| | 0 | 229 | | throw new InvalidOperationException(SR.Format(SR.SerializationConverterOnAttributeNotCompatible, location, t |
| | | 230 | | } |
| | | 231 | | |
| | | 232 | | [DoesNotReturn] |
| | | 233 | | public static void ThrowInvalidOperationException_SerializerOptionsReadOnly(JsonSerializerContext? context) |
| | 0 | 234 | | { |
| | 0 | 235 | | string message = context == null |
| | 0 | 236 | | ? SR.SerializerOptionsReadOnly |
| | 0 | 237 | | : SR.SerializerContextOptionsReadOnly; |
| | | 238 | | |
| | 0 | 239 | | throw new InvalidOperationException(message); |
| | | 240 | | } |
| | | 241 | | |
| | | 242 | | [DoesNotReturn] |
| | | 243 | | public static void ThrowInvalidOperationException_DefaultTypeInfoResolverImmutable() |
| | 0 | 244 | | { |
| | 0 | 245 | | throw new InvalidOperationException(SR.DefaultTypeInfoResolverImmutable); |
| | | 246 | | } |
| | | 247 | | |
| | | 248 | | [DoesNotReturn] |
| | | 249 | | public static void ThrowInvalidOperationException_TypeInfoResolverChainImmutable() |
| | 0 | 250 | | { |
| | 0 | 251 | | throw new InvalidOperationException(SR.TypeInfoResolverChainImmutable); |
| | | 252 | | } |
| | | 253 | | |
| | | 254 | | [DoesNotReturn] |
| | | 255 | | public static void ThrowInvalidOperationException_TypeInfoImmutable() |
| | 0 | 256 | | { |
| | 0 | 257 | | throw new InvalidOperationException(SR.TypeInfoImmutable); |
| | | 258 | | } |
| | | 259 | | |
| | | 260 | | [DoesNotReturn] |
| | | 261 | | public static void ThrowInvalidOperationException_InvalidChainedResolver() |
| | 0 | 262 | | { |
| | 0 | 263 | | throw new InvalidOperationException(SR.SerializerOptions_InvalidChainedResolver); |
| | | 264 | | } |
| | | 265 | | |
| | | 266 | | [DoesNotReturn] |
| | | 267 | | public static void ThrowInvalidOperationException_SerializerPropertyNameConflict(Type type, string propertyName) |
| | 0 | 268 | | { |
| | 0 | 269 | | throw new InvalidOperationException(SR.Format(SR.SerializerPropertyNameConflict, type, propertyName)); |
| | | 270 | | } |
| | | 271 | | |
| | | 272 | | [DoesNotReturn] |
| | | 273 | | public static void ThrowInvalidOperationException_SerializerPropertyNameNull(JsonPropertyInfo jsonPropertyInfo) |
| | 0 | 274 | | { |
| | 0 | 275 | | throw new InvalidOperationException(SR.Format(SR.SerializerPropertyNameNull, jsonPropertyInfo.DeclaringType, |
| | | 276 | | } |
| | | 277 | | |
| | | 278 | | [DoesNotReturn] |
| | | 279 | | public static void ThrowInvalidOperationException_JsonPropertyRequiredAndNotDeserializable(JsonPropertyInfo json |
| | 0 | 280 | | { |
| | 0 | 281 | | throw new InvalidOperationException(SR.Format(SR.JsonPropertyRequiredAndNotDeserializable, jsonPropertyInfo. |
| | | 282 | | } |
| | | 283 | | |
| | | 284 | | [DoesNotReturn] |
| | | 285 | | public static void ThrowInvalidOperationException_JsonPropertyRequiredAndExtensionData(JsonPropertyInfo jsonProp |
| | 0 | 286 | | { |
| | 0 | 287 | | throw new InvalidOperationException(SR.Format(SR.JsonPropertyRequiredAndExtensionData, jsonPropertyInfo.Name |
| | | 288 | | } |
| | | 289 | | |
| | | 290 | | [DoesNotReturn] |
| | | 291 | | public static void ThrowJsonException_JsonRequiredPropertyMissing(JsonTypeInfo parent, BitArray assignedOrNotReq |
| | 0 | 292 | | { |
| | 0 | 293 | | StringBuilder listOfMissingPropertiesBuilder = new(); |
| | 0 | 294 | | bool first = true; |
| | | 295 | | |
| | | 296 | | // Soft cut-off length - once message becomes longer than that we won't be adding more elements |
| | | 297 | | const int CutOffLength = 60; |
| | | 298 | | |
| | 0 | 299 | | foreach (JsonPropertyInfo property in parent.PropertyCache) |
| | 0 | 300 | | { |
| | 0 | 301 | | if (assignedOrNotRequiredPropertiesSet[property.PropertyIndex]) |
| | 0 | 302 | | { |
| | 0 | 303 | | continue; |
| | | 304 | | } |
| | | 305 | | |
| | 0 | 306 | | if (!first) |
| | 0 | 307 | | { |
| | 0 | 308 | | listOfMissingPropertiesBuilder.Append(CultureInfo.CurrentUICulture.TextInfo.ListSeparator); |
| | 0 | 309 | | listOfMissingPropertiesBuilder.Append(' '); |
| | 0 | 310 | | } |
| | | 311 | | |
| | 0 | 312 | | listOfMissingPropertiesBuilder.Append('\''); |
| | 0 | 313 | | listOfMissingPropertiesBuilder.Append(property.Name); |
| | 0 | 314 | | listOfMissingPropertiesBuilder.Append('\''); |
| | 0 | 315 | | first = false; |
| | | 316 | | |
| | 0 | 317 | | if (listOfMissingPropertiesBuilder.Length >= CutOffLength) |
| | 0 | 318 | | { |
| | 0 | 319 | | break; |
| | | 320 | | } |
| | 0 | 321 | | } |
| | | 322 | | |
| | 0 | 323 | | throw new JsonException(SR.Format(SR.JsonRequiredPropertiesMissing, parent.Type, listOfMissingPropertiesBuil |
| | | 324 | | } |
| | | 325 | | |
| | | 326 | | [DoesNotReturn] |
| | | 327 | | public static void ThrowJsonException_DuplicatePropertyNotAllowed(JsonPropertyInfo property) |
| | 0 | 328 | | { |
| | 0 | 329 | | throw new JsonException(SR.Format(SR.DuplicatePropertiesNotAllowed_JsonPropertyInfo, property.Name, property |
| | | 330 | | } |
| | | 331 | | |
| | | 332 | | [DoesNotReturn] |
| | | 333 | | public static void ThrowJsonException_DuplicatePropertyNotAllowed() |
| | 0 | 334 | | { |
| | 0 | 335 | | throw new JsonException(SR.DuplicatePropertiesNotAllowed); |
| | | 336 | | } |
| | | 337 | | |
| | | 338 | | [DoesNotReturn] |
| | | 339 | | public static void ThrowJsonException_DuplicatePropertyNotAllowed(string name) |
| | 0 | 340 | | { |
| | 0 | 341 | | throw new JsonException(SR.Format(SR.DuplicatePropertiesNotAllowed_NameSpan, Truncate(name))); |
| | | 342 | | } |
| | | 343 | | |
| | | 344 | | [DoesNotReturn] |
| | | 345 | | public static void ThrowJsonException_DuplicatePropertyNotAllowed(ReadOnlySpan<byte> nameBytes) |
| | 0 | 346 | | { |
| | 0 | 347 | | string name = Encoding.UTF8.GetString(nameBytes); |
| | 0 | 348 | | throw new JsonException(SR.Format(SR.DuplicatePropertiesNotAllowed_NameSpan, Truncate(name))); |
| | | 349 | | } |
| | | 350 | | |
| | | 351 | | private static string Truncate(ReadOnlySpan<char> str) |
| | 0 | 352 | | { |
| | | 353 | | const int MaxLength = 15; |
| | | 354 | | |
| | 0 | 355 | | if (str.Length <= MaxLength) |
| | 0 | 356 | | { |
| | 0 | 357 | | return str.ToString(); |
| | | 358 | | } |
| | | 359 | | |
| | 0 | 360 | | Span<char> builder = stackalloc char[MaxLength + 3]; |
| | 0 | 361 | | str.Slice(0, MaxLength).CopyTo(builder); |
| | 0 | 362 | | builder[MaxLength] = builder[MaxLength + 1] = builder[MaxLength + 2] = '.'; |
| | 0 | 363 | | return builder.ToString(); |
| | 0 | 364 | | } |
| | | 365 | | |
| | | 366 | | [DoesNotReturn] |
| | | 367 | | public static void ThrowInvalidOperationException_NamingPolicyReturnNull(JsonNamingPolicy namingPolicy) |
| | 0 | 368 | | { |
| | 0 | 369 | | throw new InvalidOperationException(SR.Format(SR.NamingPolicyReturnNull, namingPolicy)); |
| | | 370 | | } |
| | | 371 | | |
| | | 372 | | [DoesNotReturn] |
| | | 373 | | public static void ThrowInvalidOperationException_SerializerConverterFactoryReturnsNull(Type converterType) |
| | 0 | 374 | | { |
| | 0 | 375 | | throw new InvalidOperationException(SR.Format(SR.SerializerConverterFactoryReturnsNull, converterType)); |
| | | 376 | | } |
| | | 377 | | |
| | | 378 | | [DoesNotReturn] |
| | | 379 | | public static void ThrowInvalidOperationException_SerializerConverterFactoryReturnsJsonConverterFactory(Type con |
| | 0 | 380 | | { |
| | 0 | 381 | | throw new InvalidOperationException(SR.Format(SR.SerializerConverterFactoryReturnsJsonConverterFactory, conv |
| | | 382 | | } |
| | | 383 | | |
| | | 384 | | [DoesNotReturn] |
| | | 385 | | public static void ThrowInvalidOperationException_MultiplePropertiesBindToConstructorParameters( |
| | | 386 | | Type parentType, |
| | | 387 | | string parameterName, |
| | | 388 | | string firstMatchName, |
| | | 389 | | string secondMatchName) |
| | 0 | 390 | | { |
| | 0 | 391 | | throw new InvalidOperationException( |
| | 0 | 392 | | SR.Format( |
| | 0 | 393 | | SR.MultipleMembersBindWithConstructorParameter, |
| | 0 | 394 | | firstMatchName, |
| | 0 | 395 | | secondMatchName, |
| | 0 | 396 | | parentType, |
| | 0 | 397 | | parameterName)); |
| | | 398 | | } |
| | | 399 | | |
| | | 400 | | [DoesNotReturn] |
| | | 401 | | public static void ThrowInvalidOperationException_ConstructorParameterIncompleteBinding(Type parentType) |
| | 0 | 402 | | { |
| | 0 | 403 | | throw new InvalidOperationException(SR.Format(SR.ConstructorParamIncompleteBinding, parentType)); |
| | | 404 | | } |
| | | 405 | | |
| | | 406 | | [DoesNotReturn] |
| | | 407 | | public static void ThrowInvalidOperationException_ExtensionDataCannotBindToCtorParam(string propertyName, JsonPr |
| | 0 | 408 | | { |
| | 0 | 409 | | throw new InvalidOperationException(SR.Format(SR.ExtensionDataCannotBindToCtorParam, propertyName, jsonPrope |
| | | 410 | | } |
| | | 411 | | |
| | | 412 | | [DoesNotReturn] |
| | | 413 | | public static void ThrowInvalidOperationException_JsonIncludeOnInaccessibleProperty(string memberName, Type decl |
| | 0 | 414 | | { |
| | 0 | 415 | | throw new InvalidOperationException(SR.Format(SR.JsonIncludeOnInaccessibleProperty, memberName, declaringTyp |
| | | 416 | | } |
| | | 417 | | |
| | | 418 | | [DoesNotReturn] |
| | | 419 | | public static void ThrowInvalidOperationException_IgnoreConditionOnValueTypeInvalid(string clrPropertyName, Type |
| | 0 | 420 | | { |
| | 0 | 421 | | throw new InvalidOperationException(SR.Format(SR.IgnoreConditionOnValueTypeInvalid, clrPropertyName, propert |
| | | 422 | | } |
| | | 423 | | |
| | | 424 | | [DoesNotReturn] |
| | | 425 | | public static void ThrowInvalidOperationException_NumberHandlingOnPropertyInvalid(JsonPropertyInfo jsonPropertyI |
| | 0 | 426 | | { |
| | 0 | 427 | | Debug.Assert(!jsonPropertyInfo.IsForTypeInfo); |
| | 0 | 428 | | throw new InvalidOperationException(SR.Format(SR.NumberHandlingOnPropertyInvalid, jsonPropertyInfo.MemberNam |
| | | 429 | | } |
| | | 430 | | |
| | | 431 | | [DoesNotReturn] |
| | | 432 | | public static void ThrowInvalidOperationException_ConverterCanConvertMultipleTypes(Type runtimePropertyType, Jso |
| | 0 | 433 | | { |
| | 0 | 434 | | throw new InvalidOperationException(SR.Format(SR.ConverterCanConvertMultipleTypes, jsonConverter.GetType(), |
| | | 435 | | } |
| | | 436 | | |
| | | 437 | | [DoesNotReturn] |
| | | 438 | | public static void ThrowNotSupportedException_ObjectWithParameterizedCtorRefMetadataNotSupported( |
| | | 439 | | ReadOnlySpan<byte> propertyName, |
| | | 440 | | ref Utf8JsonReader reader, |
| | | 441 | | scoped ref ReadStack state) |
| | 0 | 442 | | { |
| | 0 | 443 | | JsonTypeInfo jsonTypeInfo = state.GetTopJsonTypeInfoWithParameterizedConstructor(); |
| | 0 | 444 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | | 445 | | |
| | 0 | 446 | | NotSupportedException ex = new NotSupportedException( |
| | 0 | 447 | | SR.Format(SR.ObjectWithParameterizedCtorRefMetadataNotSupported, jsonTypeInfo.Type)); |
| | 0 | 448 | | ThrowNotSupportedException(ref state, reader, ex); |
| | | 449 | | } |
| | | 450 | | |
| | | 451 | | [DoesNotReturn] |
| | | 452 | | public static void ThrowInvalidOperationException_JsonTypeInfoOperationNotPossibleForKind(JsonTypeInfoKind kind) |
| | 0 | 453 | | { |
| | 0 | 454 | | throw new InvalidOperationException(SR.Format(SR.InvalidJsonTypeInfoOperationForKind, kind)); |
| | | 455 | | } |
| | | 456 | | |
| | | 457 | | [DoesNotReturn] |
| | | 458 | | public static void ThrowInvalidOperationException_JsonTypeInfoOnDeserializingCallbacksNotSupported(Type type) |
| | 0 | 459 | | { |
| | 0 | 460 | | throw new InvalidOperationException(SR.Format(SR.OnDeserializingCallbacksNotSupported, type)); |
| | | 461 | | } |
| | | 462 | | |
| | | 463 | | [DoesNotReturn] |
| | | 464 | | public static void ThrowInvalidOperationException_CreateObjectConverterNotCompatible(Type type) |
| | 0 | 465 | | { |
| | 0 | 466 | | throw new InvalidOperationException(SR.Format(SR.CreateObjectConverterNotCompatible, type)); |
| | | 467 | | } |
| | | 468 | | |
| | | 469 | | [DoesNotReturn] |
| | | 470 | | public static void ReThrowWithPath(scoped ref ReadStack state, JsonReaderException ex) |
| | 35640 | 471 | | { |
| | 35640 | 472 | | Debug.Assert(ex.Path == null); |
| | | 473 | | |
| | 35640 | 474 | | string path = state.JsonPath(); |
| | 35640 | 475 | | string message = ex.Message; |
| | | 476 | | |
| | | 477 | | // Insert the "Path" portion before "LineNumber" and "BytePositionInLine". |
| | | 478 | | #if NET |
| | 35640 | 479 | | int iPos = message.AsSpan().LastIndexOf(" LineNumber: "); |
| | | 480 | | #else |
| | | 481 | | int iPos = message.LastIndexOf(" LineNumber: ", StringComparison.Ordinal); |
| | | 482 | | #endif |
| | 35640 | 483 | | if (iPos >= 0) |
| | 35640 | 484 | | { |
| | 35640 | 485 | | message = $"{message.Substring(0, iPos)} Path: {path} |{message.Substring(iPos)}"; |
| | 35640 | 486 | | } |
| | | 487 | | else |
| | 0 | 488 | | { |
| | 0 | 489 | | message += $" Path: {path}."; |
| | 0 | 490 | | } |
| | | 491 | | |
| | 35640 | 492 | | throw new JsonException(message, path, ex.LineNumber, ex.BytePositionInLine, ex); |
| | | 493 | | } |
| | | 494 | | |
| | | 495 | | [DoesNotReturn] |
| | | 496 | | public static void ReThrowWithPath(scoped ref ReadStack state, in Utf8JsonReader reader, Exception ex) |
| | 17526 | 497 | | { |
| | 17526 | 498 | | JsonException jsonException = new JsonException(null, ex); |
| | 17526 | 499 | | AddJsonExceptionInformation(ref state, reader, jsonException); |
| | 17526 | 500 | | throw jsonException; |
| | | 501 | | } |
| | | 502 | | |
| | | 503 | | public static void AddJsonExceptionInformation(scoped ref ReadStack state, in Utf8JsonReader reader, JsonExcepti |
| | 20088 | 504 | | { |
| | 20088 | 505 | | Debug.Assert(ex.Path is null); // do not overwrite existing path information |
| | | 506 | | |
| | 20088 | 507 | | long lineNumber = reader.CurrentState._lineNumber; |
| | 20088 | 508 | | ex.LineNumber = lineNumber; |
| | | 509 | | |
| | 20088 | 510 | | long bytePositionInLine = reader.CurrentState._bytePositionInLine; |
| | 20088 | 511 | | ex.BytePositionInLine = bytePositionInLine; |
| | | 512 | | |
| | 20088 | 513 | | string path = state.JsonPath(); |
| | 20088 | 514 | | ex.Path = path; |
| | | 515 | | |
| | 20088 | 516 | | string? message = ex._message; |
| | | 517 | | |
| | 20088 | 518 | | if (string.IsNullOrEmpty(message)) |
| | 18654 | 519 | | { |
| | | 520 | | // Use a default message. |
| | 18654 | 521 | | Type propertyType = state.Current.JsonPropertyInfo?.PropertyType ?? state.Current.JsonTypeInfo.Type; |
| | 18654 | 522 | | message = SR.Format(SR.DeserializeUnableToConvertValue, propertyType); |
| | 18654 | 523 | | ex.AppendPathInformation = true; |
| | 18654 | 524 | | } |
| | | 525 | | |
| | 20088 | 526 | | if (ex.AppendPathInformation) |
| | 20088 | 527 | | { |
| | 20088 | 528 | | message += $" Path: {path} | LineNumber: {lineNumber} | BytePositionInLine: {bytePositionInLine}."; |
| | 20088 | 529 | | ex.SetMessage(message); |
| | 20088 | 530 | | } |
| | 20088 | 531 | | } |
| | | 532 | | |
| | | 533 | | [DoesNotReturn] |
| | | 534 | | public static void ReThrowWithPath(ref WriteStack state, Exception ex) |
| | 0 | 535 | | { |
| | 0 | 536 | | JsonException jsonException = new JsonException(null, ex); |
| | 0 | 537 | | AddJsonExceptionInformation(ref state, jsonException); |
| | 0 | 538 | | throw jsonException; |
| | | 539 | | } |
| | | 540 | | |
| | | 541 | | public static void AddJsonExceptionInformation(ref WriteStack state, JsonException ex) |
| | 0 | 542 | | { |
| | 0 | 543 | | Debug.Assert(ex.Path is null); // do not overwrite existing path information |
| | | 544 | | |
| | 0 | 545 | | string path = state.PropertyPath(); |
| | 0 | 546 | | ex.Path = path; |
| | | 547 | | |
| | 0 | 548 | | string? message = ex._message; |
| | 0 | 549 | | if (string.IsNullOrEmpty(message)) |
| | 0 | 550 | | { |
| | | 551 | | // Use a default message. |
| | 0 | 552 | | message = SR.SerializeUnableToSerialize; |
| | 0 | 553 | | ex.AppendPathInformation = true; |
| | 0 | 554 | | } |
| | | 555 | | |
| | 0 | 556 | | if (ex.AppendPathInformation) |
| | 0 | 557 | | { |
| | 0 | 558 | | message += $" Path: {path}."; |
| | 0 | 559 | | ex.SetMessage(message); |
| | 0 | 560 | | } |
| | 0 | 561 | | } |
| | | 562 | | |
| | | 563 | | [DoesNotReturn] |
| | | 564 | | public static void ThrowInvalidOperationException_SerializationDuplicateAttribute(Type attribute, MemberInfo mem |
| | 0 | 565 | | { |
| | 0 | 566 | | string location = memberInfo is Type type ? type.ToString() : $"{memberInfo.DeclaringType}.{memberInfo.Name} |
| | 0 | 567 | | throw new InvalidOperationException(SR.Format(SR.SerializationDuplicateAttribute, attribute, location)); |
| | | 568 | | } |
| | | 569 | | |
| | | 570 | | [DoesNotReturn] |
| | | 571 | | public static void ThrowInvalidOperationException_SerializationDuplicateTypeAttribute(Type classType, Type attri |
| | 0 | 572 | | { |
| | 0 | 573 | | throw new InvalidOperationException(SR.Format(SR.SerializationDuplicateTypeAttribute, classType, attribute)) |
| | | 574 | | } |
| | | 575 | | |
| | | 576 | | [DoesNotReturn] |
| | | 577 | | public static void ThrowInvalidOperationException_SerializationDuplicateTypeAttribute<TAttribute>(Type classType |
| | 0 | 578 | | { |
| | 0 | 579 | | throw new InvalidOperationException(SR.Format(SR.SerializationDuplicateTypeAttribute, classType, typeof(TAtt |
| | | 580 | | } |
| | | 581 | | |
| | | 582 | | [DoesNotReturn] |
| | | 583 | | public static void ThrowInvalidOperationException_ExtensionDataConflictsWithUnmappedMemberHandling(Type classTyp |
| | 0 | 584 | | { |
| | 0 | 585 | | throw new InvalidOperationException(SR.Format(SR.ExtensionDataConflictsWithUnmappedMemberHandling, classType |
| | | 586 | | } |
| | | 587 | | |
| | | 588 | | [DoesNotReturn] |
| | | 589 | | public static void ThrowInvalidOperationException_SerializationDataExtensionPropertyInvalid(JsonPropertyInfo jso |
| | 0 | 590 | | { |
| | 0 | 591 | | throw new InvalidOperationException(SR.Format(SR.SerializationDataExtensionPropertyInvalid, jsonPropertyInfo |
| | | 592 | | } |
| | | 593 | | |
| | | 594 | | [DoesNotReturn] |
| | | 595 | | public static void ThrowInvalidOperationException_PropertyTypeNotNullable(JsonPropertyInfo jsonPropertyInfo) |
| | 0 | 596 | | { |
| | 0 | 597 | | throw new InvalidOperationException(SR.Format(SR.PropertyTypeNotNullable, jsonPropertyInfo.PropertyType)); |
| | | 598 | | } |
| | | 599 | | |
| | | 600 | | [DoesNotReturn] |
| | | 601 | | public static void ThrowInvalidOperationException_NodeJsonObjectCustomConverterNotAllowedOnExtensionProperty() |
| | 0 | 602 | | { |
| | 0 | 603 | | throw new InvalidOperationException(SR.NodeJsonObjectCustomConverterNotAllowedOnExtensionProperty); |
| | | 604 | | } |
| | | 605 | | |
| | | 606 | | [DoesNotReturn] |
| | | 607 | | public static void ThrowNotSupportedException(scoped ref ReadStack state, in Utf8JsonReader reader, Exception in |
| | 0 | 608 | | { |
| | 0 | 609 | | string message = innerException.Message; |
| | | 610 | | |
| | | 611 | | // The caller should check to ensure path is not already set. |
| | 0 | 612 | | Debug.Assert(!message.Contains(" Path: ")); |
| | | 613 | | |
| | | 614 | | // Obtain the type to show in the message. |
| | 0 | 615 | | Type propertyType = state.Current.JsonPropertyInfo?.PropertyType ?? state.Current.JsonTypeInfo.Type; |
| | | 616 | | |
| | 0 | 617 | | if (!message.Contains(propertyType.ToString())) |
| | 0 | 618 | | { |
| | 0 | 619 | | if (message.Length > 0) |
| | 0 | 620 | | { |
| | 0 | 621 | | message += " "; |
| | 0 | 622 | | } |
| | | 623 | | |
| | 0 | 624 | | message += SR.Format(SR.SerializationNotSupportedParentType, propertyType); |
| | 0 | 625 | | } |
| | | 626 | | |
| | 0 | 627 | | long lineNumber = reader.CurrentState._lineNumber; |
| | 0 | 628 | | long bytePositionInLine = reader.CurrentState._bytePositionInLine; |
| | 0 | 629 | | message += $" Path: {state.JsonPath()} | LineNumber: {lineNumber} | BytePositionInLine: {bytePositionInLine} |
| | | 630 | | |
| | 0 | 631 | | throw new NotSupportedException(message, innerException); |
| | | 632 | | } |
| | | 633 | | |
| | | 634 | | [DoesNotReturn] |
| | | 635 | | public static void ThrowNotSupportedException(ref WriteStack state, Exception innerException) |
| | 0 | 636 | | { |
| | 0 | 637 | | string message = innerException.Message; |
| | | 638 | | |
| | | 639 | | // The caller should check to ensure path is not already set. |
| | 0 | 640 | | Debug.Assert(!message.Contains(" Path: ")); |
| | | 641 | | |
| | | 642 | | // Obtain the type to show in the message. |
| | 0 | 643 | | Type propertyType = state.Current.JsonPropertyInfo?.PropertyType ?? state.Current.JsonTypeInfo.Type; |
| | | 644 | | |
| | 0 | 645 | | if (!message.Contains(propertyType.ToString())) |
| | 0 | 646 | | { |
| | 0 | 647 | | if (message.Length > 0) |
| | 0 | 648 | | { |
| | 0 | 649 | | message += " "; |
| | 0 | 650 | | } |
| | | 651 | | |
| | 0 | 652 | | message += SR.Format(SR.SerializationNotSupportedParentType, propertyType); |
| | 0 | 653 | | } |
| | | 654 | | |
| | 0 | 655 | | message += $" Path: {state.PropertyPath()}."; |
| | | 656 | | |
| | 0 | 657 | | throw new NotSupportedException(message, innerException); |
| | | 658 | | } |
| | | 659 | | |
| | | 660 | | [DoesNotReturn] |
| | | 661 | | public static void ThrowNotSupportedException_DeserializeNoConstructor(JsonTypeInfo typeInfo, ref Utf8JsonReader |
| | 0 | 662 | | { |
| | 0 | 663 | | Type type = typeInfo.Type; |
| | | 664 | | string message; |
| | | 665 | | |
| | 0 | 666 | | if (type.IsInterface || type.IsAbstract) |
| | 0 | 667 | | { |
| | 0 | 668 | | if (typeInfo.PolymorphicTypeResolver?.UsesTypeDiscriminators is true) |
| | 0 | 669 | | { |
| | 0 | 670 | | message = SR.Format(SR.DeserializationMustSpecifyTypeDiscriminator, type); |
| | 0 | 671 | | } |
| | 0 | 672 | | else if (typeInfo.Kind is JsonTypeInfoKind.Enumerable or JsonTypeInfoKind.Dictionary) |
| | 0 | 673 | | { |
| | 0 | 674 | | message = SR.Format(SR.CannotPopulateCollection, type); |
| | 0 | 675 | | } |
| | | 676 | | else |
| | 0 | 677 | | { |
| | 0 | 678 | | message = SR.Format(SR.DeserializeInterfaceOrAbstractType, type); |
| | 0 | 679 | | } |
| | 0 | 680 | | } |
| | | 681 | | else |
| | 0 | 682 | | { |
| | 0 | 683 | | message = SR.Format(SR.DeserializeNoConstructor, nameof(JsonConstructorAttribute), type); |
| | 0 | 684 | | } |
| | | 685 | | |
| | 0 | 686 | | ThrowNotSupportedException(ref state, reader, new NotSupportedException(message)); |
| | | 687 | | } |
| | | 688 | | |
| | | 689 | | [DoesNotReturn] |
| | | 690 | | public static void ThrowNotSupportedException_CannotPopulateCollection(Type type, ref Utf8JsonReader reader, sco |
| | 0 | 691 | | { |
| | 0 | 692 | | ThrowNotSupportedException(ref state, reader, new NotSupportedException(SR.Format(SR.CannotPopulateCollectio |
| | | 693 | | } |
| | | 694 | | |
| | | 695 | | [DoesNotReturn] |
| | | 696 | | public static void ThrowJsonException_MetadataValuesInvalidToken(JsonTokenType tokenType) |
| | 0 | 697 | | { |
| | 0 | 698 | | ThrowJsonException(SR.Format(SR.MetadataInvalidTokenAfterValues, tokenType)); |
| | | 699 | | } |
| | | 700 | | |
| | | 701 | | [DoesNotReturn] |
| | | 702 | | public static void ThrowJsonException_MetadataReferenceNotFound(string id) |
| | 0 | 703 | | { |
| | 0 | 704 | | ThrowJsonException(SR.Format(SR.MetadataReferenceNotFound, id)); |
| | | 705 | | } |
| | | 706 | | |
| | | 707 | | [DoesNotReturn] |
| | | 708 | | public static void ThrowJsonException_MetadataValueWasNotString(JsonTokenType tokenType) |
| | 0 | 709 | | { |
| | 0 | 710 | | ThrowJsonException(SR.Format(SR.MetadataValueWasNotString, tokenType)); |
| | | 711 | | } |
| | | 712 | | |
| | | 713 | | [DoesNotReturn] |
| | | 714 | | public static void ThrowJsonException_MetadataValueWasNotString(JsonValueKind valueKind) |
| | 0 | 715 | | { |
| | 0 | 716 | | ThrowJsonException(SR.Format(SR.MetadataValueWasNotString, valueKind)); |
| | | 717 | | } |
| | | 718 | | |
| | | 719 | | [DoesNotReturn] |
| | | 720 | | public static void ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties(ReadOnlySpan<byte> pro |
| | 0 | 721 | | { |
| | 0 | 722 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 723 | | ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties(); |
| | | 724 | | } |
| | | 725 | | |
| | | 726 | | [DoesNotReturn] |
| | | 727 | | public static void ThrowJsonException_MetadataUnexpectedProperty(ReadOnlySpan<byte> propertyName, scoped ref Rea |
| | 0 | 728 | | { |
| | 0 | 729 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 730 | | ThrowJsonException(SR.MetadataUnexpectedProperty); |
| | | 731 | | } |
| | | 732 | | |
| | | 733 | | [DoesNotReturn] |
| | | 734 | | public static void ThrowJsonException_UnmappedJsonProperty(Type type, string unmappedPropertyName) |
| | 0 | 735 | | { |
| | 0 | 736 | | throw new JsonException(SR.Format(SR.UnmappedJsonProperty, unmappedPropertyName, type)); |
| | | 737 | | } |
| | | 738 | | |
| | | 739 | | [DoesNotReturn] |
| | | 740 | | public static void ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties() |
| | 0 | 741 | | { |
| | 0 | 742 | | ThrowJsonException(SR.MetadataReferenceCannotContainOtherProperties); |
| | | 743 | | } |
| | | 744 | | |
| | | 745 | | [DoesNotReturn] |
| | | 746 | | public static void ThrowJsonException_MetadataIdCannotBeCombinedWithRef(ReadOnlySpan<byte> propertyName, scoped |
| | 0 | 747 | | { |
| | 0 | 748 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 749 | | ThrowJsonException(SR.MetadataIdCannotBeCombinedWithRef); |
| | | 750 | | } |
| | | 751 | | |
| | | 752 | | [DoesNotReturn] |
| | | 753 | | public static void ThrowJsonException_MetadataStandaloneValuesProperty(scoped ref ReadStack state, ReadOnlySpan< |
| | 0 | 754 | | { |
| | 0 | 755 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 756 | | ThrowJsonException(SR.MetadataStandaloneValuesProperty); |
| | | 757 | | } |
| | | 758 | | |
| | | 759 | | [DoesNotReturn] |
| | | 760 | | public static void ThrowJsonException_MetadataInvalidPropertyWithLeadingDollarSign(ReadOnlySpan<byte> propertyNa |
| | 0 | 761 | | { |
| | | 762 | | // Set PropertyInfo or KeyName to write down the conflicting property name in JsonException.Path |
| | 0 | 763 | | if (state.Current.IsProcessingDictionary()) |
| | 0 | 764 | | { |
| | 0 | 765 | | state.Current.JsonPropertyNameAsString = reader.GetString(); |
| | 0 | 766 | | } |
| | | 767 | | else |
| | 0 | 768 | | { |
| | 0 | 769 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 770 | | } |
| | | 771 | | |
| | 0 | 772 | | ThrowJsonException(SR.MetadataInvalidPropertyWithLeadingDollarSign); |
| | | 773 | | } |
| | | 774 | | |
| | | 775 | | [DoesNotReturn] |
| | | 776 | | public static void ThrowJsonException_MetadataDuplicateIdFound(string id) |
| | 0 | 777 | | { |
| | 0 | 778 | | ThrowJsonException(SR.Format(SR.MetadataDuplicateIdFound, id)); |
| | | 779 | | } |
| | | 780 | | |
| | | 781 | | [DoesNotReturn] |
| | | 782 | | public static void ThrowJsonException_DuplicateMetadataProperty(ReadOnlySpan<byte> utf8PropertyName) |
| | 0 | 783 | | { |
| | 0 | 784 | | ThrowJsonException(SR.Format(SR.DuplicateMetadataProperty, Encoding.UTF8.GetString(utf8PropertyName))); |
| | | 785 | | } |
| | | 786 | | |
| | | 787 | | [DoesNotReturn] |
| | | 788 | | public static void ThrowJsonException_MetadataInvalidReferenceToValueType(Type propertyType) |
| | 0 | 789 | | { |
| | 0 | 790 | | ThrowJsonException(SR.Format(SR.MetadataInvalidReferenceToValueType, propertyType)); |
| | | 791 | | } |
| | | 792 | | |
| | | 793 | | [DoesNotReturn] |
| | | 794 | | public static void ThrowJsonException_MetadataInvalidPropertyInArrayMetadata(scoped ref ReadStack state, Type pr |
| | 0 | 795 | | { |
| | 0 | 796 | | state.Current.JsonPropertyName = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan |
| | 0 | 797 | | string propertyNameAsString = reader.GetString()!; |
| | | 798 | | |
| | 0 | 799 | | ThrowJsonException(SR.Format(SR.MetadataPreservedArrayFailed, |
| | 0 | 800 | | SR.Format(SR.MetadataInvalidPropertyInArrayMetadata, propertyNameAsString), |
| | 0 | 801 | | SR.Format(SR.DeserializeUnableToConvertValue, propertyType))); |
| | | 802 | | } |
| | | 803 | | |
| | | 804 | | [DoesNotReturn] |
| | | 805 | | public static void ThrowJsonException_MetadataPreservedArrayValuesNotFound(scoped ref ReadStack state, Type prop |
| | 0 | 806 | | { |
| | | 807 | | // Missing $values, JSON path should point to the property's object. |
| | 0 | 808 | | state.Current.JsonPropertyName = null; |
| | | 809 | | |
| | 0 | 810 | | ThrowJsonException(SR.Format(SR.MetadataPreservedArrayFailed, |
| | 0 | 811 | | SR.MetadataStandaloneValuesProperty, |
| | 0 | 812 | | SR.Format(SR.DeserializeUnableToConvertValue, propertyType))); |
| | | 813 | | } |
| | | 814 | | |
| | | 815 | | [DoesNotReturn] |
| | | 816 | | public static void ThrowJsonException_MetadataCannotParsePreservedObjectIntoImmutable(Type propertyType) |
| | 0 | 817 | | { |
| | 0 | 818 | | ThrowJsonException(SR.Format(SR.MetadataCannotParsePreservedObjectToImmutable, propertyType)); |
| | | 819 | | } |
| | | 820 | | |
| | | 821 | | [DoesNotReturn] |
| | | 822 | | public static void ThrowInvalidOperationException_MetadataReferenceOfTypeCannotBeAssignedToType(string reference |
| | 0 | 823 | | { |
| | 0 | 824 | | throw new InvalidOperationException(SR.Format(SR.MetadataReferenceOfTypeCannotBeAssignedToType, referenceId, |
| | | 825 | | } |
| | | 826 | | |
| | | 827 | | [DoesNotReturn] |
| | | 828 | | public static void ThrowInvalidOperationException_JsonPropertyInfoIsBoundToDifferentJsonTypeInfo(JsonPropertyInf |
| | 0 | 829 | | { |
| | 0 | 830 | | Debug.Assert(propertyInfo.DeclaringTypeInfo != null, "We should not throw this exception when ParentTypeInfo |
| | 0 | 831 | | throw new InvalidOperationException(SR.Format(SR.JsonPropertyInfoBoundToDifferentParent, propertyInfo.Name, |
| | | 832 | | } |
| | | 833 | | |
| | | 834 | | [DoesNotReturn] |
| | | 835 | | internal static void ThrowUnexpectedMetadataException( |
| | | 836 | | ReadOnlySpan<byte> propertyName, |
| | | 837 | | ref Utf8JsonReader reader, |
| | | 838 | | scoped ref ReadStack state) |
| | 0 | 839 | | { |
| | | 840 | | |
| | 0 | 841 | | MetadataPropertyName name = JsonSerializer.GetMetadataPropertyName(propertyName, state.Current.BaseJsonTypeI |
| | 0 | 842 | | if (name != 0) |
| | 0 | 843 | | { |
| | 0 | 844 | | ThrowJsonException_MetadataUnexpectedProperty(propertyName, ref state); |
| | | 845 | | } |
| | | 846 | | else |
| | 0 | 847 | | { |
| | 0 | 848 | | ThrowJsonException_MetadataInvalidPropertyWithLeadingDollarSign(propertyName, ref state, reader); |
| | | 849 | | } |
| | | 850 | | } |
| | | 851 | | |
| | | 852 | | [DoesNotReturn] |
| | | 853 | | public static void ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver? resolver) |
| | 0 | 854 | | { |
| | 0 | 855 | | throw new NotSupportedException(SR.Format(SR.NoMetadataForType, type, resolver?.ToString() ?? "<null>")); |
| | | 856 | | } |
| | | 857 | | |
| | | 858 | | public static NotSupportedException GetNotSupportedException_AmbiguousMetadataForType(Type type, Type match1, Ty |
| | 0 | 859 | | { |
| | 0 | 860 | | return new NotSupportedException(SR.Format(SR.AmbiguousMetadataForType, type, match1, match2)); |
| | 0 | 861 | | } |
| | | 862 | | |
| | | 863 | | [DoesNotReturn] |
| | | 864 | | public static void ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type declaringType) |
| | 0 | 865 | | { |
| | 0 | 866 | | throw new NotSupportedException(SR.Format(SR.ConstructorContainsNullParameterNames, declaringType)); |
| | | 867 | | } |
| | | 868 | | |
| | | 869 | | [DoesNotReturn] |
| | | 870 | | public static void ThrowInvalidOperationException_NoMetadataForType(Type type, IJsonTypeInfoResolver? resolver) |
| | 0 | 871 | | { |
| | 0 | 872 | | throw new InvalidOperationException(SR.Format(SR.NoMetadataForType, type, resolver?.ToString() ?? "<null>")) |
| | | 873 | | } |
| | | 874 | | |
| | | 875 | | public static Exception GetInvalidOperationException_NoMetadataForTypeProperties(IJsonTypeInfoResolver? resolver |
| | 0 | 876 | | { |
| | 0 | 877 | | return new InvalidOperationException(SR.Format(SR.NoMetadataForTypeProperties, resolver?.ToString() ?? "<nul |
| | 0 | 878 | | } |
| | | 879 | | |
| | | 880 | | [DoesNotReturn] |
| | | 881 | | public static void ThrowInvalidOperationException_NoMetadataForTypeProperties(IJsonTypeInfoResolver? resolver, T |
| | 0 | 882 | | { |
| | 0 | 883 | | throw GetInvalidOperationException_NoMetadataForTypeProperties(resolver, type); |
| | | 884 | | } |
| | | 885 | | |
| | | 886 | | [DoesNotReturn] |
| | | 887 | | public static void ThrowMissingMemberException_MissingFSharpCoreMember(string missingFsharpCoreMember) |
| | 0 | 888 | | { |
| | 0 | 889 | | throw new MissingMemberException(SR.Format(SR.MissingFSharpCoreMember, missingFsharpCoreMember)); |
| | | 890 | | } |
| | | 891 | | |
| | | 892 | | [DoesNotReturn] |
| | | 893 | | public static void ThrowNotSupportedException_BaseConverterDoesNotSupportMetadata(Type derivedType) |
| | 0 | 894 | | { |
| | 0 | 895 | | throw new NotSupportedException(SR.Format(SR.Polymorphism_DerivedConverterDoesNotSupportMetadata, derivedTyp |
| | | 896 | | } |
| | | 897 | | |
| | | 898 | | [DoesNotReturn] |
| | | 899 | | public static void ThrowNotSupportedException_DerivedConverterDoesNotSupportMetadata(Type derivedType) |
| | 0 | 900 | | { |
| | 0 | 901 | | throw new NotSupportedException(SR.Format(SR.Polymorphism_DerivedConverterDoesNotSupportMetadata, derivedTyp |
| | | 902 | | } |
| | | 903 | | |
| | | 904 | | [DoesNotReturn] |
| | | 905 | | public static void ThrowNotSupportedException_RuntimeTypeNotSupported(Type baseType, Type runtimeType) |
| | 0 | 906 | | { |
| | 0 | 907 | | throw new NotSupportedException(SR.Format(SR.Polymorphism_RuntimeTypeNotSupported, runtimeType, baseType)); |
| | | 908 | | } |
| | | 909 | | |
| | | 910 | | [DoesNotReturn] |
| | | 911 | | public static void ThrowNotSupportedException_RuntimeTypeDiamondAmbiguity(Type baseType, Type runtimeType, Type |
| | 0 | 912 | | { |
| | 0 | 913 | | throw new NotSupportedException(SR.Format(SR.Polymorphism_RuntimeTypeDiamondAmbiguity, runtimeType, derivedT |
| | | 914 | | } |
| | | 915 | | |
| | | 916 | | [DoesNotReturn] |
| | | 917 | | public static void ThrowInvalidOperationException_TypeDoesNotSupportPolymorphism(Type baseType) |
| | 0 | 918 | | { |
| | 0 | 919 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_TypeDoesNotSupportPolymorphism, baseType)); |
| | | 920 | | } |
| | | 921 | | |
| | | 922 | | [DoesNotReturn] |
| | | 923 | | public static void ThrowInvalidOperationException_DerivedTypeNotSupported(Type baseType, Type derivedType) |
| | 0 | 924 | | { |
| | 0 | 925 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_DerivedTypeIsNotSupported, derivedType, baseTy |
| | | 926 | | } |
| | | 927 | | |
| | | 928 | | [DoesNotReturn] |
| | | 929 | | public static void ThrowInvalidOperationException_DerivedTypeIsAlreadySpecified(Type baseType, Type derivedType) |
| | 0 | 930 | | { |
| | 0 | 931 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_DerivedTypeIsAlreadySpecified, baseType, deriv |
| | | 932 | | } |
| | | 933 | | |
| | | 934 | | [DoesNotReturn] |
| | | 935 | | public static void ThrowInvalidOperationException_TypeDicriminatorIdIsAlreadySpecified(Type baseType, object typ |
| | 0 | 936 | | { |
| | 0 | 937 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_TypeDicriminatorIdIsAlreadySpecified, baseType |
| | | 938 | | } |
| | | 939 | | |
| | | 940 | | [DoesNotReturn] |
| | | 941 | | public static void ThrowInvalidOperationException_InvalidCustomTypeDiscriminatorPropertyName() |
| | 0 | 942 | | { |
| | 0 | 943 | | throw new InvalidOperationException(SR.Polymorphism_InvalidCustomTypeDiscriminatorPropertyName); |
| | | 944 | | } |
| | | 945 | | |
| | | 946 | | [DoesNotReturn] |
| | | 947 | | public static void ThrowInvalidOperationException_PropertyConflictsWithMetadataPropertyName(Type type, string pr |
| | 0 | 948 | | { |
| | 0 | 949 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_PropertyConflictsWithMetadataPropertyName, typ |
| | | 950 | | } |
| | | 951 | | |
| | | 952 | | [DoesNotReturn] |
| | | 953 | | public static void ThrowInvalidOperationException_PolymorphicTypeConfigurationDoesNotSpecifyDerivedTypes(Type ba |
| | 0 | 954 | | { |
| | 0 | 955 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_ConfigurationDoesNotSpecifyDerivedTypes, baseT |
| | | 956 | | } |
| | | 957 | | |
| | | 958 | | [DoesNotReturn] |
| | | 959 | | public static void ThrowInvalidOperationException_UnsupportedEnumIdentifier(Type enumType, string? enumName) |
| | 0 | 960 | | { |
| | 0 | 961 | | throw new InvalidOperationException(SR.Format(SR.UnsupportedEnumIdentifier, enumType.Name, enumName)); |
| | | 962 | | } |
| | | 963 | | |
| | | 964 | | [DoesNotReturn] |
| | | 965 | | public static void ThrowJsonException_UnrecognizedTypeDiscriminator(object typeDiscriminator) |
| | 0 | 966 | | { |
| | 0 | 967 | | ThrowJsonException(SR.Format(SR.Polymorphism_UnrecognizedTypeDiscriminator, typeDiscriminator)); |
| | | 968 | | } |
| | | 969 | | |
| | | 970 | | [DoesNotReturn] |
| | | 971 | | public static void ThrowArgumentException_JsonPolymorphismOptionsAssociatedWithDifferentJsonTypeInfo(string para |
| | 0 | 972 | | { |
| | 0 | 973 | | throw new ArgumentException(SR.JsonPolymorphismOptionsAssociatedWithDifferentJsonTypeInfo, paramName: parame |
| | | 974 | | } |
| | | 975 | | |
| | | 976 | | [DoesNotReturn] |
| | | 977 | | public static void ThrowOperationCanceledException_PipeWriteCanceled() |
| | 0 | 978 | | { |
| | 0 | 979 | | throw new OperationCanceledException(SR.PipeWriterCanceled); |
| | | 980 | | } |
| | | 981 | | |
| | | 982 | | [DoesNotReturn] |
| | | 983 | | public static void ThrowOperationCanceledException_PipeReadCanceled() |
| | 0 | 984 | | { |
| | 0 | 985 | | throw new OperationCanceledException(SR.PipeReaderCanceled); |
| | | 986 | | } |
| | | 987 | | |
| | | 988 | | [DoesNotReturn] |
| | | 989 | | public static void ThrowInvalidOperationException_PipeWriterDoesNotImplementUnflushedBytes(PipeWriter pipeWriter |
| | 0 | 990 | | { |
| | 0 | 991 | | throw new InvalidOperationException(SR.Format(SR.PipeWriter_DoesNotImplementUnflushedBytes, pipeWriter.GetTy |
| | | 992 | | } |
| | | 993 | | |
| | | 994 | | [DoesNotReturn] |
| | | 995 | | public static void ThrowNotSupportedException_JsonSchemaExporterDoesNotSupportReferenceHandlerPreserve() |
| | 0 | 996 | | { |
| | 0 | 997 | | throw new NotSupportedException(SR.JsonSchemaExporter_ReferenceHandlerPreserve_NotSupported); |
| | | 998 | | } |
| | | 999 | | |
| | | 1000 | | [DoesNotReturn] |
| | | 1001 | | public static void ThrowInvalidOperationException_JsonSchemaExporterDepthTooLarge() |
| | 0 | 1002 | | { |
| | 0 | 1003 | | throw new InvalidOperationException(SR.JsonSchemaExporter_DepthTooLarge); |
| | | 1004 | | } |
| | | 1005 | | } |
| | | 1006 | | } |