EWSoftware / SHFB

Sandcastle Help File Builder (SHFB). A standalone GUI, Visual Studio integration package, and MSBuild tasks providing full configuration and extensibility for building help files with the Sandcastle tools.
Other
2.19k stars 367 forks source link

Unable to build .shfbproj using dotnet CLI - Works fine using SHFB GUI #1076

Closed Matheos96 closed 1 week ago

Matheos96 commented 1 month ago

We want to make the building of our SandCastle project a part of a script. The project has Presentation Style = Markdown Content and Framework version: .NET Core/.NET Standard/.NET 5.0+

This builds fine using the Sandcastle Help File Builder GUI but when I try to build it using dotnet CLI I get the following error:

image

The log does not tell me much either...

<buildStep step="GenerateReflectionInfo">
Generating reflection information...
[C:\Program Files\dotnet\dotnet.exe - GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
Build started 14.8.2024 17.33.16.
     1&gt;Project &quot;D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj&quot; on node 1 (default targets).
     1&gt;PrepareForBuild:
         Creating directory &quot;obj\Debug\&quot;.
       GenerateRefInfo:
         Microsoft.Build (v17.11.0-preview-24318-05+4a45d56330882a5e596e97d05ba568ec32e0603c)
         &#169; Microsoft Corporation. All rights reserved.
         No source code context base path specified.  Source context information is unavailable.
         Loaded 6 assemblies for reflection and 139 dependency assemblies.
     1&gt;MRefBuilder : error : An unexpected error occurred trying to execute the MRefBuilder MSBuild task: System.NullReferenceException: Object reference not set to an instance of an object. [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.ManagedReflectionWriter.WriteParameter(Parameter parameter) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.ManagedReflectionWriter.WriteParameters(ParameterList parameters) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.ManagedReflectionWriter.WriteMember(Member member, TypeNode type, Boolean includeSourceCodeContext) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.ManagedReflectionWriter.WriteMember(Member member, Boolean includeSourceContext) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.ManagedReflectionWriter.VisitMember(Member member) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.Reflection.ApiVisitor.VisitMembers(MemberList members) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.Reflection.ApiVisitor.VisitType(TypeNode type) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.ManagedReflectionWriter.VisitType(TypeNode type) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.Reflection.ApiVisitor.VisitTypes(TypeNodeList types) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.Reflection.ApiVisitor.VisitNamespace(Namespace space) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.ManagedReflectionWriter.VisitNamespace(Namespace space) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.Reflection.ApiVisitor.VisitNamespaces(NamespaceList spaces) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.ManagedReflectionWriter.VisitNamespaces(NamespaceList spaces) [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.Reflection.ApiVisitor.VisitApis() [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.MSBuild.MRefBuilder.GenerateReflectionInformation() [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
MRefBuilder : error :    at Sandcastle.Tools.MSBuild.MRefBuilder.Execute() [D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj]
     1&gt;Done Building Project &quot;D:\SVN\development\TXP\Products\SDKsandCastle\API Documentation\Working\GenerateRefInfo-e54b5bd8-4f49-41cf-844e-eb5fc48b57db.proj&quot; (default targets) -- FAILED.
    Last step completed in 00:00:01,5102
</buildStep>
<buildStep step="Failed">

SHFB: Error BE0043: Unexpected error detected in last build step.  See build log for details.
   at SandcastleBuilder.Utils.BuildEngine.TaskRunner.Run(String processFilename, String targetFile, String arguments)
   at SandcastleBuilder.Utils.BuildEngine.TaskRunner.Run(String processFilename, String targetFile, String arguments)
   at SandcastleBuilder.Utils.BuildEngine.TaskRunner.RunProject(String projectFile, Boolean minimalOutput)
   at SandcastleBuilder.Utils.BuildEngine.BuildProcess.Build()

</buildStep>

I tried both using dotnet build and dotnet msbuild. Any tips?

EWSoftware commented 1 month ago

Are you using the latest version? Do you have an example I can use to try and reproduce the issue?

Matheos96 commented 1 month ago

Yes I am using version 2024.2.18.0.

I am actually unable to create an example. It does seem to be .csproj specific though as if I made a copy of the .shfbproj and dropped all Documentation Sources and added my own, dummy .NET Standard 2.0 project it actually works fine...

I even tried copying basically all the contents of a problematic .csproj into my dummy .csproj but it still works...

Obviously I cannot really post our projects here so I am unsure what to try next.. Something that the other projects are producing is causing the issue

EWSoftware commented 1 month ago

You can try excluding types to perhaps find which one is causing the issue. If you can narrow it down, try limiting it to specific members of the type to see if you can find the cause. If you can create a test case that way, I can look into it.

Matheos96 commented 4 weeks ago

Thanks for the tip. Using filters, I was able to pin it down to a single method declaration to find the culprit (or at least one of them). As of writing this message, I did not have time to verify if the issue is also caused by other types or not... It could well be the same issue in multiple places in our code base, which is likely.

In the end, the culrpit I found is our usage and references of the System.Drawing.Image class. It is not too known to me, so I cannot speak to as why we use it etc. In the attached repro solution you will find a single interface with a single method declaration which takes a parameter of this type. This is enough to cause our issue with dotnet build (works using the GUI though, as I said..). I have not tested whether this is specific to interfaces, or even specific to parameters. It may well reproduce wherever the type is used.

SandCastleErrorRepro.zip

To use the sample, simply build the .csproj (.NET Standard 2.0) and then try building the Sandcastle project using dotnet build. There will be an error and a log file similar to the original post. Then you can verify that it works when building using the GUI.

Thanks a ton for looking into this!

Matheos96 commented 3 weeks ago

@EWSoftware Have you gotten around to checking out the sample? I don't mean to rush you, we are just eagerly waiting :)

EWSoftware commented 3 weeks ago

I can reproduce the error but I haven't had time to try and figure out why it is happening.

Matheos96 commented 3 weeks ago

Okay, no worries. Thanks for the update :) Glad it at least is not only "on my machine" 😆