Doraku / DefaultDocumentation

Create a simple markdown documentation from the Visual Studio xml one.
MIT No Attribution
157 stars 26 forks source link

msbuild task fails with ParameterizedType cast #49

Closed cdhanna closed 3 years ago

cdhanna commented 3 years ago

Hi, I'm getting this error when I build my project. I'm using version 0.7.2

DefaultDocumentation.targets(38, 5): [MSB4018] The "DefaultDocumentationTask" task failed unexpectedly.
System.Exception: Error while writing documentation for BrewedInk.WFC.ModuleSet
 ---> System.InvalidCastException: Unable to cast object of type 'ICSharpCode.Decompiler.TypeSystem.ParameterizedType' to type 'ICSharpCode.Decompiler.TypeSystem.ITypeDefinition'.
   at DefaultDocumentation.Writer.MarkdownWriter.WriteInheritances(DocItem item) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\MarkdownWriter.cs:line 403
   at DefaultDocumentation.Writer.MarkdownWriter.WriteItem(DocItem item) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\MarkdownWriter.cs:line 537
   at DefaultDocumentation.Writer.MarkdownWriter.WritePage(DirectoryInfo directory, DocItem item) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\MarkdownWriter.cs:line 607
   at DefaultDocumentation.Writer.DocItemWriter.Execute() in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\DocItemWriter.cs:line 121
   --- End of inner exception stack trace ---
   at DefaultDocumentation.Writer.DocItemWriter.Execute() in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\DocItemWriter.cs:line 125
   at DefaultDocumentation.Generator.Execute(Settings settings) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Generator.cs:line 7
   at DefaultDocumentation.DefaultDocumentationTask.Execute() in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation\DefaultDocumentationTask.cs:line 42
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

The csproj file looks like this...

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Library</OutputType>
        <TargetFramework>net5.0</TargetFramework>
        <OutputPath>$(MSBuildProjectDirectory)\..\..\bin\Debug\</OutputPath>
        <BaseIntermediateOutputPath>$(MSBuildProjectDirectory)\..\..\obj\Debug</BaseIntermediateOutputPath>
        <IntermediateOutputPath>$(MSBuildProjectDirectory)\..\..\obj\</IntermediateOutputPath>

    </PropertyGroup>

    <PropertyGroup>
        <DocumentationFile>$(MSBuildProjectDirectory)\..\Documentation~\CodeDocs\brewkedink.wfc.docs.xml</DocumentationFile>
        <DisableDefaultDocumentation />
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="DefaultDocumentation" Version="0.7.2">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      </PackageReference>
      <PackageReference Include="Unity3D.UnityEngine" Version="2018.3.5.1" />
    </ItemGroup>
</Project>

BrewedInk.WFC.ModuleSet is some code I am writing in the project. I'm not sure if its worth putting the source code here for it or not. I'll post it here just in case...

    /// <summary>
    /// A ModuleSet is a collection of modules. It is a HashSet, with a few helpful methods attached to it. 
    /// </summary>
    [Serializable]
    public class ModuleSet : HashSet<Module>
    {
        public ModuleSet()
        {

        }

        public ModuleSet(IEnumerable<Module> other) : base(other)
        {

        }

        public ModuleSet(params Module[] modules) : base(modules){}

        public List<Module> ModuleList => this.ToList();

        public Module FindByDisplay(string display)
        {
            return this.FirstOrDefault(m => m.Display.Equals(display));
        }

        public Module FindByDisplay(Module module)
        {
            return FindByDisplay(module.Display);
        }

        public ModuleSet ProduceConstraints<TModule>(ConstraintGenerator<TModule> constraintGenerator) where TModule: Module
        {
            var originalSet = this.ToList();
            var next = new ModuleSet();
            foreach (var source in originalSet)
            {
                var typedSource = source as TModule;
                var newConstraints = new List<ModuleConstraint>();
                if (constraintGenerator.CreateConstraints(typedSource, out var singleConstraints))
                {
                    newConstraints.AddRange(singleConstraints);
                }
                foreach (var target in originalSet)
                {
                    // TODO: The type checking here feels wrong...
                    if (constraintGenerator.CreateConstraints(typedSource, target as TModule, out var constraints))
                    {
                        newConstraints.AddRange(constraints);
                    }
                }
                var copy = constraintGenerator.Copy(typedSource, newConstraints);
                next.Add(copy);
            }
            return next;
        }
    }

Any advice?

Doraku commented 3 years ago

Hello, yeah this as already been identified and fixed, I just pushed version 0.7.3 it should be available soon if not already. Sorry for missing this problem in the previous release ^^". Tell me if it fixed your problem.

cdhanna commented 3 years ago

Wow, thanks! Yes, I just confirmed that 0.7.3 fixes the issue!

Doraku commented 3 years ago

great to hear!