dotnet / docfx

Static site generator for .NET API documentation.
https://dotnet.github.io/docfx/
MIT License
3.94k stars 839 forks source link

[Bug] Failed to load custom plugin DLL when tested on local build environment #10046

Open filzrev opened 6 days ago

filzrev commented 6 days ago

Describe the bug On local docfx build. docfx plugin DLL fails to load because of Docfx.Plugins version mismatch.

To Reproduce Steps to reproduce the behavior:

  1. Create custom PostProcessor DLL.
  2. Place plugin DLL to samples\seed\template\plugins
  3. Configure custom PostProcessor name at docfx.json's postProcessors section.
  4. Start docfx build inside Visual Studio
  5. Confirm following exception occurred.
System.Reflection.ReflectionTypeLoadException
  HResult=0x80131602
  Message=Unable to load one or more of the requested types.
Could not load file or assembly 'Docfx.Plugins, Version=2.76.0.0, Culture=neutral, PublicKeyToken=null'. 
  Source=System.Private.CoreLib
  StackTrace:
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at Docfx.DocumentBuilderWrapper.<LoadPluginAssemblies>d__2.MoveNext() in C:\Projects\docfx\src\Docfx.App\Helpers\DocumentBuilderWrapper.cs:line 88

Expected behavior It can load custom plugin DLL. on local build environment.

Root cause of problem

  1. When docfx is build on local environment. assembly Version is set to 1.0.0
  2. docfx load Docfx.Plugins, Version=1.0.0 on startup.
  3. MEF(System.Composition) plugin try to load plugin DLL.
    But it fails because it attempt to load newer dependent assembly (Docfx.Plugins, Version=2.76.0.0)

How to fix problems It can successfully load plugin DLLs. When manually assign newer version by Directory.Build.props (e.g. <Version>2.76.1</Version>)

So I thought either of the following actions will be required to fix versioning problems. 1, Manually update <Version> tags when docfx version is updated.

  1. Introduce dotnet/Nerdbank.GitVersioning for versioning

Context (please complete the following information):

Additional context Add any other context about the problem here.