Replace invalid sourcegen debug assertion with runtime check (#68828)
authorEirik Tsarpalis <eirik.tsarpalis@gmail.com>
Thu, 5 May 2022 11:08:19 +0000 (14:08 +0300)
committerGitHub <noreply@github.com>
Thu, 5 May 2022 11:08:19 +0000 (12:08 +0100)
* Replace AttributeConstructor null assertion with runtime exception

* Remove redundand Json.NET package references

* Revert "Remove redundand Json.NET package references"

This reverts commit 5247c1f98313410fc8cff399670f9595155cef9c.

src/libraries/System.Text.Json/gen/Reflection/ConstructorInfoWrapper.cs
src/libraries/System.Text.Json/gen/Reflection/CustomAttributeDataWrapper.cs

index 51dcef2..206234f 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Globalization;
 using System.Reflection;
 using Microsoft.CodeAnalysis;
@@ -15,6 +16,7 @@ namespace System.Text.Json.Reflection
 
         public ConstructorInfoWrapper(IMethodSymbol ctor, MetadataLoadContextInternal metadataLoadContext)
         {
+            Debug.Assert(ctor != null);
             _ctor = ctor;
             _metadataLoadContext = metadataLoadContext;
         }
index f95c0dc..ad504d8 100644 (file)
@@ -13,7 +13,10 @@ namespace System.Text.Json.Reflection
     {
         public CustomAttributeDataWrapper(AttributeData a, MetadataLoadContextInternal metadataLoadContext)
         {
-            Debug.Assert(a.AttributeConstructor != null);
+            if (a.AttributeConstructor is null)
+            {
+                throw new InvalidOperationException();
+            }
 
             var namedArguments = new List<CustomAttributeNamedArgument>();
             foreach (KeyValuePair<string, TypedConstant> na in a.NamedArguments)