json-everything: Type initialiser for SchemaRegistry throws an exception

Environment

  • Nuget Package: JsonSchema.Net
  • Nuget Version: 1.10.5
  • OS: Windows 10
  • .Net Target: .NET Core 3.1.16, .NET 5.0.7

Describe the bug An exception is thrown by the type initialiser for ValidationOptions that is caused by a NullReferenceException in the SchemaRegistry type initialiser:

System.TypeInitializationException: The type initializer for 'Json.Schema.ValidationOptions' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Json.Schema.SchemaRegistry' threw an exception.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Json.Schema.JsonSchema.RegisterSubschemasAndGetBaseUri(SchemaRegistry registry, Uri currentUri)
   at Json.Schema.ItemsKeyword.Json.Schema.IRefResolvable.RegisterSubschemas(SchemaRegistry registry, Uri currentUri)
   at Json.Schema.JsonSchema.RegisterSubschemasAndGetBaseUri(SchemaRegistry registry, Uri currentUri)
   at Json.Schema.DefinitionsKeyword.Json.Schema.IRefResolvable.RegisterSubschemas(SchemaRegistry registry, Uri currentUri)
   at Json.Schema.JsonSchema.RegisterSubschemasAndGetBaseUri(SchemaRegistry registry, Uri currentUri)
   at Json.Schema.JsonSchema.RegisterSubschemas(SchemaRegistry registry, Uri currentUri)
   at Json.Schema.SchemaRegistry..cctor()
   --- End of inner exception stack trace ---
   at Json.Schema.SchemaRegistry..ctor(ValidationOptions options)
   at Json.Schema.ValidationOptions..ctor()
   at Json.Schema.ValidationOptions..cctor()
   --- End of inner exception stack trace ---
   at Json.Schema.ValidationOptions.get_Default()

The issue means that it is not possible to validate a JsonElement against a schema.

To Reproduce

try {
    var options = Json.Schema.ValidationOptions.Default;
}
catch (Exception e) {
    Console.WriteLine(e.ToString());
}

Expected behavior The type initialiser for SchemaRegistry should not throw a NullReferenceException.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (13 by maintainers)

Most upvoted comments

1.10.7 incoming!

if I pass ValidationOptions as second argument to .Validate(..) it works without exception, but with only one argument the .Validate(..) method throws the mentioned exception