docfx icon indicating copy to clipboard operation
docfx copied to clipboard

Inheritdoc on the constructor function of a struct crashes DocFX

Open jo3w4rd opened this issue 3 years ago • 4 comments

Operating System: (Windows or Linux or MacOS) Windows

DocFX Version Used: 2.58

Template used: (default or statictoc or contain custom template) default with minor cosmetic customizations

Steps to Reproduce:

  1. Place an inheritdoc element on the constructor function of a struct:
public struct BadInheritance
{
    /// <inheritdoc/>
    public BadInheritance(string foo)
    {
    }
}
  1. Run DocFX

Expected Behavior: DocFX would complete and, ideally, emit a warning that the inheritdoc element didn't find any docs to inherit (since structs cannot inherit from other structs).

Actual Behavior: DocFX exits with a null reference exception stack trace and does not produce any output.

jo3w4rd avatar Aug 11 '22 15:08 jo3w4rd

I suspect the problem is here: https://github.com/dotnet/docfx/blob/0341b6c0e4ec999da8cef6ac50ab720160d09c35/src/Microsoft.DocAsCode.Metadata.ManagedReference/Resolvers/CopyInheritedDocumentation.cs#L37

There's an assertion that the constructor function belongs to a class, but that isn't necessarily the case.

jo3w4rd avatar Aug 11 '22 15:08 jo3w4rd

@jo3w4rd For reference, is the comment below the type of documentation you are expecting to inherit in this case?

Initializes a new instance of the ValueType class.

paulushub avatar Aug 11 '22 23:08 paulushub

@paulushub I don't think inheritdoc needs to do anything useful here (a warning would suffice). However, DocFX simply exiting without any indication of what or where the problem lies is extremely bad.

In the case that spurred this issue, I had a largish code base that some engineer at some point in time had inserted this inheritdoc element into. The way I found the problem was by deleting files from the project until I narrowed down which file was the cause (half-split method).

jo3w4rd avatar Aug 12 '22 16:08 jo3w4rd

@jo3w4rd Thanks for the information.

paulushub avatar Aug 12 '22 18:08 paulushub