KirillOsenkov / MSBuildStructuredLog

A logger for MSBuild that records a structured representation of executed targets, tasks, property and item values.
MIT License
1.44k stars 190 forks source link

NullReferenceException when loading binlog #561

Closed rolfbjarne closed 2 years ago

rolfbjarne commented 2 years ago

Test case:

log-Build-20220202_162411.binlog.zip

Opening on macOS results in (latest Avalonia version as of today):

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Build.Logging.StructuredLogger.MessageProcessor.AddItems(IEnumerable items, TreeNode parent) in C:\projects\msbuildstructuredlog\src\StructuredLogger\Construction\MessageProcessor.cs:line 268
   at Microsoft.Build.Logging.StructuredLogger.MessageProcessor.ProcessTaskParameter(TaskParameterEventArgs args) in C:\projects\msbuildstructuredlog\src\StructuredLogger\Construction\MessageProcessor.cs:line 224
   at Microsoft.Build.Logging.StructuredLogger.MessageProcessor.Process(BuildMessageEventArgs args) in C:\projects\msbuildstructuredlog\src\StructuredLogger\Construction\MessageProcessor.cs:line 37
   at Microsoft.Build.Logging.StructuredLogger.Construction.MessageRaised(Object sender, BuildMessageEventArgs args) in C:\projects\msbuildstructuredlog\src\StructuredLogger\Construction\Construction.cs:line 417
Screen Shot 2022-02-02 at 16 31 22

Online results:

Screen Shot 2022-02-02 at 16 31 34
KirillOsenkov commented 2 years ago

Interesting, this is because in this case it logs a TaskParameterEventArgs with kind SkippedTargetOutputs and null ItemName and Items list: image

Probably need to make a change to MSBuild to not log the event args in the first place.

For now I'll just add a null check in the viewer.

KirillOsenkov commented 2 years ago

Found a repro:

<Project>

  <ItemGroup>
    <_CodesignItems Include="foo" />
  </ItemGroup>

  <Target Name="Build"
          Inputs="@(_CodesignItems)"
          Outputs="@(_CodesignItems -> '%(CodesignStampFile)')">
  </Target>

</Project>
KirillOsenkov commented 2 years ago

Filed https://github.com/dotnet/msbuild/issues/7362

KirillOsenkov commented 2 years ago

I suspect you don't need me to republish the Windows viewer since you're using the Avalonia and the Live one. I'll include this fix with the next batch of fixes and updates.

KirillOsenkov commented 2 years ago

@rolfbjarne the CodesignStampFile metadata is missing on this item, not sure if intentional: image

rolfbjarne commented 2 years ago

@KirillOsenkov thanks! I was eventually able to figure out that that was the problem, but it's certainly easier when the viewer works :)