CsprojModifier
CsprojModifier copied to clipboard
NullReferenceException with VSCode.
Error occured when I tried to modify csproj following the readme.
- OS: macOS Sonoma 14.5 (Apple Silicon, Apple M1 Max)
- Unity 6(Preview)/ Unity 2023.2.201f
- Visual Studio Code 1.94.2 (EXTENTIONS: C#, C# Dev Kit, Unity, .NET Install Tool, vscode-solution-explorer)
- Visual Studio Editor 2.0.22 (installed Unity Package Manager)
- Additional project imports: (file name) LangVersion.props
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
- Error:
NullReferenceException: Object reference not set to an instance of an object
CsprojModifier.Editor.Features.InsertAdditionalImportFeature.OnGeneratedCSProject (System.String path, System.String content) (at ./Library/PackageCache/com.cysharp.csprojmodifier/Editor/Features/InsertAdditionalImportFeature.cs:157)
CsprojModifier.Editor.CsprojModifierFeatureProvider+<>c__DisplayClass4_0.<OnGeneratedCSProject>b__0 (System.String r, CsprojModifier.Editor.Features.ICsprojModifierGeneratedFileProcessor x) (at ./Library/PackageCache/com.cysharp.csprojmodifier/Editor/CsprojModifierFeatureProvider.cs:22)
System.Linq.Enumerable.Aggregate[TSource,TAccumulate] (System.Collections.Generic.IEnumerable`1[T] source, TAccumulate seed, System.Func`3[T1,T2,TResult] func) (at <219b9aa5d50c4ce08e2a41cea5b36ecd>:0)
CsprojModifier.Editor.CsprojModifierFeatureProvider.OnGeneratedCSProject (System.String path, System.String content) (at ./Library/PackageCache/com.cysharp.csprojmodifier/Editor/CsprojModifierFeatureProvider.cs:22)
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <a6d715f5ce8c4754a140b50ff638878a>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <a6d715f5ce8c4754a140b50ff638878a>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <a6d715f5ce8c4754a140b50ff638878a>:0)
Microsoft.Unity.VisualStudio.Editor.ProjectGeneration.InvokeAssetPostProcessorGenerationCallbacks (System.String name, System.String path, System.String content) (at ./Library/PackageCache/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs:457)
Microsoft.Unity.VisualStudio.Editor.ProjectGeneration.OnGeneratedCSProject (System.String path, System.String content) (at ./Library/PackageCache/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs:470)
Microsoft.Unity.VisualStudio.Editor.ProjectGeneration.SyncProjectFileIfNotChanged (System.String path, System.String newContents) (at ./Library/PackageCache/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs:406)
Microsoft.Unity.VisualStudio.Editor.ProjectGeneration.SyncProject (UnityEditor.Compilation.Assembly assembly, System.Collections.Generic.Dictionary`2[TKey,TValue] allAssetsProjectParts, UnityEditor.Compilation.ResponseFileData[] responseFilesData) (at ./Library/PackageCache/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs:397)
Microsoft.Unity.VisualStudio.Editor.ProjectGeneration.GenerateAndWriteSolutionAndProjects () (at ./Library/PackageCache/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs:293)
Microsoft.Unity.VisualStudio.Editor.ProjectGeneration.Sync () (at ./Library/PackageCache/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs:193)
Microsoft.Unity.VisualStudio.Editor.VisualStudioEditor.RegenerateProjectFiles (Microsoft.Unity.VisualStudio.Editor.IVisualStudioInstallation installation) (at ./Library/PackageCache/com.unity.ide.visualstudio/Editor/VisualStudioEditor.cs:155)
Microsoft.Unity.VisualStudio.Editor.VisualStudioEditor.OnGUI () (at ./Library/PackageCache/com.unity.ide.visualstudio/Editor/VisualStudioEditor.cs:145)
UnityEditor.PreferencesProvider.ShowExternalApplications (System.String searchContext) (at /Users/bokken/build/output/unity/unity/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:422)
UnityEditor.PreferencesProvider.OnGUI (System.String searchContext, System.Action`1[T] drawAction) (at /Users/bokken/build/output/unity/unity/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:406)
UnityEditor.PreferencesProvider+<>c__DisplayClass77_0.<CreateExternalToolsProvider>b__0 (System.String searchContext) (at /Users/bokken/build/output/unity/unity/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:297)
UnityEditor.SettingsProvider.OnGUI (System.String searchContext) (at /Users/bokken/build/output/unity/unity/Editor/Mono/Settings/SettingsProvider.cs:103)
UnityEditor.SettingsWindow.DrawControls () (at /Users/bokken/build/output/unity/unity/Editor/Mono/Settings/SettingsWindow.cs:485)
UnityEditor.SettingsWindow.DrawSettingsPanel () (at /Users/bokken/build/output/unity/unity/Editor/Mono/Settings/SettingsWindow.cs:456)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/IMGUIContainer.cs:429)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/IMGUIContainer.cs:718)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/IMGUIContainer.cs:690)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/IMGUIContainer.cs:683)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/IMGUIContainer.cs:643)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/IMGUIContainer.cs:632)
UnityEngine.UIElements.IMGUIContainer.HandleEventBubbleUp (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/IMGUIContainer.cs:782)
UnityEngine.UIElements.CallbackEventHandler.HandleEventBubbleUpInternal (UnityEngine.UIElements.EventBase evt) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/Events/EventHandler.cs:283)
UnityEngine.UIElements.EventDispatchUtilities.HandleEvent_BubbleUpHandleEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement element, System.Boolean disabled) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/Events/EventDispatchUtilities.cs:409)
UnityEngine.UIElements.EventDispatchUtilities.HandleEvent_BubbleUpAllDefaultActions (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement element, System.Boolean disabled, System.Boolean isCapturingTarget) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/Events/EventDispatchUtilities.cs:422)
UnityEngine.UIElements.EventDispatchUtilities.HandleEventAcrossPropagationPathWithCompatibilityEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.EventBase compatibilityEvt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement target, System.Boolean isCapturingTarget) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/Events/EventDispatchUtilities.cs:301)
UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.VisualElement target, System.Boolean isCapturingTarget) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/Events/EventDispatchUtilities.cs:57)
UnityEngine.UIElements.EventDispatchUtilities.DispatchToCapturingElement (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, System.Int32 pointerId, UnityEngine.Vector2 position) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/Events/EventDispatchUtilities.cs:616)
UnityEngine.UIElements.EventDispatchUtilities.DispatchToCapturingElementOrElementUnderPointer (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, System.Int32 pointerId, UnityEngine.Vector2 position) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/Events/EventDispatchUtilities.cs:578)
UnityEngine.UIElements.PointerEventBase`1[T].Dispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/Events/PointerEvents.cs:1188)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/EventDispatcher.cs:415)
UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/EventDispatcher.cs:215)
UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/Panel.cs:590)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/UIElementsUtility.cs:513)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/UIElementsUtility.cs:232)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/UIElementsUtility.cs:76)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at /Users/bokken/build/output/unity/unity/Modules/UIElements/Core/UIElementsUtility.cs:30)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:219)
-
I found
projectEis null, becausecontentdoes not have "http://schemas.microsoft.com/developer/msbuild/2003"; https://github.com/Cysharp/CsprojModifier/blob/8887279e53782dd07fad3e5961888d5d3f50ba05/src/CsprojModifier/Assets/CsprojModifier/Editor/Features/InsertAdditionalImportFeature.cs#L145-L148 -
I think this is because Visual Studio Editor create csproj header without the url, only
<Project ToolsVersion=""Current"">. -
When I use Visual Studio for Mac(no longer supported), no error occurs.