I'm encountering a System.AccessViolationException
while working in Visual Studio 2022. The error occurs specifically when I try to add a new UI or CLR item to a project using the IVsProject.AddItem()
method. Below is the full exception log:
Aplicación: devenv.exe
Versión de Framework: v4.0.30319
Descripción: el proceso terminó debido a una excepción no controlada.
Información de la excepción: System.AccessViolationException
en Microsoft.VisualStudio.Shell.Interop.IVsProject.AddItem(UInt32, Microsoft.VisualStudio.Shell.Interop.VSADDITEMOPERATION, System.String, UInt32, System.String[], IntPtr, Microsoft.VisualStudio.Shell.Interop.VSADDRESULT[])
en Microsoft.VisualStudio.Dialogs.ServiceHelper.AddNewItem(Microsoft.VisualStudio.TemplateProviders.Templates.IVsTemplate, System.String, Microsoft.Internal.VisualStudio.Shell.Interop.VSNEWPROJECTDLGCTX, Microsoft.VisualStudio.Shell.Interop.IVsProject, UInt32, Boolean, UInt32, Boolean, System.String, Microsoft.VisualStudio.Dialogs.OpenWithEditorSelection, Boolean)
en Microsoft.VisualStudio.NewProjectDialog.LegacyItemTemplateProvider+<InstantiateItemTemplateAsync>d__14.MoveNext()
en System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
en System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
en System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
en Microsoft.VisualStudio.Threading.JoinableTaskFactory+SingleExecuteProtector.TryExecute()
en Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
en Microsoft.VisualStudio.Threading.JoinableTask`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].CompleteOnCurrentThread()
en Microsoft.VisualStudio.Dialogs.ServiceHelper.AddNewItem(Microsoft.VisualStudio.TemplateProviders.Templates.IVsTemplate, System.String, Microsoft.Internal.VisualStudio.Shell.Interop.VSNEWPROJECTDLGCTX, Microsoft.VisualStudio.Shell.Interop.IVsProject, UInt32, Boolean, UInt32, Boolean, System.String, Microsoft.VisualStudio.Dialogs.OpenWithEditorSelection, Boolean)
en Microsoft.VisualStudio.Dialogs.SVsDialogService.InvokeDialog(Microsoft.Internal.VisualStudio.Shell.Interop.VSNEWPROJECTDLGINFO, System.String ByRef)
en Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchy.ExecCommand(UInt32, System.Guid ByRef, UInt32, UInt32, IntPtr, IntPtr)
en Microsoft.Internal.VisualStudio.PlatformUI.HierarchyUtilities+<>c__DisplayClass35_0.<ExecHierParentChain>b__1()
en Microsoft.VisualStudio.ErrorHandler.CallWithCOMConvention(System.Func`1<Int32>, Boolean, Boolean)
en Microsoft.Internal.VisualStudio.PlatformUI.HierarchyUtilities.ExecHierParentChain(Microsoft.VisualStudio.Shell.IVsHierarchyItemManager, Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchy, Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchy, UInt32, System.Guid ByRef, UInt32, UInt32, IntPtr, IntPtr)
en Microsoft.VisualStudio.PlatformUI.PivotNavigatorCommandTarget.Exec(System.Guid ByRef, UInt32, UInt32, IntPtr, IntPtr)
en Microsoft.VisualStudio.PlatformUI.SolutionNavigatorCommandTarget.Exec(System.Guid ByRef, UInt32, UInt32, IntPtr, IntPtr)
en Microsoft.VisualStudio.Platform.WindowManagement.DocumentObjectSite.<Exec>g__TryHandleExec|82_0(System.Object, Int32 ByRef, <>c__DisplayClass82_0 ByRef)
en Microsoft.VisualStudio.Platform.WindowManagement.DocumentObjectSite.Exec(System.Guid ByRef, UInt32, UInt32, IntPtr, IntPtr)
en Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.Exec(System.Guid ByRef, UInt32, UInt32, IntPtr, IntPtr)
This crash consistently happens when adding UI elements or CLR templates to a project. I have tried repairing Visual Studio, updating it to the latest version, and even reinstalling, but the issue persists. Here are the things I've tried:
- Running Visual Studio as an administrator.
- Checking for corrupted templates or missing dependencies.
- Resetting Visual Studio settings.
Any suggestions on how to resolve or further investigate this issue? What could be causing this AccessViolationException
when adding UI or CLR items?
Environment:
- Visual Studio version: 2022
- OS: Windows 11 24H2
- .NET Framework: v4.0.30319