Closed cnlizhipeng closed 6 years ago
Hi, I am facing a similar issue.
My application source code https://github.com/aspnetlabs/Dynamic-WebAPI-Controllers
This is the stack trace:
Microsoft.AspNetCore.Server.Kestrel:Error: Connection id "0HLE3ADDEN75D": An unhandled exception was thrown by the application.
System.NullReferenceException: Object reference not set to an instance of an object.
at Swashbuckle.AspNetCore.SwaggerGen.TypeExtensions.FullNameSansTypeArguments(Type type)
at Swashbuckle.AspNetCore.SwaggerGen.XmlCommentsMemberNameHelper.BuildTypeToken(Type type)
at System.Linq.Enumerable.SelectArrayIterator2.MoveNext() at System.String.Join(String separator, IEnumerable
1 values)
at Swashbuckle.AspNetCore.SwaggerGen.XmlCommentsMemberNameHelper.GetMemberNameForMethod(MethodInfo method)
at Swashbuckle.AspNetCore.SwaggerGen.XmlCommentsOperationFilter.Apply(Operation operation, OperationFilterContext context)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, ISchemaRegistry schemaRegistry)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable1 apiDescriptions, ISchemaRegistry schemaRegistry) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable
1 source, Func2 keySelector, Func
2 elementSelector, IEqualityComparer`1 comparer)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath, String[] schemes)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.
Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.
d__2.MoveNext()
Just faced the same issue on a generic class, any news?
The MSDN for Type.FullName says that this property return
null if the current instance represents a generic type parameter, an array type, pointer type, or byreftype based on a type parameter, or a generic type that is not a generic type definition but contains unresolved type parameters.
It doesn't even matter if I add xml comments on that generic class as SwashBuckle seems to autodiscover the whole API. (As observed with Resharper debugging of external modules)
I'd classify the current implementation as a bug, looks like I have to disable documentation for now as the generic type controller is required to save a huge amount of redundant code.
Above solution did't completly work for me, I was not able to see the comments on swagger page, after adding this post build script it resolved the issue.
c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "$x=(Get-Content $(TargetDir)\$(ProjectName).xml) -replace '{`0}', '{T}[T]' | Out-File $(TargetDir)\$(ProjectName).xml"
See the link below - I've come up with a test to repro but have it commented out because I haven't had the time to find a solution. Those XML comments member names are extremely cryptic, particularly when generics come into play and I haven't had the time to give it the focus it needs:
If anyone else wants to pull it down and take a stab that would be awesome?
@cnlizhipeng, @aspnetlabs, @PatrickTetz I believe I've implemented a fix for this, pushed with the following commit - 0b6e0b2
It should be available with the following preview package on myget.org:
Swashbuckle.AspNetCore.2.5.0-preview-0510.nupkg
Could you please pull it down, test it out and provide feedback? Thanks
I believe this is now fixed as of v2.5.0. Feel free to re-open if you're still seeing issues with that version or above
My abstract class has this function
void Delete(ICollection<KeyType> input);
There will be a mistake
I tried to modify the following code to solve my problem.
Are there any other better things to do, or my use is wrong?