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

Duplicate param/@name in XML causes NullReferenceException #4165

Closed
KalleOlaviNiemitalo opened this issue Mar 14, 2019 · 3 comments · Fixed by #8552
Closed

Duplicate param/@name in XML causes NullReferenceException #4165

KalleOlaviNiemitalo opened this issue Mar 14, 2019 · 3 comments · Fixed by #8552
Labels
bug A bug to fix dotnet: xml-comment XML comment for .NET API reference docs dotnet Generate .NET API reference docs

Comments

@KalleOlaviNiemitalo
Copy link

Operation System: Windows

DocFX Version Used: 2.40.12.0

Template used: default

Steps to Reproduce:

  1. Extract the files from the attached docfx_project.zip, in which the important part is this bin/DuplicateParam.xml:
    <?xml version="1.0"?>
    <doc>
        <assembly>
            <name>DuplicateParam</name>
        </assembly>
        <members>
            <member name="T:DuplicateParam.Program">
                <summary>Probes error handling in DocFX.</summary>
            </member>
            <member name="M:DuplicateParam.Program.Main(System.String[])">
                <param name="args">Command-line arguments.</param>
                <param name="args">Duplicate documentation for the same parameter.</param>
            </member>
        </members>
    </doc>
  2. Run docfx metadata.

Expected Behavior:

Metadata extraction succeeds, possibly with a warning about the duplicate param element.

Actual Behavior:

NullReferenceException is thrown:

[19-03-14 03.45.10.324]Info:Config file docfx.json found, start generating metadata...
[19-03-14 03.45.10.544]Info:[ExtractMetadata]Environment variable VSINSTALLDIR is set to C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\, it is used as the inner compiler.
[19-03-14 03.45.10.802]Info:[ExtractMetadata]Loading projects...
[19-03-14 03.45.10.816]Info:[ExtractMetadata]Generating metadata for each project...
[19-03-14 03.45.12.131]Info:[ExtractMetadata]Loading developer comments from file: C:/Projects/Kalle/duplicate_param/docfx_project/bin/DuplicateParam.xml
[19-03-14 03.45.12.198]Error:Error extracting metadata for C:/Projects/Kalle/duplicate_param/docfx_project/bin/DuplicateParam.exe: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.DocAsCode.Metadata.ManagedReference.TripleSlashCommentModel.GetListContent(XPathNavigator navigator, String xpath, String contentType, ITripleSlashCommentParserContext context)
   at Microsoft.DocAsCode.Metadata.ManagedReference.TripleSlashCommentModel..ctor(String xml, SyntaxLanguage language, ITripleSlashCommentParserContext context)
   at Microsoft.DocAsCode.Metadata.ManagedReference.TripleSlashCommentModel.CreateModel(String xml, SyntaxLanguage language, ITripleSlashCommentParserContext context)
   at Microsoft.DocAsCode.Metadata.ManagedReference.MergeCommentsHelper.PatchViewModel(MetadataItem item, String comment)
   at Microsoft.DocAsCode.Metadata.ManagedReference.MergeCommentsHelper.PatchMetadataItem(MetadataItem assembly, IEnumerable`1 list)
   at Microsoft.DocAsCode.Metadata.ManagedReference.MergeCommentsHelper.MergeComments(MetadataItem item, IEnumerable`1 commentFiles)
   at Microsoft.DocAsCode.Metadata.ManagedReference.ExtractMetadataWorker.<SaveAllMembersFromCacheAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.DocAsCode.Metadata.ManagedReference.ExtractMetadataWorker.<ExtractMetadataAsync>d__11.MoveNext()
[19-03-14 03.45.12.204]Info:Completed in 1670,0582 milliseconds


Build failed.
[19-03-14 03.45.12.214]Error:Error extracting metadata for C:/Projects/Kalle/duplicate_param/docfx_project/bin/DuplicateParam.exe: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.DocAsCode.Metadata.ManagedReference.TripleSlashCommentModel.GetListContent(XPathNavigator navigator, String xpath, String contentType, ITripleSlashCommentParserContext context)
   at Microsoft.DocAsCode.Metadata.ManagedReference.TripleSlashCommentModel..ctor(String xml, SyntaxLanguage language, ITripleSlashCommentParserContext context)
   at Microsoft.DocAsCode.Metadata.ManagedReference.TripleSlashCommentModel.CreateModel(String xml, SyntaxLanguage language, ITripleSlashCommentParserContext context)
   at Microsoft.DocAsCode.Metadata.ManagedReference.MergeCommentsHelper.PatchViewModel(MetadataItem item, String comment)
   at Microsoft.DocAsCode.Metadata.ManagedReference.MergeCommentsHelper.PatchMetadataItem(MetadataItem assembly, IEnumerable`1 list)
   at Microsoft.DocAsCode.Metadata.ManagedReference.MergeCommentsHelper.MergeComments(MetadataItem item, IEnumerable`1 commentFiles)
   at Microsoft.DocAsCode.Metadata.ManagedReference.ExtractMetadataWorker.<SaveAllMembersFromCacheAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.DocAsCode.Metadata.ManagedReference.ExtractMetadataWorker.<ExtractMetadataAsync>d__11.MoveNext()
        0 Warning(s)
        1 Error(s)
@KalleOlaviNiemitalo
Copy link
Author

One of our projects actually hit this error, and the cause of the NullReferenceException was not easy to find.

@KalleOlaviNiemitalo
Copy link
Author

I debugged this several weeks ago and I think the problem was that, when TripleSlashCommentModel.GetListContent evaluated context.Source.Remote to log a warning about the duplicate param element, context.Source was null because DocFX had not read the param element from a C# source file. My memory may be wrong, though.

@superyyrrzz superyyrrzz added bug A bug to fix dotnet Generate .NET API reference docs labels Mar 18, 2019
@superyyrrzz superyyrrzz added dotnet: xml-comment XML comment for .NET API reference docs and removed dotnet Generate .NET API reference docs labels May 14, 2019
@agent00jackson
Copy link

agent00jackson commented Oct 26, 2022

I also encountered this issue. Would not have figured out the cause of the exception if it wasn't for this.

@yufeih yufeih added the dotnet Generate .NET API reference docs label Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug to fix dotnet: xml-comment XML comment for .NET API reference docs dotnet Generate .NET API reference docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants