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

Can't import: MyPostProcessor: No export was found for the contract 'IPostProcessor "MyPostProcessor"' #9246

Closed
michfuchs opened this issue Sep 25, 2023 Discussed in #9239 · 7 comments
Labels
extensibility Extend the platform to support new languages, new outputs and custom behaviors

Comments

@michfuchs
Copy link

michfuchs commented Sep 25, 2023

DocFX version: 2.70.3
Project built with .NET Core SDK 7.0.401 (also tried .NET 6.0, same behaviour)

Reproducing the issue:

  1. Follow the instructions in the Documentation.
  2. Copy the generated assembly to templates/my-template/plugins
  3. Build the site

Observed behavior:

  • Exception message (see below), PostProcessor does not work

Expected behavior:

  • PostProcessor is picked up as the documentation would suggest

Others seem to struggle with the issue as well:

Discussed in #9239

Originally posted by michfuchs September 25, 2023
One appraoch to solve #9238 seems to be implementing a custom PostProcessor, as described in the Documentation.

image

However, I don't seem to be able to load my post processor.

My docfx.json configuration for the post processors looks like this:

"postProcessors": [ "ExtractSearchIndex", "MyPostProcessor" ]

Since ExtractSearchIndex works, I'm confident it's in the right spot.

Step 4 in the documentation specifies where the built dll of the assembly containing the preprocessor should be copied to:
image

I tried several folder options, none seem to work:
image
image
image
image

I am consistently getting the following error:

1>Searching custom plugins in directory ****\802_Documentation\templates\my-template\plugins...
1>6 plug-in(s) loaded.
1>Post processor ExtractSearchIndex loaded.
1>EXEC : warning : Can't import: MyPostProcessor, System.Composition.Hosting.CompositionFailedException: No export was found for the contract 'IPostProcessor "MyPostProcessor"'.
1>   at System.Composition.CompositionContext.GetExport(CompositionContract contract)
1>   at System.Composition.CompositionContext.GetExport(Type exportType, String contractName)
1>   at Docfx.Common.CompositionContainer.GetExport(CompositionHost container, Type type, String name) in /_/src/Docfx.Build.Engine/CompositionContainer.cs:line 41
1>EXEC : warning : Can't find the post processor: MyPostProcessor

It was always 6 plug-ins, even before I added the processor, so the plug-in is definitely not picked up.

@yufeih yufeih added the extensibility Extend the platform to support new languages, new outputs and custom behaviors label Sep 26, 2023
@yufeih
Copy link
Contributor

yufeih commented Sep 26, 2023

Is there a DLL that contains MyPostProcessor you could share to help us diagnose the issue?

@michfuchs
Copy link
Author

michfuchs commented Sep 26, 2023

A version mismatch was responsible for the issue (see answer in #9239).

Maybe a warning could be shown if versions are not matched. Thanks for your help.

@alricsans
Copy link

Have you ever had a similar issues in docker containers ?

On my windows machine, everything works perfectly, but inside a container based on mcr.microsoft.com/dotnet/sdk:6.0 (or even 7.0). I get the same error :

warning: Can't import: TagsProcessor, System.Composition.Hosting.CompositionFailedException: No export was found for the contract 'IPostProcessor "TagsProcessor"'.
   at System.Composition.CompositionContext.GetExport(CompositionContract contract)
   at System.Composition.CompositionContext.GetExport(Type exportType, String contractName)
   at Docfx.Common.CompositionContainer.GetExport(CompositionHost container, Type type, String name) in /_/src/Docfx.Build/CompositionContainer.cs:line 41
warning: Can't find the post processor: TagsProcessor

It is exactly the same code, using docfx version 2.75.3 and Docfx.Plugins and Docfx.Common version 2.75.3 also.
I tried upgrading and downgrading all of those versions accordingly from 2.75.0 to 2.76.0 but nothing woked.

Did anyone encounter the same issue ? If there is something to do for unix-based OS so that the Export attribute works, please let me know.

@filzrev
Copy link
Contributor

filzrev commented Jun 20, 2024

@alricsans
Plugin DLL loading failure is reported as Verbose level message.
Is there any log output when running docfx with the --verbose parameter?

@alricsans
Copy link

I compared the one that works with the one that does not (with the --verbose parameter), and I have no difference until the warning that appears during the Loading plug-ins and post-processors... step :

  • Local setup (works fine):
Loading plug-ins and post-processors...
Searching custom plugins in directory C:\<project-path>\docs\<my-template>\plugins...
Scanning assembly file C:\<project-path>\docs\<my-template>\plugins\Docfx.TagsGenerator.PostProcessor.dll...
Post processor ExtractSearchIndex loaded.
Post processor TagsProcessor loaded.
Post processor SitemapGenerator loaded.
7 plug-in(s) loaded.
  • Docker container (failing):
Loading plug-ins and post-processors...
warning: Can't import: TagsProcessor, System.Composition.Hosting.CompositionFailedException: No export was found for the contract 'IPostProcessor "TagsProcessor"'.
   at System.Composition.CompositionContext.GetExport(CompositionContract contract)
   at System.Composition.CompositionContext.GetExport(Type exportType, String contractName)
   at Docfx.Common.CompositionContainer.GetExport(CompositionHost container, Type type, String name) in /_/src/Docfx.Build/CompositionContainer.cs:line 41
warning: Can't find the post processor: TagsProcessor
Post processor SitemapGenerator loaded.

Unfortunately I don't see any differences in the first lines (Skipping assembly, Scanning assembly file and so on)

@filzrev
Copy link
Contributor

filzrev commented Jun 20, 2024

It seems that the DLL in the <my-template>\plugins directory is not searched on docker environment.
Because following lines are not exists on docker logs.

Searching custom plugins in directory C:\<project-path>\docs\<my-template>\plugins...
Scanning assembly file C:\<project-path>\docs\<my-template>\plugins\Docfx.TagsGenerator.PostProcessor.dll...

Is it able to confirm <project-path>/docs/<my-template>/plugins directory is exists on docker build environment?


I've also tried to run docfx on docker by using this Dockerfile
And it seems to work as expected. (Custom template's plugin directory search log outputted).

Searching custom plugins in directory /root/.dotnet/tools/.store/docfx/2.76.0/docfx/2.76.0/tools/net6.0/any/...
Searching custom plugins in directory /opt/prj/docs/templates/custom/plugins...
Post processor ExtractSearchIndex loaded.
...

@alricsans
Copy link

alricsans commented Jun 21, 2024

Thank you so much @filzrev your comment helped me troubleshoot my problem.

What seemed to cause the problem was that the dll from my postprocessor were copied to : ./docs/my-template/Plugins instead of ./docs/my-template/plugins, and Windows is probably not case sensitive, but linux is ...

Many thanks again for your help @filzrev !

Edit :
In case other have this issue, I saw it had to be named with an uppercase in this section : https://dotnet.github.io/docfx/tutorial/howto_add_a_customized_post_processor.html#step4-build-your-project-and-copy-the-output-dll-files-to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extensibility Extend the platform to support new languages, new outputs and custom behaviors
Projects
None yet
Development

No branches or pull requests

4 participants