MrefBuilder Unhandled Exception with DocumentPrivates

Topics: User Forum
Jun 23, 2011 at 2:00 PM

I enabled DocumentPrivates and DocumentExplictInterfaceImplementations so that <inheritdoc/> would work.   However I am getting an unhandled exception with no clear indication of what input is causing the failure.  Here is the log.

<?xml version="1.0" encoding="utf-8"?>
<shfbBuild product="Sandcastle Help File Builder Utilities" version="1.9.3.0" projectFile="C:\Code\Shared Projects\vs2010\Hsb\Hsb .NET  Libraries - Sandcastle Documentation\Src\HSB .NET Libraries.shfbproj" started="6/23/2011 8:51:42 AM">
<buildStep step="Initializing">
</buildStep>
<buildStep step="FindingTools">
Finding tools...
Found Sandcastle tools in &#39;C:\Program Files\Sandcastle\&#39;
</buildStep>
<buildStep step="ValidatingDocumentationSources">
Validating and copying documentation source information
Source: C:\Code\Shared Projects\vs2010\Hsb\Hsb.Data\src\Hsb.Data\Hsb.Data.vbproj
    Found project &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Data\src\Hsb.Data\Hsb.Data.vbproj&#39;
Source: C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Configuration\Hsb.EnterpriseLibrary.Configuration\Hsb.EnterpriseLibrary.Configuration.csproj
    Found project &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Configuration\Hsb.EnterpriseLibrary.Configuration\Hsb.EnterpriseLibrary.Configuration.csproj&#39;
Source: C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Logging\Hsb.EnterpriseLibrary.Logging\Hsb.EnterpriseLibrary.Logging.csproj
    Found project &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Logging\Hsb.EnterpriseLibrary.Logging\Hsb.EnterpriseLibrary.Logging.csproj&#39;
Source: C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Validation\Hsb.EnterpriseLibrary.Validation\Hsb.EnterpriseLibrary.Validation.vbproj
    Found project &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Validation\Hsb.EnterpriseLibrary.Validation\Hsb.EnterpriseLibrary.Validation.vbproj&#39;
Source: C:\Code\Shared Projects\vs2010\Hsb\Hsb.ServiceModel\src\Hsb.ServiceModel\Hsb.ServiceModel.vbproj
    Found project &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.ServiceModel\src\Hsb.ServiceModel\Hsb.ServiceModel.vbproj&#39;
Source: C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web.Security.AppSec\src\Hsb.Web.Security.AppSec\Hsb.Web.Security.AppSec.vbproj
    Found project &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web.Security.AppSec\src\Hsb.Web.Security.AppSec\Hsb.Web.Security.AppSec.vbproj&#39;
Source: C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web\src\Hsb.Web\Hsb.Web.vbproj
    Found project &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web\src\Hsb.Web\Hsb.Web.vbproj&#39;
Source: C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web.Xml\src\Hsb.Web.Xml\Hsb.Web.Xml.vbproj
    Found project &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web.Xml\src\Hsb.Web.Xml\Hsb.Web.Xml.vbproj&#39;
Source: C:\Code\Shared Projects\vs2010\Hsb\Hsb.Xml\src\Hsb.Xml\Hsb.Xml.vbproj
    Found project &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Xml\src\Hsb.Xml\Hsb.Xml.vbproj&#39;

Parsing project files
    Found assembly &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Data\src\Hsb.Data\bin\Debug\Hsb.Data.dll&#39;
    Found assembly &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Configuration\Hsb.EnterpriseLibrary.Configuration\bin\Debug\Hsb.EnterpriseLibrary.Configuration.dll&#39;
    Found assembly &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Logging\Hsb.EnterpriseLibrary.Logging\bin\Debug\Hsb.EnterpriseLibrary.Logging.dll&#39;
    Found assembly &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Validation\Hsb.EnterpriseLibrary.Validation\bin\Debug\Hsb.EnterpriseLibrary.Validation.dll&#39;
    Found assembly &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.ServiceModel\src\Hsb.ServiceModel\bin\Debug\Hsb.ServiceModel.dll&#39;
    Found assembly &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web.Security.AppSec\src\Hsb.Web.Security.AppSec\bin\Debug\Hsb.Web.Security.AppSec.dll&#39;
    Found assembly &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web\src\Hsb.Web\bin\Debug\Hsb.Web.dll&#39;
    Found assembly &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web.Xml\src\Hsb.Web.Xml\bin\Debug\Hsb.Web.Xml.dll&#39;
    Found assembly &#39;C:\Code\Shared Projects\vs2010\Hsb\Hsb.Xml\src\Hsb.Xml\bin\Debug\Hsb.Xml.dll&#39;

