Search code examples
swaggerasp.net-core-webapi.net-8.0

Error on apply rule 'NotEmpty' for property


I recently upgraded my ASP.NET Web API project to .NET 8. Now I have a lot of warnings related to NJsonSchema.JsonObjectType and NJsonSchema.JsonSchema.get_Type().

Error on apply rule 'NotEmpty' for property 'ResetPasswordRequest.token'
System.MissingMethodException: Method not found: 'NJsonSchema.JsonObjectType NJsonSchema.JsonSchema.get_Type()'.

at ZymLabs.NSwag.FluentValidation.FluentValidationSchemaProcessor.<>c.b__9_6(RuleContext context)
at ZymLabs.NSwag.FluentValidation.FluentValidationSchemaProcessor.ApplyRulesToSchema(SchemaProcessorContext context, IValidator validator)

Library versions:

<PackageReference Include="NSwag.AspNetCore" Version="14.0.7" />
<PackageReference Include="ZymLabs.NSwag.FluentValidation.AspNetCore" Version="0.6.3" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.1" />

Thanks for helping

I tried to downgrade library version but not compatible with .NET 8.


Solution

  • The fundamental issue is an incompatibility between Nswag.FluentValidation and the version of NJsonSchema provided by Nswag, there is an open issue in that repository here The alpha release fixes the problem. Update ZymLabs.NSwag.FluentValidation.AspNetCore to 0.7.0-alpha0007, clean and rebuild your solution and it will be fixed.