Base solution for your next web application
Open Closed

Running 'refresh.bat' file NSwag gives Stack overflow error #12219


User avatar
0
OriAssurant created

After 13.1 merge to our current dev branch , we are getting Stack overflow error while running 'refresh.bat' file to update service-proxes.ts file

Anyone seen this kind of error before or any ideas on this error. Please suggest Thanks


8 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi OriAssurant

    If your model classes have circular references (e.g., a property in Class A references Class B, and Class B references Class A), NSwag may struggle to generate the schema. Try using [JsonIgnore] or [SwaggerIgnore] attributes on properties that create circular references.

  • User Avatar
    0
    OriAssurant created

    Thank you oguzhanagir-

    Any other causes you have seen for this issue? After checking for circular references, commenting out many of our custom classes, etc. the issue is still occurring.

    Asp.net Zero dropped the use of Newtonsoft in favor of System.Text.Json in v13 right? Seeing Newtonsoft.Json in the error we're getting.

    Any other ideas of what to check would be very much appreciated. Thanks

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @OriAssurant,

    Can you update the following code on your service.config.nswag

      "codeGenerators": {
        "openApiToCSharpClient": {
          "jsonLibrary": "SystemTextJson", // change this line
        }
    
  • User Avatar
    0
    OriAssurant created

    Unfortunately changing "jsonLibrary": "SystemTextJson" in service.config.nswag didn't resolve the issue. Now I can see new errors

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @OriAssurant,

    Could you share your project with [email protected] We can take a look for your custom services.

  • User Avatar
    0
    OriAssurant created

    Hi oguzhanagir Project shared with "[email protected]" .

    Please check and et us know if you are facing any access issue to get the shared project.

    Thank you

  • User Avatar
    0
    OriAssurant created

    Hi oguzhanagir, Hopefully your support received the shared project and taking a look.

    any ideas/clues regarding resolve the issue from our project would be very much appreciated.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @OriAssurant

    We have found the reason of the problem. It is because of JToken and JObject usages in CustomersController, ExternalController and OrdersController.

    You can either use DTO classes instead or exclude these controllers from swagger as shown below;

    options.DocInclusionPredicate((docName, description) =>
    {
    	var excludedControllers = new[]
    	{
    		"CustomersController",
    		"ExternalController",
    		"OrdersController", 
    	};
    	
    	foreach (var excludedController in excludedControllers)
    	{
    		if (description.ActionDescriptor.DisplayName.Contains(excludedController))
    		{
    			return false;
    		}
    	}
    
    	return true;
    });