References to use:
    AjaxControlToolkit
    Csla
    Microsoft.CSharp
    Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
    Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
    Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
    Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
    Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
    System
    System.ComponentModel.DataAnnotations
    System.configuration
    System.Configuration
    System.Core
    System.Data
    System.Data.DataSetExtensions
    System.Design
    System.Drawing
    System.IdentityModel
    System.IdentityModel.Selectors
    System.Management
    System.Runtime.Serialization
    System.ServiceModel
    System.ServiceModel.Channels
    System.ServiceModel.Web
    System.Transactions
    System.Web
    System.Web.ApplicationServices
    System.Web.Extensions
    System.Web.Services
    System.Xml
    System.Xml.Linq

Copying XML comments files
    C:\Code\Shared Projects\vs2010\Hsb\Hsb.Data\src\Hsb.Data\bin\Debug\Hsb.Data.xml -&gt; C:\Code\Shared Projects\vs2010\Hsb\Hsb .NET  Libraries - Sandcastle Documentation\Src\output\Working\Hsb.Data.xml
    C:\Code\Shared Projects\vs2010\Hsb\Hsb.EnterpriseLibrary\src\Hsb.EnterpriseLibrary.Validation\Hsb.EnterpriseLibrary.Validation\bin\Debug\Hsb.EnterpriseLibrary.Validation.xml -&gt; C:\Code\Shared Projects\vs2010\Hsb\Hsb .NET  Libraries - Sandcastle Documentation\Src\output\Working\Hsb.EnterpriseLibrary.Validation.xml
    C:\Code\Shared Projects\vs2010\Hsb\Hsb.ServiceModel\src\Hsb.ServiceModel\bin\Debug\Hsb.ServiceModel.xml -&gt; C:\Code\Shared Projects\vs2010\Hsb\Hsb .NET  Libraries - Sandcastle Documentation\Src\output\Working\Hsb.ServiceModel.xml
    C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web.Security.AppSec\src\Hsb.Web.Security.AppSec\bin\Debug\Hsb.Web.Security.AppSec.xml -&gt; C:\Code\Shared Projects\vs2010\Hsb\Hsb .NET  Libraries - Sandcastle Documentation\Src\output\Working\Hsb.Web.Security.AppSec.xml
    C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web\src\Hsb.Web\bin\Debug\Hsb.Web.xml -&gt; C:\Code\Shared Projects\vs2010\Hsb\Hsb .NET  Libraries - Sandcastle Documentation\Src\output\Working\Hsb.Web.xml
    C:\Code\Shared Projects\vs2010\Hsb\Hsb.Web.Xml\src\Hsb.Web.Xml\bin\Debug\Hsb.Web.Xml.xml -&gt; C:\Code\Shared Projects\vs2010\Hsb\Hsb .NET  Libraries - Sandcastle Documentation\Src\output\Working\Hsb.Web.Xml.xml
    C:\Code\Shared Projects\vs2010\Hsb\Hsb.Xml\src\Hsb.Xml\bin\Debug\Hsb.Xml.xml -&gt; C:\Code\Shared Projects\vs2010\Hsb\Hsb .NET  Libraries - Sandcastle Documentation\Src\output\Working\Hsb.Xml.xml
</buildStep>
<buildStep step="GenerateSharedContent">
Generating shared content files (en-US, English (United States))...
    Last step completed in 00:00:00.0050
</buildStep>
<buildStep step="GenerateApiFilter">
Generating API filter for MRefBuilder...
    Last step completed in 00:00:00.0060
