Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value cannot be null exception #288

Closed
shotai opened this issue Apr 21, 2015 · 5 comments
Closed

Value cannot be null exception #288

shotai opened this issue Apr 21, 2015 · 5 comments
Milestone

Comments

@shotai
Copy link

shotai commented Apr 21, 2015

Hi, I have an issue with the c.IncludeXmlComments()

I am using my own comments, however, the swachbuckle throw out the exception in below function.

private static void ApplyParamComments(Operation operation, XPathNavigator methodNode)
{
var paramNodes = methodNode.Select(ParameterExpression);
while (paramNodes.MoveNext())
{
var paramNode = paramNodes.Current;
var parameter =
operation.parameters.SingleOrDefault(param => param.name == paramNode.GetAttribute("name", ""));
if (parameter != null)
parameter.description = paramNode.Value.Trim();
}
}

Exception message is:

Value cannot be null. Parameter name: source

The XML of the paramNodes which throws the exception is like below:
<member name="getData">
<summary>
get resource data
</summary>
<param name="id">id</param>
<returns></returns>
</member>

Could some one help with this problem?

Thanks!

@shotai
Copy link
Author

shotai commented Apr 21, 2015

I see the issue seems caused by operation.parameters. If this one is null, then the error will throw out. however, I have no idea why this one could be null.

@domaindrivendev
Copy link
Owner

Does the id parameter actually exist on the corresponding method signature?

The swagger spec does not allow an empty parameters collection - if there are no parameters, then the parameters property should be omitted altogether. So, if an action accepts no parameters, then operation.parameters will be null.

This could be causing your issue and if so you can resolve by simply removing the param node from your XML comments (which makes sense if the param doesn't actually exist).

With all that said, SB should handle this a bit more gracefully - so I'll keep the issue open so I remember to address it when I get the chance.

Richie

@shotai
Copy link
Author

shotai commented Apr 22, 2015

Thanks, Richie. You're right. The parameter didn't exist on the corresponding method signature. After removing it, SB works fine now. Great thanks!

@MerickOWA
Copy link

I also discovered this bug. #293 is a pull request to fix it.

@domaindrivendev
Copy link
Owner

Should be resolved in latest release - 5.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants