| | | 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) |
| | 0 | 51 | | { |
| | 0 | 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) |
| | 0 | 147 | | { |
| | 0 | 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 is null); |
| | 0 | 157 | | throw new ArgumentException(SR.Format(SR.CannotSerializeInvalidType, typeToConvert), paramName); |
| | | 158 | | } |
| | | 159 | | |
| | 0 | 160 | | Debug.Assert(propertyName is not 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_SerializationConverterOnAttributeOpenGenericNotCompatible(Type |
| | 0 | 234 | | { |
| | 0 | 235 | | string location = classType.ToString(); |
| | 0 | 236 | | if (memberInfo != null) |
| | 0 | 237 | | { |
| | 0 | 238 | | location += $".{memberInfo.Name}"; |
| | 0 | 239 | | } |
| | | 240 | | |
| | 0 | 241 | | throw new InvalidOperationException(SR.Format(SR.SerializationConverterOnAttributeOpenGenericNotCompatible, |
| | | 242 | | } |
| | | 243 | | |
| | | 244 | | [DoesNotReturn] |
| | | 245 | | public static void ThrowInvalidOperationException_SerializerOptionsReadOnly(JsonSerializerContext? context) |
| | 0 | 246 | | { |
| | 0 | 247 | | string message = context is null |
| | 0 | 248 | | ? SR.SerializerOptionsReadOnly |
| | 0 | 249 | | : SR.SerializerContextOptionsReadOnly; |
| | | 250 | | |
| | 0 | 251 | | throw new InvalidOperationException(message); |
| | | 252 | | } |
| | | 253 | | |
| | | 254 | | [DoesNotReturn] |
| | | 255 | | public static void ThrowInvalidOperationException_DefaultTypeInfoResolverImmutable() |
| | 0 | 256 | | { |
| | 0 | 257 | | throw new InvalidOperationException(SR.DefaultTypeInfoResolverImmutable); |
| | | 258 | | } |
| | | 259 | | |
| | | 260 | | [DoesNotReturn] |
| | | 261 | | public static void ThrowInvalidOperationException_TypeInfoResolverChainImmutable() |
| | 0 | 262 | | { |
| | 0 | 263 | | throw new InvalidOperationException(SR.TypeInfoResolverChainImmutable); |
| | | 264 | | } |
| | | 265 | | |
| | | 266 | | [DoesNotReturn] |
| | | 267 | | public static void ThrowInvalidOperationException_TypeInfoImmutable() |
| | 0 | 268 | | { |
| | 0 | 269 | | throw new InvalidOperationException(SR.TypeInfoImmutable); |
| | | 270 | | } |
| | | 271 | | |
| | | 272 | | [DoesNotReturn] |
| | | 273 | | public static void ThrowInvalidOperationException_InvalidChainedResolver() |
| | 0 | 274 | | { |
| | 0 | 275 | | throw new InvalidOperationException(SR.SerializerOptions_InvalidChainedResolver); |
| | | 276 | | } |
| | | 277 | | |
| | | 278 | | [DoesNotReturn] |
| | | 279 | | public static void ThrowInvalidOperationException_SerializerPropertyNameConflict(Type type, string propertyName) |
| | 0 | 280 | | { |
| | 0 | 281 | | throw new InvalidOperationException(SR.Format(SR.SerializerPropertyNameConflict, type, propertyName)); |
| | | 282 | | } |
| | | 283 | | |
| | | 284 | | [DoesNotReturn] |
| | | 285 | | public static void ThrowInvalidOperationException_SerializerPropertyNameNull(JsonPropertyInfo jsonPropertyInfo) |
| | 0 | 286 | | { |
| | 0 | 287 | | throw new InvalidOperationException(SR.Format(SR.SerializerPropertyNameNull, jsonPropertyInfo.DeclaringType, |
| | | 288 | | } |
| | | 289 | | |
| | | 290 | | [DoesNotReturn] |
| | | 291 | | public static void ThrowInvalidOperationException_JsonPropertyRequiredAndNotDeserializable(JsonPropertyInfo json |
| | 0 | 292 | | { |
| | 0 | 293 | | throw new InvalidOperationException(SR.Format(SR.JsonPropertyRequiredAndNotDeserializable, jsonPropertyInfo. |
| | | 294 | | } |
| | | 295 | | |
| | | 296 | | [DoesNotReturn] |
| | | 297 | | public static void ThrowInvalidOperationException_JsonPropertyRequiredAndExtensionData(JsonPropertyInfo jsonProp |
| | 0 | 298 | | { |
| | 0 | 299 | | throw new InvalidOperationException(SR.Format(SR.JsonPropertyRequiredAndExtensionData, jsonPropertyInfo.Name |
| | | 300 | | } |
| | | 301 | | |
| | | 302 | | [DoesNotReturn] |
| | | 303 | | public static void ThrowJsonException_JsonRequiredPropertyMissing(JsonTypeInfo parent, BitArray assignedOrNotReq |
| | 0 | 304 | | { |
| | 0 | 305 | | StringBuilder builder = new(); |
| | | 306 | | |
| | 0 | 307 | | foreach (JsonPropertyInfo property in parent.PropertyCache) |
| | 0 | 308 | | { |
| | 0 | 309 | | if (!assignedOrNotRequiredPropertiesSet[property.PropertyIndex]) |
| | 0 | 310 | | { |
| | 0 | 311 | | if (!AppendMissingProperty(builder, property.Name)) |
| | 0 | 312 | | { |
| | 0 | 313 | | break; |
| | | 314 | | } |
| | 0 | 315 | | } |
| | 0 | 316 | | } |
| | | 317 | | |
| | 0 | 318 | | throw new JsonException(SR.Format(SR.JsonRequiredPropertiesMissing, parent.Type, builder.ToString())); |
| | | 319 | | } |
| | | 320 | | |
| | | 321 | | [DoesNotReturn] |
| | | 322 | | public static void ThrowJsonException_JsonRequiredPropertyMissing(Type type, string propertyList) |
| | 0 | 323 | | { |
| | 0 | 324 | | throw new JsonException(SR.Format(SR.JsonRequiredPropertiesMissing, type, propertyList)); |
| | | 325 | | } |
| | | 326 | | |
| | | 327 | | /// <summary> |
| | | 328 | | /// Appends a property name to a missing-properties list with culture-aware separators and a soft length cut-off |
| | | 329 | | /// Returns false when the cut-off is reached and no more names should be appended. |
| | | 330 | | /// </summary> |
| | | 331 | | internal static bool AppendMissingProperty(StringBuilder builder, string propertyName) |
| | 0 | 332 | | { |
| | | 333 | | const int CutOffLength = 60; |
| | | 334 | | |
| | 0 | 335 | | if (builder.Length > 0) |
| | 0 | 336 | | { |
| | 0 | 337 | | builder.Append(CultureInfo.CurrentUICulture.TextInfo.ListSeparator); |
| | 0 | 338 | | builder.Append(' '); |
| | 0 | 339 | | } |
| | | 340 | | |
| | 0 | 341 | | builder.Append('\''); |
| | 0 | 342 | | builder.Append(propertyName); |
| | 0 | 343 | | builder.Append('\''); |
| | | 344 | | |
| | 0 | 345 | | return builder.Length < CutOffLength; |
| | 0 | 346 | | } |
| | | 347 | | |
| | | 348 | | [DoesNotReturn] |
| | | 349 | | public static void ThrowJsonException_DuplicatePropertyNotAllowed(JsonPropertyInfo property) |
| | 0 | 350 | | { |
| | 0 | 351 | | throw new JsonException(SR.Format(SR.DuplicatePropertiesNotAllowed_JsonPropertyInfo, property.Name, property |
| | | 352 | | } |
| | | 353 | | |
| | | 354 | | [DoesNotReturn] |
| | | 355 | | public static void ThrowJsonException_DuplicatePropertyNotAllowed() |
| | 0 | 356 | | { |
| | 0 | 357 | | throw new JsonException(SR.DuplicatePropertiesNotAllowed); |
| | | 358 | | } |
| | | 359 | | |
| | | 360 | | [DoesNotReturn] |
| | | 361 | | public static void ThrowJsonException_DuplicatePropertyNotAllowed(string name) |
| | 0 | 362 | | { |
| | 0 | 363 | | throw new JsonException(SR.Format(SR.DuplicatePropertiesNotAllowed_NameSpan, Truncate(name))); |
| | | 364 | | } |
| | | 365 | | |
| | | 366 | | [DoesNotReturn] |
| | | 367 | | public static void ThrowJsonException_DuplicatePropertyNotAllowed(ReadOnlySpan<byte> nameBytes) |
| | 0 | 368 | | { |
| | 0 | 369 | | string name = Encoding.UTF8.GetString(nameBytes); |
| | 0 | 370 | | throw new JsonException(SR.Format(SR.DuplicatePropertiesNotAllowed_NameSpan, Truncate(name))); |
| | | 371 | | } |
| | | 372 | | |
| | | 373 | | private static unsafe string Truncate(ReadOnlySpan<char> str) |
| | 0 | 374 | | { |
| | | 375 | | const int MaxLength = 15; |
| | | 376 | | |
| | 0 | 377 | | if (str.Length <= MaxLength) |
| | 0 | 378 | | { |
| | 0 | 379 | | return str.ToString(); |
| | | 380 | | } |
| | | 381 | | |
| | 0 | 382 | | Span<char> builder = stackalloc char[MaxLength + 3]; |
| | 0 | 383 | | str.Slice(0, MaxLength).CopyTo(builder); |
| | 0 | 384 | | builder[MaxLength] = builder[MaxLength + 1] = builder[MaxLength + 2] = '.'; |
| | 0 | 385 | | return builder.ToString(); |
| | 0 | 386 | | } |
| | | 387 | | |
| | | 388 | | [DoesNotReturn] |
| | | 389 | | public static void ThrowInvalidOperationException_NamingPolicyReturnNull(JsonNamingPolicy namingPolicy) |
| | 0 | 390 | | { |
| | 0 | 391 | | throw new InvalidOperationException(SR.Format(SR.NamingPolicyReturnNull, namingPolicy)); |
| | | 392 | | } |
| | | 393 | | |
| | | 394 | | [DoesNotReturn] |
| | | 395 | | public static void ThrowInvalidOperationException_SerializerConverterFactoryReturnsNull(Type converterType) |
| | 0 | 396 | | { |
| | 0 | 397 | | throw new InvalidOperationException(SR.Format(SR.SerializerConverterFactoryReturnsNull, converterType)); |
| | | 398 | | } |
| | | 399 | | |
| | | 400 | | [DoesNotReturn] |
| | | 401 | | public static void ThrowInvalidOperationException_SerializerConverterFactoryReturnsJsonConverterFactory(Type con |
| | 0 | 402 | | { |
| | 0 | 403 | | throw new InvalidOperationException(SR.Format(SR.SerializerConverterFactoryReturnsJsonConverterFactory, conv |
| | | 404 | | } |
| | | 405 | | |
| | | 406 | | [DoesNotReturn] |
| | | 407 | | public static void ThrowInvalidOperationException_MultiplePropertiesBindToConstructorParameters( |
| | | 408 | | Type parentType, |
| | | 409 | | string parameterName, |
| | | 410 | | string firstMatchName, |
| | | 411 | | string secondMatchName) |
| | 0 | 412 | | { |
| | 0 | 413 | | throw new InvalidOperationException( |
| | 0 | 414 | | SR.Format( |
| | 0 | 415 | | SR.MultipleMembersBindWithConstructorParameter, |
| | 0 | 416 | | firstMatchName, |
| | 0 | 417 | | secondMatchName, |
| | 0 | 418 | | parentType, |
| | 0 | 419 | | parameterName)); |
| | | 420 | | } |
| | | 421 | | |
| | | 422 | | [DoesNotReturn] |
| | | 423 | | public static void ThrowInvalidOperationException_ConstructorParameterIncompleteBinding(Type parentType) |
| | 0 | 424 | | { |
| | 0 | 425 | | throw new InvalidOperationException(SR.Format(SR.ConstructorParamIncompleteBinding, parentType)); |
| | | 426 | | } |
| | | 427 | | |
| | | 428 | | [DoesNotReturn] |
| | | 429 | | public static void ThrowInvalidOperationException_ExtensionDataCannotBindToCtorParam(string propertyName, JsonPr |
| | 0 | 430 | | { |
| | 0 | 431 | | throw new InvalidOperationException(SR.Format(SR.ExtensionDataCannotBindToCtorParam, propertyName, jsonPrope |
| | | 432 | | } |
| | | 433 | | |
| | | 434 | | [DoesNotReturn] |
| | | 435 | | public static void ThrowInvalidOperationException_JsonIncludeOnInaccessibleProperty(string memberName, Type decl |
| | 0 | 436 | | { |
| | 0 | 437 | | throw new InvalidOperationException(SR.Format(SR.JsonIncludeOnInaccessibleProperty, memberName, declaringTyp |
| | | 438 | | } |
| | | 439 | | |
| | | 440 | | [DoesNotReturn] |
| | | 441 | | public static void ThrowInvalidOperationException_IgnoreConditionOnValueTypeInvalid(string clrPropertyName, Type |
| | 0 | 442 | | { |
| | 0 | 443 | | throw new InvalidOperationException(SR.Format(SR.IgnoreConditionOnValueTypeInvalid, clrPropertyName, propert |
| | | 444 | | } |
| | | 445 | | |
| | | 446 | | [DoesNotReturn] |
| | | 447 | | public static void ThrowInvalidOperationException_NumberHandlingOnPropertyInvalid(JsonPropertyInfo jsonPropertyI |
| | 0 | 448 | | { |
| | 0 | 449 | | Debug.Assert(!jsonPropertyInfo.IsForTypeInfo); |
| | 0 | 450 | | throw new InvalidOperationException(SR.Format(SR.NumberHandlingOnPropertyInvalid, jsonPropertyInfo.MemberNam |
| | | 451 | | } |
| | | 452 | | |
| | | 453 | | [DoesNotReturn] |
| | | 454 | | public static void ThrowInvalidOperationException_ConverterCanConvertMultipleTypes(Type runtimePropertyType, Jso |
| | 0 | 455 | | { |
| | 0 | 456 | | throw new InvalidOperationException(SR.Format(SR.ConverterCanConvertMultipleTypes, jsonConverter.GetType(), |
| | | 457 | | } |
| | | 458 | | |
| | | 459 | | [DoesNotReturn] |
| | | 460 | | public static void ThrowNotSupportedException_ObjectWithParameterizedCtorRefMetadataNotSupported( |
| | | 461 | | ReadOnlySpan<byte> propertyName, |
| | | 462 | | ref Utf8JsonReader reader, |
| | | 463 | | scoped ref ReadStack state) |
| | 0 | 464 | | { |
| | 0 | 465 | | JsonTypeInfo jsonTypeInfo = state.GetTopJsonTypeInfoWithParameterizedConstructor(); |
| | 0 | 466 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | | 467 | | |
| | 0 | 468 | | NotSupportedException ex = new NotSupportedException( |
| | 0 | 469 | | SR.Format(SR.ObjectWithParameterizedCtorRefMetadataNotSupported, jsonTypeInfo.Type)); |
| | 0 | 470 | | ThrowNotSupportedException(ref state, reader, ex); |
| | | 471 | | } |
| | | 472 | | |
| | | 473 | | [DoesNotReturn] |
| | | 474 | | public static void ThrowInvalidOperationException_JsonTypeInfoOperationNotPossibleForKind(JsonTypeInfoKind kind) |
| | 0 | 475 | | { |
| | 0 | 476 | | throw new InvalidOperationException(SR.Format(SR.InvalidJsonTypeInfoOperationForKind, kind)); |
| | | 477 | | } |
| | | 478 | | |
| | | 479 | | [DoesNotReturn] |
| | | 480 | | public static void ThrowInvalidOperationException_JsonTypeInfoOnDeserializingCallbacksNotSupported(Type type) |
| | 0 | 481 | | { |
| | 0 | 482 | | throw new InvalidOperationException(SR.Format(SR.OnDeserializingCallbacksNotSupported, type)); |
| | | 483 | | } |
| | | 484 | | |
| | | 485 | | [DoesNotReturn] |
| | | 486 | | public static void ThrowInvalidOperationException_CreateObjectConverterNotCompatible(Type type) |
| | 0 | 487 | | { |
| | 0 | 488 | | throw new InvalidOperationException(SR.Format(SR.CreateObjectConverterNotCompatible, type)); |
| | | 489 | | } |
| | | 490 | | |
| | | 491 | | [DoesNotReturn] |
| | | 492 | | public static void ReThrowWithPath(scoped ref ReadStack state, JsonReaderException ex) |
| | 0 | 493 | | { |
| | 0 | 494 | | Debug.Assert(ex.Path is null); |
| | | 495 | | |
| | 0 | 496 | | string path = state.JsonPath(); |
| | 0 | 497 | | string message = ex.Message; |
| | | 498 | | |
| | | 499 | | // Insert the "Path" portion before "LineNumber" and "BytePositionInLine". |
| | | 500 | | #if NET |
| | 0 | 501 | | int iPos = message.AsSpan().LastIndexOf(" LineNumber: "); |
| | | 502 | | #else |
| | | 503 | | int iPos = message.LastIndexOf(" LineNumber: ", StringComparison.Ordinal); |
| | | 504 | | #endif |
| | 0 | 505 | | if (iPos >= 0) |
| | 0 | 506 | | { |
| | 0 | 507 | | message = $"{message.Substring(0, iPos)} Path: {path} |{message.Substring(iPos)}"; |
| | 0 | 508 | | } |
| | | 509 | | else |
| | 0 | 510 | | { |
| | 0 | 511 | | message += $" Path: {path}."; |
| | 0 | 512 | | } |
| | | 513 | | |
| | 0 | 514 | | throw new JsonException(message, path, ex.LineNumber, ex.BytePositionInLine, ex); |
| | | 515 | | } |
| | | 516 | | |
| | | 517 | | [DoesNotReturn] |
| | | 518 | | public static void ReThrowWithPath(scoped ref ReadStack state, in Utf8JsonReader reader, Exception ex) |
| | 0 | 519 | | { |
| | 0 | 520 | | JsonException jsonException = new JsonException(null, ex); |
| | 0 | 521 | | AddJsonExceptionInformation(ref state, reader, jsonException); |
| | 0 | 522 | | throw jsonException; |
| | | 523 | | } |
| | | 524 | | |
| | | 525 | | public static void AddJsonExceptionInformation(scoped ref ReadStack state, in Utf8JsonReader reader, JsonExcepti |
| | 0 | 526 | | { |
| | 0 | 527 | | Debug.Assert(ex.Path is null); // do not overwrite existing path information |
| | | 528 | | |
| | 0 | 529 | | long lineNumber = reader.CurrentState._lineNumber; |
| | 0 | 530 | | ex.LineNumber = lineNumber; |
| | | 531 | | |
| | 0 | 532 | | long bytePositionInLine = reader.CurrentState._bytePositionInLine; |
| | 0 | 533 | | ex.BytePositionInLine = bytePositionInLine; |
| | | 534 | | |
| | 0 | 535 | | string path = state.JsonPath(); |
| | 0 | 536 | | ex.Path = path; |
| | | 537 | | |
| | 0 | 538 | | string? message = ex._message; |
| | | 539 | | |
| | 0 | 540 | | if (string.IsNullOrEmpty(message)) |
| | 0 | 541 | | { |
| | | 542 | | // Use a default message. |
| | 0 | 543 | | Type propertyType = state.Current.JsonPropertyInfo?.PropertyType ?? |
| | 0 | 544 | | state.Current.CtorArgumentState?.JsonParameterInfo?.ParameterType ?? |
| | 0 | 545 | | state.Current.JsonTypeInfo.Type; |
| | 0 | 546 | | message = SR.Format(SR.DeserializeUnableToConvertValue, propertyType); |
| | 0 | 547 | | ex.AppendPathInformation = true; |
| | 0 | 548 | | } |
| | | 549 | | |
| | 0 | 550 | | if (ex.AppendPathInformation) |
| | 0 | 551 | | { |
| | 0 | 552 | | message += $" Path: {path} | LineNumber: {lineNumber} | BytePositionInLine: {bytePositionInLine}."; |
| | 0 | 553 | | ex.SetMessage(message); |
| | 0 | 554 | | } |
| | 0 | 555 | | } |
| | | 556 | | |
| | | 557 | | [DoesNotReturn] |
| | | 558 | | public static void ReThrowWithPath(ref WriteStack state, Exception ex) |
| | 0 | 559 | | { |
| | 0 | 560 | | JsonException jsonException = new JsonException(null, ex); |
| | 0 | 561 | | AddJsonExceptionInformation(ref state, jsonException); |
| | 0 | 562 | | throw jsonException; |
| | | 563 | | } |
| | | 564 | | |
| | | 565 | | public static void AddJsonExceptionInformation(ref WriteStack state, JsonException ex) |
| | 0 | 566 | | { |
| | 0 | 567 | | Debug.Assert(ex.Path is null); // do not overwrite existing path information |
| | | 568 | | |
| | 0 | 569 | | string path = state.PropertyPath(); |
| | 0 | 570 | | ex.Path = path; |
| | | 571 | | |
| | 0 | 572 | | string? message = ex._message; |
| | 0 | 573 | | if (string.IsNullOrEmpty(message)) |
| | 0 | 574 | | { |
| | | 575 | | // Use a default message. |
| | 0 | 576 | | message = SR.SerializeUnableToSerialize; |
| | 0 | 577 | | ex.AppendPathInformation = true; |
| | 0 | 578 | | } |
| | | 579 | | |
| | 0 | 580 | | if (ex.AppendPathInformation) |
| | 0 | 581 | | { |
| | 0 | 582 | | message += $" Path: {path}."; |
| | 0 | 583 | | ex.SetMessage(message); |
| | 0 | 584 | | } |
| | 0 | 585 | | } |
| | | 586 | | |
| | | 587 | | [DoesNotReturn] |
| | | 588 | | public static void ThrowInvalidOperationException_SerializationDuplicateAttribute(Type attribute, MemberInfo mem |
| | 0 | 589 | | { |
| | 0 | 590 | | string location = memberInfo is Type type ? type.ToString() : $"{memberInfo.DeclaringType}.{memberInfo.Name} |
| | 0 | 591 | | throw new InvalidOperationException(SR.Format(SR.SerializationDuplicateAttribute, attribute, location)); |
| | | 592 | | } |
| | | 593 | | |
| | | 594 | | [DoesNotReturn] |
| | | 595 | | public static void ThrowInvalidOperationException_SerializationDuplicateTypeAttribute(Type classType, Type attri |
| | 0 | 596 | | { |
| | 0 | 597 | | throw new InvalidOperationException(SR.Format(SR.SerializationDuplicateTypeAttribute, classType, attribute)) |
| | | 598 | | } |
| | | 599 | | |
| | | 600 | | [DoesNotReturn] |
| | | 601 | | public static void ThrowInvalidOperationException_SerializationDuplicateTypeAttribute<TAttribute>(Type classType |
| | 0 | 602 | | { |
| | 0 | 603 | | throw new InvalidOperationException(SR.Format(SR.SerializationDuplicateTypeAttribute, classType, typeof(TAtt |
| | | 604 | | } |
| | | 605 | | |
| | | 606 | | [DoesNotReturn] |
| | | 607 | | public static void ThrowInvalidOperationException_ExtensionDataConflictsWithUnmappedMemberHandling(Type classTyp |
| | 0 | 608 | | { |
| | 0 | 609 | | throw new InvalidOperationException(SR.Format(SR.ExtensionDataConflictsWithUnmappedMemberHandling, classType |
| | | 610 | | } |
| | | 611 | | |
| | | 612 | | [DoesNotReturn] |
| | | 613 | | public static void ThrowInvalidOperationException_SerializationDataExtensionPropertyInvalid(JsonPropertyInfo jso |
| | 0 | 614 | | { |
| | 0 | 615 | | throw new InvalidOperationException(SR.Format(SR.SerializationDataExtensionPropertyInvalid, jsonPropertyInfo |
| | | 616 | | } |
| | | 617 | | |
| | | 618 | | [DoesNotReturn] |
| | | 619 | | public static void ThrowInvalidOperationException_PropertyTypeNotNullable(JsonPropertyInfo jsonPropertyInfo) |
| | 0 | 620 | | { |
| | 0 | 621 | | throw new InvalidOperationException(SR.Format(SR.PropertyTypeNotNullable, jsonPropertyInfo.PropertyType)); |
| | | 622 | | } |
| | | 623 | | |
| | | 624 | | [DoesNotReturn] |
| | | 625 | | public static void ThrowInvalidOperationException_NodeJsonObjectCustomConverterNotAllowedOnExtensionProperty() |
| | 0 | 626 | | { |
| | 0 | 627 | | throw new InvalidOperationException(SR.NodeJsonObjectCustomConverterNotAllowedOnExtensionProperty); |
| | | 628 | | } |
| | | 629 | | |
| | | 630 | | [DoesNotReturn] |
| | | 631 | | public static void ThrowNotSupportedException(scoped ref ReadStack state, in Utf8JsonReader reader, Exception in |
| | 0 | 632 | | { |
| | 0 | 633 | | string message = innerException.Message; |
| | | 634 | | |
| | | 635 | | // The caller should check to ensure path is not already set. |
| | 0 | 636 | | Debug.Assert(!message.Contains(" Path: ")); |
| | | 637 | | |
| | | 638 | | // Obtain the type to show in the message. |
| | 0 | 639 | | Type propertyType = state.Current.JsonPropertyInfo?.PropertyType ?? state.Current.JsonTypeInfo.Type; |
| | | 640 | | |
| | 0 | 641 | | if (!message.Contains(propertyType.ToString())) |
| | 0 | 642 | | { |
| | 0 | 643 | | if (message.Length > 0) |
| | 0 | 644 | | { |
| | 0 | 645 | | message += " "; |
| | 0 | 646 | | } |
| | | 647 | | |
| | 0 | 648 | | message += SR.Format(SR.SerializationNotSupportedParentType, propertyType); |
| | 0 | 649 | | } |
| | | 650 | | |
| | 0 | 651 | | long lineNumber = reader.CurrentState._lineNumber; |
| | 0 | 652 | | long bytePositionInLine = reader.CurrentState._bytePositionInLine; |
| | 0 | 653 | | message += $" Path: {state.JsonPath()} | LineNumber: {lineNumber} | BytePositionInLine: {bytePositionInLine} |
| | | 654 | | |
| | 0 | 655 | | throw new NotSupportedException(message, innerException); |
| | | 656 | | } |
| | | 657 | | |
| | | 658 | | [DoesNotReturn] |
| | | 659 | | public static void ThrowNotSupportedException(ref WriteStack state, Exception innerException) |
| | 0 | 660 | | { |
| | 0 | 661 | | string message = innerException.Message; |
| | | 662 | | |
| | | 663 | | // The caller should check to ensure path is not already set. |
| | 0 | 664 | | Debug.Assert(!message.Contains(" Path: ")); |
| | | 665 | | |
| | | 666 | | // Obtain the type to show in the message. |
| | 0 | 667 | | Type propertyType = state.Current.JsonPropertyInfo?.PropertyType ?? state.Current.JsonTypeInfo.Type; |
| | | 668 | | |
| | 0 | 669 | | if (!message.Contains(propertyType.ToString())) |
| | 0 | 670 | | { |
| | 0 | 671 | | if (message.Length > 0) |
| | 0 | 672 | | { |
| | 0 | 673 | | message += " "; |
| | 0 | 674 | | } |
| | | 675 | | |
| | 0 | 676 | | message += SR.Format(SR.SerializationNotSupportedParentType, propertyType); |
| | 0 | 677 | | } |
| | | 678 | | |
| | 0 | 679 | | message += $" Path: {state.PropertyPath()}."; |
| | | 680 | | |
| | 0 | 681 | | throw new NotSupportedException(message, innerException); |
| | | 682 | | } |
| | | 683 | | |
| | | 684 | | [DoesNotReturn] |
| | | 685 | | public static void ThrowNotSupportedException_DeserializeNoConstructor(JsonTypeInfo typeInfo, ref Utf8JsonReader |
| | 0 | 686 | | { |
| | 0 | 687 | | Type type = typeInfo.Type; |
| | | 688 | | string message; |
| | | 689 | | |
| | 0 | 690 | | if (type.IsInterface || type.IsAbstract) |
| | 0 | 691 | | { |
| | 0 | 692 | | if (typeInfo.PolymorphicTypeResolver?.UsesTypeDiscriminators is true) |
| | 0 | 693 | | { |
| | 0 | 694 | | message = SR.Format(SR.DeserializationMustSpecifyTypeDiscriminator, type); |
| | 0 | 695 | | } |
| | 0 | 696 | | else if (typeInfo.Kind is JsonTypeInfoKind.Enumerable or JsonTypeInfoKind.Dictionary) |
| | 0 | 697 | | { |
| | 0 | 698 | | message = SR.Format(SR.CannotPopulateCollection, type); |
| | 0 | 699 | | } |
| | | 700 | | else |
| | 0 | 701 | | { |
| | 0 | 702 | | message = SR.Format(SR.DeserializeInterfaceOrAbstractType, type); |
| | 0 | 703 | | } |
| | 0 | 704 | | } |
| | | 705 | | else |
| | 0 | 706 | | { |
| | 0 | 707 | | message = SR.Format(SR.DeserializeNoConstructor, nameof(JsonConstructorAttribute), type); |
| | 0 | 708 | | } |
| | | 709 | | |
| | 0 | 710 | | ThrowNotSupportedException(ref state, reader, new NotSupportedException(message)); |
| | | 711 | | } |
| | | 712 | | |
| | | 713 | | [DoesNotReturn] |
| | | 714 | | public static void ThrowNotSupportedException_CannotPopulateCollection(Type type, ref Utf8JsonReader reader, sco |
| | 0 | 715 | | { |
| | 0 | 716 | | ThrowNotSupportedException(ref state, reader, new NotSupportedException(SR.Format(SR.CannotPopulateCollectio |
| | | 717 | | } |
| | | 718 | | |
| | | 719 | | [DoesNotReturn] |
| | | 720 | | public static void ThrowJsonException_MetadataValuesInvalidToken(JsonTokenType tokenType) |
| | 0 | 721 | | { |
| | 0 | 722 | | ThrowJsonException(SR.Format(SR.MetadataInvalidTokenAfterValues, tokenType)); |
| | | 723 | | } |
| | | 724 | | |
| | | 725 | | [DoesNotReturn] |
| | | 726 | | public static void ThrowJsonException_MetadataReferenceNotFound(string id) |
| | 0 | 727 | | { |
| | 0 | 728 | | ThrowJsonException(SR.Format(SR.MetadataReferenceNotFound, id)); |
| | | 729 | | } |
| | | 730 | | |
| | | 731 | | [DoesNotReturn] |
| | | 732 | | public static void ThrowJsonException_MetadataValueWasNotString(JsonTokenType tokenType) |
| | 0 | 733 | | { |
| | 0 | 734 | | ThrowJsonException(SR.Format(SR.MetadataValueWasNotString, tokenType)); |
| | | 735 | | } |
| | | 736 | | |
| | | 737 | | [DoesNotReturn] |
| | | 738 | | public static void ThrowJsonException_MetadataValueWasNotString(JsonValueKind valueKind) |
| | 0 | 739 | | { |
| | 0 | 740 | | ThrowJsonException(SR.Format(SR.MetadataValueWasNotString, valueKind)); |
| | | 741 | | } |
| | | 742 | | |
| | | 743 | | [DoesNotReturn] |
| | | 744 | | public static void ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties(ReadOnlySpan<byte> pro |
| | 0 | 745 | | { |
| | 0 | 746 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 747 | | ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties(); |
| | | 748 | | } |
| | | 749 | | |
| | | 750 | | [DoesNotReturn] |
| | | 751 | | public static void ThrowJsonException_MetadataUnexpectedProperty(ReadOnlySpan<byte> propertyName, scoped ref Rea |
| | 0 | 752 | | { |
| | 0 | 753 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 754 | | ThrowJsonException(SR.MetadataUnexpectedProperty); |
| | | 755 | | } |
| | | 756 | | |
| | | 757 | | [DoesNotReturn] |
| | | 758 | | public static void ThrowJsonException_UnmappedJsonProperty(Type type, string unmappedPropertyName) |
| | 0 | 759 | | { |
| | 0 | 760 | | throw new JsonException(SR.Format(SR.UnmappedJsonProperty, unmappedPropertyName, type)); |
| | | 761 | | } |
| | | 762 | | |
| | | 763 | | [DoesNotReturn] |
| | | 764 | | public static void ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties() |
| | 0 | 765 | | { |
| | 0 | 766 | | ThrowJsonException(SR.MetadataReferenceCannotContainOtherProperties); |
| | | 767 | | } |
| | | 768 | | |
| | | 769 | | [DoesNotReturn] |
| | | 770 | | public static void ThrowJsonException_MetadataIdCannotBeCombinedWithRef(ReadOnlySpan<byte> propertyName, scoped |
| | 0 | 771 | | { |
| | 0 | 772 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 773 | | ThrowJsonException(SR.MetadataIdCannotBeCombinedWithRef); |
| | | 774 | | } |
| | | 775 | | |
| | | 776 | | [DoesNotReturn] |
| | | 777 | | public static void ThrowJsonException_MetadataStandaloneValuesProperty(scoped ref ReadStack state, ReadOnlySpan< |
| | 0 | 778 | | { |
| | 0 | 779 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 780 | | ThrowJsonException(SR.MetadataStandaloneValuesProperty); |
| | | 781 | | } |
| | | 782 | | |
| | | 783 | | [DoesNotReturn] |
| | | 784 | | public static void ThrowJsonException_MetadataInvalidPropertyWithLeadingDollarSign(ReadOnlySpan<byte> propertyNa |
| | 0 | 785 | | { |
| | | 786 | | // Set PropertyInfo or KeyName to write down the conflicting property name in JsonException.Path |
| | 0 | 787 | | if (state.Current.IsProcessingDictionary()) |
| | 0 | 788 | | { |
| | 0 | 789 | | state.Current.JsonPropertyNameAsString = reader.GetString(); |
| | 0 | 790 | | } |
| | | 791 | | else |
| | 0 | 792 | | { |
| | 0 | 793 | | state.Current.JsonPropertyName = propertyName.ToArray(); |
| | 0 | 794 | | } |
| | | 795 | | |
| | 0 | 796 | | ThrowJsonException(SR.MetadataInvalidPropertyWithLeadingDollarSign); |
| | | 797 | | } |
| | | 798 | | |
| | | 799 | | [DoesNotReturn] |
| | | 800 | | public static void ThrowJsonException_MetadataDuplicateIdFound(string id) |
| | 0 | 801 | | { |
| | 0 | 802 | | ThrowJsonException(SR.Format(SR.MetadataDuplicateIdFound, id)); |
| | | 803 | | } |
| | | 804 | | |
| | | 805 | | [DoesNotReturn] |
| | | 806 | | public static void ThrowJsonException_DuplicateMetadataProperty(ReadOnlySpan<byte> utf8PropertyName) |
| | 0 | 807 | | { |
| | 0 | 808 | | ThrowJsonException(SR.Format(SR.DuplicateMetadataProperty, Encoding.UTF8.GetString(utf8PropertyName))); |
| | | 809 | | } |
| | | 810 | | |
| | | 811 | | [DoesNotReturn] |
| | | 812 | | public static void ThrowJsonException_MetadataInvalidReferenceToValueType(Type propertyType) |
| | 0 | 813 | | { |
| | 0 | 814 | | ThrowJsonException(SR.Format(SR.MetadataInvalidReferenceToValueType, propertyType)); |
| | | 815 | | } |
| | | 816 | | |
| | | 817 | | [DoesNotReturn] |
| | | 818 | | public static void ThrowJsonException_MetadataInvalidPropertyInArrayMetadata(scoped ref ReadStack state, Type pr |
| | 0 | 819 | | { |
| | 0 | 820 | | state.Current.JsonPropertyName = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan |
| | 0 | 821 | | string propertyNameAsString = reader.GetString()!; |
| | | 822 | | |
| | 0 | 823 | | ThrowJsonException(SR.Format(SR.MetadataPreservedArrayFailed, |
| | 0 | 824 | | SR.Format(SR.MetadataInvalidPropertyInArrayMetadata, propertyNameAsString), |
| | 0 | 825 | | SR.Format(SR.DeserializeUnableToConvertValue, propertyType))); |
| | | 826 | | } |
| | | 827 | | |
| | | 828 | | [DoesNotReturn] |
| | | 829 | | public static void ThrowJsonException_MetadataPreservedArrayValuesNotFound(scoped ref ReadStack state, Type prop |
| | 0 | 830 | | { |
| | | 831 | | // Missing $values, JSON path should point to the property's object. |
| | 0 | 832 | | state.Current.JsonPropertyName = null; |
| | | 833 | | |
| | 0 | 834 | | ThrowJsonException(SR.Format(SR.MetadataPreservedArrayFailed, |
| | 0 | 835 | | SR.MetadataStandaloneValuesProperty, |
| | 0 | 836 | | SR.Format(SR.DeserializeUnableToConvertValue, propertyType))); |
| | | 837 | | } |
| | | 838 | | |
| | | 839 | | [DoesNotReturn] |
| | | 840 | | public static void ThrowJsonException_MetadataCannotParsePreservedObjectIntoImmutable(Type propertyType) |
| | 0 | 841 | | { |
| | 0 | 842 | | ThrowJsonException(SR.Format(SR.MetadataCannotParsePreservedObjectToImmutable, propertyType)); |
| | | 843 | | } |
| | | 844 | | |
| | | 845 | | [DoesNotReturn] |
| | | 846 | | public static void ThrowInvalidOperationException_MetadataReferenceOfTypeCannotBeAssignedToType(string reference |
| | 0 | 847 | | { |
| | 0 | 848 | | throw new InvalidOperationException(SR.Format(SR.MetadataReferenceOfTypeCannotBeAssignedToType, referenceId, |
| | | 849 | | } |
| | | 850 | | |
| | | 851 | | [DoesNotReturn] |
| | | 852 | | public static void ThrowInvalidOperationException_JsonPropertyInfoIsBoundToDifferentJsonTypeInfo(JsonPropertyInf |
| | 0 | 853 | | { |
| | 0 | 854 | | Debug.Assert(propertyInfo.DeclaringTypeInfo is not null, "We should not throw this exception when ParentType |
| | 0 | 855 | | throw new InvalidOperationException(SR.Format(SR.JsonPropertyInfoBoundToDifferentParent, propertyInfo.Name, |
| | | 856 | | } |
| | | 857 | | |
| | | 858 | | [DoesNotReturn] |
| | | 859 | | internal static void ThrowUnexpectedMetadataException( |
| | | 860 | | ReadOnlySpan<byte> propertyName, |
| | | 861 | | ref Utf8JsonReader reader, |
| | | 862 | | scoped ref ReadStack state) |
| | 0 | 863 | | { |
| | | 864 | | |
| | 0 | 865 | | MetadataPropertyName name = JsonSerializer.GetMetadataPropertyName(propertyName, state.Current.BaseJsonTypeI |
| | 0 | 866 | | if (name != 0) |
| | 0 | 867 | | { |
| | 0 | 868 | | ThrowJsonException_MetadataUnexpectedProperty(propertyName, ref state); |
| | | 869 | | } |
| | | 870 | | else |
| | 0 | 871 | | { |
| | 0 | 872 | | ThrowJsonException_MetadataInvalidPropertyWithLeadingDollarSign(propertyName, ref state, reader); |
| | | 873 | | } |
| | | 874 | | } |
| | | 875 | | |
| | | 876 | | [DoesNotReturn] |
| | | 877 | | public static void ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver? resolver) |
| | 0 | 878 | | { |
| | 0 | 879 | | throw new NotSupportedException(SR.Format(SR.NoMetadataForType, type, resolver?.ToString() ?? "<null>")); |
| | | 880 | | } |
| | | 881 | | |
| | | 882 | | public static NotSupportedException GetNotSupportedException_AmbiguousMetadataForType(Type type, Type match1, Ty |
| | 0 | 883 | | { |
| | 0 | 884 | | return new NotSupportedException(SR.Format(SR.AmbiguousMetadataForType, type, match1, match2)); |
| | 0 | 885 | | } |
| | | 886 | | |
| | | 887 | | [DoesNotReturn] |
| | | 888 | | public static void ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type declaringType) |
| | 0 | 889 | | { |
| | 0 | 890 | | throw new NotSupportedException(SR.Format(SR.ConstructorContainsNullParameterNames, declaringType)); |
| | | 891 | | } |
| | | 892 | | |
| | | 893 | | [DoesNotReturn] |
| | | 894 | | public static void ThrowInvalidOperationException_NoMetadataForType(Type type, IJsonTypeInfoResolver? resolver) |
| | 0 | 895 | | { |
| | 0 | 896 | | throw new InvalidOperationException(SR.Format(SR.NoMetadataForType, type, resolver?.ToString() ?? "<null>")) |
| | | 897 | | } |
| | | 898 | | |
| | | 899 | | public static Exception GetInvalidOperationException_NoMetadataForTypeProperties(IJsonTypeInfoResolver? resolver |
| | 0 | 900 | | { |
| | 0 | 901 | | return new InvalidOperationException(SR.Format(SR.NoMetadataForTypeProperties, resolver?.ToString() ?? "<nul |
| | 0 | 902 | | } |
| | | 903 | | |
| | | 904 | | [DoesNotReturn] |
| | | 905 | | public static void ThrowInvalidOperationException_NoMetadataForTypeProperties(IJsonTypeInfoResolver? resolver, T |
| | 0 | 906 | | { |
| | 0 | 907 | | throw GetInvalidOperationException_NoMetadataForTypeProperties(resolver, type); |
| | | 908 | | } |
| | | 909 | | |
| | | 910 | | [DoesNotReturn] |
| | | 911 | | public static void ThrowMissingMemberException_MissingFSharpCoreMember(string missingFsharpCoreMember) |
| | 0 | 912 | | { |
| | 0 | 913 | | throw new MissingMemberException(SR.Format(SR.MissingFSharpCoreMember, missingFsharpCoreMember)); |
| | | 914 | | } |
| | | 915 | | |
| | | 916 | | [DoesNotReturn] |
| | | 917 | | public static void ThrowNotSupportedException_BaseConverterDoesNotSupportMetadata(Type derivedType) |
| | 0 | 918 | | { |
| | 0 | 919 | | throw new NotSupportedException(SR.Format(SR.Polymorphism_DerivedConverterDoesNotSupportMetadata, derivedTyp |
| | | 920 | | } |
| | | 921 | | |
| | | 922 | | [DoesNotReturn] |
| | | 923 | | public static void ThrowNotSupportedException_DerivedConverterDoesNotSupportMetadata(Type derivedType) |
| | 0 | 924 | | { |
| | 0 | 925 | | throw new NotSupportedException(SR.Format(SR.Polymorphism_DerivedConverterDoesNotSupportMetadata, derivedTyp |
| | | 926 | | } |
| | | 927 | | |
| | | 928 | | [DoesNotReturn] |
| | | 929 | | public static void ThrowNotSupportedException_RuntimeTypeNotSupported(Type baseType, Type runtimeType) |
| | 0 | 930 | | { |
| | 0 | 931 | | throw new NotSupportedException(SR.Format(SR.Polymorphism_RuntimeTypeNotSupported, runtimeType, baseType)); |
| | | 932 | | } |
| | | 933 | | |
| | | 934 | | [DoesNotReturn] |
| | | 935 | | public static void ThrowNotSupportedException_RuntimeTypeDiamondAmbiguity(Type baseType, Type runtimeType, Type |
| | 0 | 936 | | { |
| | 0 | 937 | | throw new NotSupportedException(SR.Format(SR.Polymorphism_RuntimeTypeDiamondAmbiguity, runtimeType, derivedT |
| | | 938 | | } |
| | | 939 | | |
| | | 940 | | [DoesNotReturn] |
| | | 941 | | public static void ThrowInvalidOperationException_TypeDoesNotSupportPolymorphism(Type baseType) |
| | 0 | 942 | | { |
| | 0 | 943 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_TypeDoesNotSupportPolymorphism, baseType)); |
| | | 944 | | } |
| | | 945 | | |
| | | 946 | | [DoesNotReturn] |
| | | 947 | | public static void ThrowInvalidOperationException_DerivedTypeNotSupported(Type baseType, Type derivedType) |
| | 0 | 948 | | { |
| | 0 | 949 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_DerivedTypeIsNotSupported, derivedType, baseTy |
| | | 950 | | } |
| | | 951 | | |
| | | 952 | | [DoesNotReturn] |
| | | 953 | | public static void ThrowInvalidOperationException_DerivedTypeIsAlreadySpecified(Type baseType, Type derivedType) |
| | 0 | 954 | | { |
| | 0 | 955 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_DerivedTypeIsAlreadySpecified, baseType, deriv |
| | | 956 | | } |
| | | 957 | | |
| | | 958 | | [DoesNotReturn] |
| | | 959 | | public static void ThrowInvalidOperationException_OpenGenericDerivedTypeCouldNotBeResolved(Type baseType, Type d |
| | 0 | 960 | | { |
| | 0 | 961 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_OpenGenericDerivedTypeCouldNotBeResolved, deri |
| | | 962 | | } |
| | | 963 | | |
| | | 964 | | [DoesNotReturn] |
| | | 965 | | public static void ThrowInvalidOperationException_TypeDicriminatorIdIsAlreadySpecified(Type baseType, object typ |
| | 0 | 966 | | { |
| | 0 | 967 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_TypeDicriminatorIdIsAlreadySpecified, baseType |
| | | 968 | | } |
| | | 969 | | |
| | | 970 | | [DoesNotReturn] |
| | | 971 | | public static void ThrowInvalidOperationException_InferredDerivedTypeIsNotAccessible(Type baseType, Type derived |
| | 0 | 972 | | { |
| | 0 | 973 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_InferredDerivedTypeIsNotAccessible, derivedTyp |
| | | 974 | | } |
| | | 975 | | |
| | | 976 | | [DoesNotReturn] |
| | | 977 | | public static void ThrowInvalidOperationException_InferClosedTypePolymorphismOnNonClosedType(Type baseType) |
| | 0 | 978 | | { |
| | 0 | 979 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_InferClosedTypePolymorphismOnNonClosedType, ba |
| | | 980 | | } |
| | | 981 | | |
| | | 982 | | [DoesNotReturn] |
| | | 983 | | public static void ThrowInvalidOperationException_InvalidCustomTypeDiscriminatorPropertyName() |
| | 0 | 984 | | { |
| | 0 | 985 | | throw new InvalidOperationException(SR.Polymorphism_InvalidCustomTypeDiscriminatorPropertyName); |
| | | 986 | | } |
| | | 987 | | |
| | | 988 | | [DoesNotReturn] |
| | | 989 | | public static void ThrowInvalidOperationException_PropertyConflictsWithMetadataPropertyName(Type type, string pr |
| | 0 | 990 | | { |
| | 0 | 991 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_PropertyConflictsWithMetadataPropertyName, typ |
| | | 992 | | } |
| | | 993 | | |
| | | 994 | | [DoesNotReturn] |
| | | 995 | | public static void ThrowInvalidOperationException_PolymorphicTypeConfigurationDoesNotSpecifyDerivedTypes(Type ba |
| | 0 | 996 | | { |
| | 0 | 997 | | throw new InvalidOperationException(SR.Format(SR.Polymorphism_ConfigurationDoesNotSpecifyDerivedTypes, baseT |
| | | 998 | | } |
| | | 999 | | |
| | | 1000 | | [DoesNotReturn] |
| | | 1001 | | public static void ThrowJsonException_UnionDoesNotAcceptNull(Type unionType) |
| | 0 | 1002 | | { |
| | 0 | 1003 | | ThrowJsonException(SR.Format(SR.UnionDoesNotAcceptNull, unionType)); |
| | | 1004 | | } |
| | | 1005 | | |
| | | 1006 | | [DoesNotReturn] |
| | | 1007 | | public static void ThrowJsonException_UnionRuntimeTypeNotMatchedToCase(Type unionType, Type runtimeType) |
| | 0 | 1008 | | { |
| | 0 | 1009 | | ThrowJsonException(SR.Format(SR.UnionRuntimeTypeNotMatchedToCase, runtimeType, unionType)); |
| | | 1010 | | } |
| | | 1011 | | |
| | | 1012 | | [DoesNotReturn] |
| | | 1013 | | public static void ThrowJsonException_UnionCannotCreateValue(Type unionType) |
| | 0 | 1014 | | { |
| | 0 | 1015 | | ThrowJsonException(SR.Format(SR.UnionCannotCreateValue, unionType)); |
| | | 1016 | | } |
| | | 1017 | | |
| | | 1018 | | [DoesNotReturn] |
| | | 1019 | | public static void ThrowJsonException_UnionCannotReadValue(Type unionType) |
| | 0 | 1020 | | { |
| | 0 | 1021 | | ThrowJsonException(SR.Format(SR.UnionCannotReadValue, unionType)); |
| | | 1022 | | } |
| | | 1023 | | |
| | | 1024 | | [DoesNotReturn] |
| | | 1025 | | public static void ThrowJsonException_UnionTypeClassifierReturnedNull(Type unionType, JsonTokenType tokenType) |
| | 0 | 1026 | | { |
| | 0 | 1027 | | ThrowJsonException(SR.Format(SR.UnionTypeClassifierReturnedNull, unionType, tokenType)); |
| | | 1028 | | } |
| | | 1029 | | |
| | | 1030 | | [DoesNotReturn] |
| | | 1031 | | public static void ThrowJsonException_UnionAmbiguousJsonValueType(Type unionType, JsonValueType valueType) |
| | 0 | 1032 | | { |
| | 0 | 1033 | | ThrowJsonException(SR.Format(SR.UnionAmbiguousJsonValueType, valueType, unionType)); |
| | | 1034 | | } |
| | | 1035 | | |
| | | 1036 | | [DoesNotReturn] |
| | | 1037 | | public static void ThrowJsonException_UnionJsonTokenTypeNotSupported(Type unionType, JsonTokenType tokenType) |
| | 0 | 1038 | | { |
| | 0 | 1039 | | ThrowJsonException(SR.Format(SR.UnionJsonTokenTypeNotSupported, tokenType, unionType)); |
| | | 1040 | | } |
| | | 1041 | | |
| | | 1042 | | [DoesNotReturn] |
| | | 1043 | | public static void ThrowInvalidOperationException_UnionCasesNotPopulated(Type unionType) |
| | 0 | 1044 | | { |
| | 0 | 1045 | | throw new InvalidOperationException(SR.Format(SR.UnionCasesNotPopulated, unionType)); |
| | | 1046 | | } |
| | | 1047 | | |
| | | 1048 | | [DoesNotReturn] |
| | | 1049 | | public static void ThrowInvalidOperationException_UnionCannotCreateValue(Type unionType) |
| | 0 | 1050 | | { |
| | 0 | 1051 | | throw new InvalidOperationException(SR.Format(SR.UnionCannotCreateValue, unionType)); |
| | | 1052 | | } |
| | | 1053 | | |
| | | 1054 | | [DoesNotReturn] |
| | | 1055 | | public static void ThrowInvalidOperationException_UnionCannotReadValue(Type unionType) |
| | 0 | 1056 | | { |
| | 0 | 1057 | | throw new InvalidOperationException(SR.Format(SR.UnionCannotReadValue, unionType)); |
| | | 1058 | | } |
| | | 1059 | | |
| | | 1060 | | [DoesNotReturn] |
| | | 1061 | | public static void ThrowInvalidOperationException_UnionTypeStructuralClassifierOnlyForUnions(Type unionType) |
| | 0 | 1062 | | { |
| | 0 | 1063 | | throw new InvalidOperationException(SR.Format(SR.UnionTypeStructuralClassifierOnlyForUnions, unionType)); |
| | | 1064 | | } |
| | | 1065 | | |
| | | 1066 | | [DoesNotReturn] |
| | | 1067 | | public static void ThrowNotSupportedException_UnionTypeStructuralClassifierCaseNotSupported( |
| | | 1068 | | Type unionType, |
| | | 1069 | | Type caseType) |
| | 0 | 1070 | | { |
| | 0 | 1071 | | throw new NotSupportedException( |
| | 0 | 1072 | | SR.Format( |
| | 0 | 1073 | | SR.UnionTypeStructuralClassifierCaseNotSupported, |
| | 0 | 1074 | | unionType, |
| | 0 | 1075 | | caseType)); |
| | | 1076 | | } |
| | | 1077 | | |
| | | 1078 | | [DoesNotReturn] |
| | | 1079 | | public static void ThrowNotSupportedException_UnionTypeStructuralClassifierPreserveReferencesNotSupported(Type u |
| | 0 | 1080 | | { |
| | 0 | 1081 | | throw new NotSupportedException( |
| | 0 | 1082 | | SR.Format( |
| | 0 | 1083 | | SR.UnionTypeStructuralClassifierPreserveReferencesNotSupported, |
| | 0 | 1084 | | unionType)); |
| | | 1085 | | } |
| | | 1086 | | |
| | | 1087 | | [DoesNotReturn] |
| | | 1088 | | public static void ThrowNotSupportedException_UnionTypeStructuralClassifierAmbiguousCases( |
| | | 1089 | | Type unionType, |
| | | 1090 | | Type conflictingCaseType, |
| | | 1091 | | Type caseType, |
| | | 1092 | | JsonValueType valueType) |
| | 0 | 1093 | | { |
| | 0 | 1094 | | throw new NotSupportedException( |
| | 0 | 1095 | | SR.Format( |
| | 0 | 1096 | | SR.UnionTypeStructuralClassifierAmbiguousCases, |
| | 0 | 1097 | | unionType, |
| | 0 | 1098 | | conflictingCaseType, |
| | 0 | 1099 | | caseType, |
| | 0 | 1100 | | valueType)); |
| | | 1101 | | } |
| | | 1102 | | |
| | | 1103 | | [DoesNotReturn] |
| | | 1104 | | public static void ThrowNotSupportedException_UnionTypeStructuralClassifierUnreachableObjectCase( |
| | | 1105 | | Type unionType, |
| | | 1106 | | Type unreachableCaseType, |
| | | 1107 | | Type shadowingCaseType) |
| | 0 | 1108 | | { |
| | 0 | 1109 | | throw new NotSupportedException( |
| | 0 | 1110 | | SR.Format( |
| | 0 | 1111 | | SR.UnionTypeStructuralClassifierUnreachableObjectCase, |
| | 0 | 1112 | | unionType, |
| | 0 | 1113 | | unreachableCaseType, |
| | 0 | 1114 | | shadowingCaseType)); |
| | | 1115 | | } |
| | | 1116 | | |
| | | 1117 | | [DoesNotReturn] |
| | | 1118 | | public static void ThrowInvalidOperationException_TypeClassifierMustDeriveFromJsonTypeClassifierFactory(Type cla |
| | 0 | 1119 | | { |
| | 0 | 1120 | | throw new InvalidOperationException(SR.Format(SR.TypeClassifierMustDeriveFromJsonTypeClassifierFactory, clas |
| | | 1121 | | } |
| | | 1122 | | |
| | | 1123 | | [DoesNotReturn] |
| | | 1124 | | public static void ThrowInvalidOperationException_TypeClassifierNotSupported(Type classifierType, Type type) |
| | 0 | 1125 | | { |
| | 0 | 1126 | | throw new InvalidOperationException(SR.Format(SR.TypeClassifierNotSupported, classifierType, type)); |
| | | 1127 | | } |
| | | 1128 | | |
| | | 1129 | | [DoesNotReturn] |
| | | 1130 | | public static void ThrowInvalidOperationException_UnsupportedEnumIdentifier(Type enumType, string? enumName) |
| | 0 | 1131 | | { |
| | 0 | 1132 | | throw new InvalidOperationException(SR.Format(SR.UnsupportedEnumIdentifier, enumType.Name, enumName)); |
| | | 1133 | | } |
| | | 1134 | | |
| | | 1135 | | [DoesNotReturn] |
| | | 1136 | | public static void ThrowJsonException_UnrecognizedTypeDiscriminator(object typeDiscriminator) |
| | 0 | 1137 | | { |
| | 0 | 1138 | | ThrowJsonException(SR.Format(SR.Polymorphism_UnrecognizedTypeDiscriminator, typeDiscriminator)); |
| | | 1139 | | } |
| | | 1140 | | |
| | | 1141 | | [DoesNotReturn] |
| | | 1142 | | public static void ThrowArgumentException_JsonPolymorphismOptionsAssociatedWithDifferentJsonTypeInfo(string para |
| | 0 | 1143 | | { |
| | 0 | 1144 | | throw new ArgumentException(SR.JsonPolymorphismOptionsAssociatedWithDifferentJsonTypeInfo, paramName: parame |
| | | 1145 | | } |
| | | 1146 | | |
| | | 1147 | | [DoesNotReturn] |
| | | 1148 | | public static void ThrowOperationCanceledException_PipeWriteCanceled() |
| | 0 | 1149 | | { |
| | 0 | 1150 | | throw new OperationCanceledException(SR.PipeWriterCanceled); |
| | | 1151 | | } |
| | | 1152 | | |
| | | 1153 | | [DoesNotReturn] |
| | | 1154 | | public static void ThrowOperationCanceledException_PipeReadCanceled() |
| | 0 | 1155 | | { |
| | 0 | 1156 | | throw new OperationCanceledException(SR.PipeReaderCanceled); |
| | | 1157 | | } |
| | | 1158 | | |
| | | 1159 | | [DoesNotReturn] |
| | | 1160 | | public static void ThrowInvalidOperationException_PipeWriterDoesNotImplementUnflushedBytes(PipeWriter pipeWriter |
| | 0 | 1161 | | { |
| | 0 | 1162 | | throw new InvalidOperationException(SR.Format(SR.PipeWriter_DoesNotImplementUnflushedBytes, pipeWriter.GetTy |
| | | 1163 | | } |
| | | 1164 | | |
| | | 1165 | | [DoesNotReturn] |
| | | 1166 | | public static void ThrowNotSupportedException_JsonSchemaExporterDoesNotSupportReferenceHandlerPreserve() |
| | 0 | 1167 | | { |
| | 0 | 1168 | | throw new NotSupportedException(SR.JsonSchemaExporter_ReferenceHandlerPreserve_NotSupported); |
| | | 1169 | | } |
| | | 1170 | | |
| | | 1171 | | [DoesNotReturn] |
| | | 1172 | | public static void ThrowInvalidOperationException_JsonSchemaExporterDepthTooLarge() |
| | 0 | 1173 | | { |
| | 0 | 1174 | | throw new InvalidOperationException(SR.JsonSchemaExporter_DepthTooLarge); |
| | | 1175 | | } |
| | | 1176 | | } |
| | | 1177 | | } |
| | | 1178 | | |