</buildStep>
<buildStep step="GenerateReflectionInfo">
Generating reflection information...
[C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe]
  MrefBuilder (v2.6.10621.1)
  Copyright c Microsoft 2006
  Info: Loaded 9 assemblies for reflection and 30 dependency assemblies.
  
  Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
     at Microsoft.Ddue.Tools.Reflection.ReflectionUtilities.GetNamespace(TypeNode type)
     at Microsoft.Ddue.Tools.Reflection.NamespaceFilter.IsExposedMember(Member member)
     at Microsoft.Ddue.Tools.Reflection.RootFilter.IsExposedMember(Member member)
     at Microsoft.Ddue.Tools.Reflection.ApiFilter.IsExposedMember(Member member)
     at Microsoft.Ddue.Tools.Reflection.AllDocumentedFilter.IsExposedMember(Member member)
     at Microsoft.Ddue.Tools.ExtensionMethodAddIn.RecordExtensionMethods(XmlWriter writer, Object info)
     at Microsoft.Ddue.Tools.ManagedReflectionWriter.StartElementCallbacks(String name, Object info)
     at Microsoft.Ddue.Tools.ManagedReflectionWriter.VisitNamespaces(NamespaceList spaces)
     at Microsoft.Ddue.Tools.Reflection.ApiVisitor.VisitApis()
     at Microsoft.Ddue.Tools.MRefBuilder.Main(String[] args)
C:\Code\Shared Projects\vs2010\Hsb\Hsb .NET  Libraries - Sandcastle Documentation\Src\output\Working\GenerateRefInfo.proj(119,5): error MSB6006: &quot;MRefBuilder.exe&quot; exited with code -1073741819.
    Last step completed in 00:00:10.1720
</buildStep>
<buildStep step="Failed">

SHFB: Error BE0043: Unexpected error detected in last build step.  See output above for details.

</buildStep>
</shfbBuild>
Coordinator
Jun 26, 2011 at 11:29 PM

It's MRefBuilder that's failing, one of the Sandcastle tools, so it's hard to say what it didn't like.  Are any of the assemblies obfuscated?  It sometimes has trouble if any of them are.  You might take a look in the .\Working folder in the project output folder for the reflection.xml file.  If it has any content, the last entry in it might point you to the assembly with which it's having trouble.

Eric

 

Jun 27, 2011 at 1:46 PM

There are no obfuscated assemblies that I am aware of.  I am documenting our own code which we have source for. 

Our projcts have references to .NET Framework, Ajax Control Toolkit, Enterprise Library and CSLA, none of which are obfuscated as far as I am aware.

A reflection.org file is generated and it is a well formed XML file (i.e. complete) but it has not been copied to reflection.xml by the time the build fails.

I tried to include the contents of reflection.org here but after hitting the save button, the browser was trying to download a file from codeplex and the post didn't save.

Coordinator
Jun 27, 2011 at 4:13 PM

Posting the content here wouldn't help anyway.  It was just a suggestion that may help you track down in which assembly MRefBuilder failed.

Eric

 

Jan 31, 2012 at 4:49 PM

Hi,

My help build was failing with the same stack trace. It's a .NET 4 project using code contracts. The code is signed but not obfuscated.

After investigating, I managed to track down the problem to the following method:

 

    [Pure]
    public static bool IsSorted<T>(IList<T> list, IList<int> index) where T : IComparable<T>
    {
      Contract.Requires(list != null); // (1)
      IEnumerable<T> elements = index.Select(i => list[i]); // (2)
      return true;
    }

 

(this is a cut-down version of the original, with just enough content to recreate the error).

If either (1) or (2) is removed, the help seems to build okay. If they are both present, I get the "MrefBuilder Unhandled Exception with DocumentPrivates" error and the log includes:

  Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
     at Microsoft.Ddue.Tools.Reflection.ReflectionUtilities.GetNamespace(TypeNode type)
     at Microsoft.Ddue.Tools.Reflection.NamespaceFilter.IsExposedMember(Member member)
     at Microsoft.Ddue.Tools.Reflection.RootFilter.IsExposedMember(Member member)
     at Microsoft.Ddue.Tools.Reflection.ApiFilter.IsExposedMember(Member member)
     at Microsoft.Ddue.Tools.Reflection.AllDocumentedFilter.IsExposedMember(Member member)
     at Microsoft.Ddue.Tools.ExtensionMethodAddIn.RecordExtensionMethods(XmlWriter writer, Object info)
     at Microsoft.Ddue.Tools.ManagedReflectionWriter.StartElementCallbacks(String name, Object info)
     at Microsoft.Ddue.Tools.ManagedReflectionWriter.VisitNamespaces(NamespaceList spaces)
     at Microsoft.Ddue.Tools.Reflection.ApiVisitor.VisitApis()
     at Microsoft.Ddue.Tools.MRefBuilder.Main(String[] args)

