2

Despite reading through the docfx documentation, and numerous Github issues, I am unable to get my docfx project working.

Steps taken:

  1. Initialise root directory docfx init -q
  2. Build from root directory docfx build (no errors)
  3. Serve docfx "/user/docfx_project/docfx.json" --serve

Stacktrace:

Error:Error extracting metadata for /user/docfx_project/src/MyApp/MyApp.csproj,/user/docfx_project/src/MyApp.Tests/MyApp.Tests.csproj: System.NullReferenceException: Object reference not set to an instance of an object
  at Microsoft.DocAsCode.Metadata.ManagedReference.ExtractMetadataWorker.SaveAllMembersFromCacheAsync () [0x00380] in <0779a76130d64c11baa2c8c084cbfe7c>:0 
  at Microsoft.DocAsCode.Metadata.ManagedReference.ExtractMetadataWorker.ExtractMetadataAsync () [0x000c0] in <0779a76130d64c11baa2c8c084cbfe7c>:0 

Environment:

  • OSX 10.13.6
  • docfx 2.56.2.0
  • .NET Core SDK (3.1.401)
  • Mono JIT compiler version 6.10.0.104

Project structure:

docfx-project
 |
 +-- _site
 +-- api
 +-- apidoc
 +-- articles
 +-- docfx.json
 +-- images
 +-- index.md
 +-- obj
 +-- src
     |
     +-- MyApp
         |
         +-- MyApp.csproj
 +-- toc.yml

docfx.json:

{
  "metadata": [
    {
      "src": [
        {
          "files": [
            "src/**/**.csproj"
          ]
        }
      ],
      "dest": "api",
      "disableGitFeatures": false,
      "disableDefaultFilter": false
    }
  ],
  "build": {
    "content": [
      {
        "files": [
          "api/**.yml",
          "api/index.md"
        ]
      },
      {
        "files": [
          "articles/**.md",
          "articles/**/toc.yml",
          "toc.yml",
          "*.md"
        ]
      }
    ],
    "resource": [
      {
        "files": [
          "images/**"
        ]
      }
    ],
    "overwrite": [
      {
        "files": [
          "apidoc/**.md"
        ],
        "exclude": [
          "obj/**",
          "_site/**"
        ]
      }
    ],
    "dest": "_site",
    "globalMetadataFiles": [],
    "fileMetadataFiles": [],
    "template": [
      "default"
    ],
    "postProcessors": [],
    "markdownEngineName": "markdig",
    "noLangKeyword": false,
    "keepFileLink": false,
    "cleanupCacheHistory": false,
    "disableGitFeatures": false
  }
}

Halp.

burntsugar
  • 57,360
  • 21
  • 58
  • 81
  • I've just encountered this myself in a CI build (where it works fine locally). Investigating... – Jon Skeet Feb 03 '21 at 07:00
  • Apparently there's a fix - which I have not tried because I have moved on from this project. See here https://github.com/dotnet/docfx/issues/5785#issuecomment-709777562 – burntsugar Feb 03 '21 at 11:14
  • Hmm... can't really download an arbitrary version of docfx on CI. (Huge security risk.) But I'm trying to update the version of VS on our CI machine... will report back with whether that helped. – Jon Skeet Feb 03 '21 at 11:50

1 Answers1

1

I have relatively little idea why this works, but what it took on my CI machine was export VSINSTALLDIR= - in other words, clearing the VSINSTALLDIR environment variable before running docfx metadata. I believe that affects the version of msbuild (or some msbuild files, at least) that docfx uses.

This is has been a fix for other issues in the past - that one claims to have been fixed a while ago, but the same workaround seems to work for this issue too... at least on my CI machine.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194