diff --git a/src/NJsonSchema.CodeGeneration.CSharp/Templates/JsonInheritanceConverter.liquid b/src/NJsonSchema.CodeGeneration.CSharp/Templates/JsonInheritanceConverter.liquid index df07bfae9..26cb4bc93 100644 --- a/src/NJsonSchema.CodeGeneration.CSharp/Templates/JsonInheritanceConverter.liquid +++ b/src/NJsonSchema.CodeGeneration.CSharp/Templates/JsonInheritanceConverter.liquid @@ -103,11 +103,11 @@ public class JsonInheritanceConverter : System.Text.Json.Serialization.Js throw new System.InvalidOperationException("Could not find subtype of '" + objectType.Name + "' with discriminator '" + discriminatorValue + "'."); } - private System.Type GetObjectSubtype(System.Type objectType, string discriminator) + private System.Type GetObjectSubtype(System.Type baseType, string discriminatorValue) { - foreach (var attribute in System.Reflection.CustomAttributeExtensions.GetCustomAttributes(System.Reflection.IntrospectionExtensions.GetTypeInfo(objectType), true)) + foreach (var attribute in System.Reflection.CustomAttributeExtensions.GetCustomAttributes(System.Reflection.IntrospectionExtensions.GetTypeInfo(baseType), true)) { - if (attribute.Key == discriminator) + if (attribute.Key == discriminatorValue) return attribute.Type; } @@ -122,7 +122,7 @@ public class JsonInheritanceConverter : System.Text.Json.Serialization.Js return attribute.Key; } - return objectType.Name; + return null; } } {%- else -%}