mhutch / MonoDevelop.MSBuildEditor

Improved MSBuild editing support
Other
228 stars 26 forks source link

ArgumentNullException thrown by MSBuildExtensionLogger #229

Closed martincostello closed 6 months ago

martincostello commented 6 months ago

I happened to spot this error in Visual Studio:

Error: Unhandled error in SDK resolver
  System.ArgumentNullException: Value cannot be null.
  Parameter name: source
     at System.Linq.Enumerable.Append[TSource](IEnumerable`1 source, TSource element)
     at MonoDevelop.MSBuild.Editor.VisualStudio.Logging.MSBuildExtensionLogger.Log[TState](String categoryName, IEnumerable`1 properties, LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter) in D:\a\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuild.Editor.VisualStudio\Logging\MSBuildExtensionLogger.cs:line 108
     at MonoDevelop.MSBuild.Editor.VisualStudio.Logging.MSBuildExtensionLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter) in D:\a\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuild.Editor.VisualStudio\Logging\MSBuildExtensionLogger.cs:line 67
     at MonoDevelop.MSBuild.Editor.VisualStudio.Logging.MSBuildEditorLogger.BeginScope[TState](TState state) in D:\a\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuild.Editor.VisualStudio\Logging\MSBuildEditorLogger.cs:line 34
     at MonoDevelop.MSBuild.SdkResolution.MSBuildSdkResolver.ResolveSdk(SdkReference sdk, String projectFile, String solutionPath, ILogger logger) in D:\a\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuild\SdkResolution\MSBuildSdkResolver.cs:line 52
     at MonoDevelop.MSBuild.CurrentProcessMSBuildEnvironment.ResolveSdk(ValueTuple`3 sdk, String projectFile, String solutionPath, ILogger logger) in D:\a\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuildEditor\MonoDevelop.MSBuild\CurrentProcessMSBuildEnvironment.cs:line 

Looks like there's a missing null check here for IEnumerable<KeyValuePair<string, string>>? properties:

https://github.com/mhutch/MonoDevelop.MSBuildEditor/blob/dc7c2506c6860b04f6d63da4993e36c26dbe7536/MonoDevelop.MSBuild.Editor.VisualStudio/Logging/MSBuildExtensionLogger.cs#L106-L109