I've fixed this by rewriting the LINQ line to do the same thing without using LINQ, but it would be good to have a fix so other people don't hit the same issue.

Regards,

Matthew

Jan 31, 2012 at 6:22 PM

@maddax - May I ask how you were able to track the issue down to particular lines of code?   That could help in my case as well.  Your issue seems to be specific enough to warrant opening an issue at the Sandcastle project site.

Jan 31, 2012 at 7:29 PM

@rcollette Luckily the commit that first broke our document build only had three changed files in it. It's still taken a long time to pinpoint the issue. The behaviour described above actually happened in two methods, and the error could be switched on and off quite reliably. Both methods were generic, used code contracts and contained a LINQ select. In both cases, rewriting the LINQ longhand seems to have fixed it.

Perhaps Eric can try recreating this and confirm whether it's a problem in Visual Studio, Sandcastle or SHFB.

Coordinator
Jan 31, 2012 at 9:18 PM

I'm pretty sure it's related to this already reported bug: http://sandcastle.codeplex.com/workitem/11066

My guess is that MRefBuilder is having a problem with one of the compiler generated closures for the LINQ expression if rewriting them makes it go away.  I'll see about getting it fixed.

Eric

 

Coordinator
Feb 1, 2012 at 8:23 PM

I tried duplicating the problem with the code snippet above but MRefBuilder handled it just fine both built from the code and the one from the June 2010 release.  It's probably related to the structure of the assembly as a whole.  Can you provide an example that does fail or e-mail me the assembly that's failing and any necessary references so that I can duplicate it?  Thanks.

Eric

 

Feb 2, 2012 at 10:24 AM

Eric,

Thank you for looking into this.

I was able to recreate it in a simple console project. For reference, I've also uploaded the chm file that built successfully when I commented out the Contract.Requires line from Program.cs.

I'm using Visual Studio 2010 and building the docs using the SHFB VS extension (v1.9.3.3).

FWIW, the problem only happened when I turned on all the visibility options in the .shfbproj, even though everything is public. I suspect the problem may have something to do with the code contracts rewriter changing the assembly in a way that MRefBuilder can't cope with.

Let me know whether you manage to recreate the problem at your end, or if you need me to do some more digging.

Matthew

Coordinator
Feb 2, 2012 at 8:32 PM

Thanks for the test case.  The code contract stuff apparently did make the difference, probably something in one of the private classes or members that got included by documenting the internals too.  Is that only in VS Premium or Ultimate or is that an add-in or extension package?  I was able to see that it failed with the June 2010 release.  The good news is that it works just fine with the copy of MRefBuilder built from the source code.  It didn't hit any of my other patches so it doesn't appear to be related to any fixes I've made so far.  I do know there were some minor differences between the source code and the tools that actually got released in the June 2010 version due to their internal version getting out of synch with the CodePlex version so the bug was apparently fixed in the source version on CodePlex but not their internal version they built the release off of.

In case you havent' seen my post over in the Sandcastle project discussion page, I'm working on getting added as coordinator on the project so that I can fix the bugs and publish updates to it.  It'll take about four weeks for that to happen so I'm working on the fixes while I wait.

Eric

 

Feb 2, 2012 at 8:35 PM

Fantastic news about becoming a coordinator.  There seems to only be a few inhibitive bugs at the moment and hopefully you'll be able to get them sorted out.  I appreaciate your work immensely.

Feb 2, 2012 at 8:48 PM

Thanks Eric. That all sounds very positive.

The code contracts stuff requires an extension (see the download link here); without it, the code will compile but won't get post-processed to do the checking. The extension runs on all editions of Visual Studio except Express.

Matthew