Search code examples
visual-studioexceptioncompareschema

Unable to compare database schema in Visual Studio 2022 due to exception


I recently got a new laptop and installed Visual Studio 2022 on it. I am trying to compare schema for an SQL Server database project in my solution, but every time I try to select a source or destination, the connection window does not appear. Instead, I'm greeted with an exception window. For the life of me, I have been unable to fix this. I have never faced this issue ever in any of the versions of Visual Studio. I have tried repairing and reinstalling Visual Studio 2022, but to no avail. I couldn't find any specific solutions to this problem online. Can someone guide me in the right direction?

The exception is as below:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.Data.Tools.Package.SharedUtilities.ProjectUtilities.GetGuidOfProject(IVsHierarchy projectNode)
   at Microsoft.VisualStudio.Data.Tools.Package.SchemaCompare2.UI.SchemaCompareConnectionDialog.PopulateProjectCombos()
   at Microsoft.VisualStudio.Data.Tools.Package.SchemaCompare2.UI.SchemaCompareConnectionDialog..ctor(Boolean isSource, ISchemaCompareParticipant participant)
   at Microsoft.VisualStudio.Data.Tools.Package.SchemaCompare2.UI.SchemaCompareSourceTargetControl.CollectFromConnectionDialog(Boolean isSource)
   at Microsoft.VisualStudio.Data.Tools.Package.SchemaCompare2.UI.SchemaCompareSourceTargetControl.OnSelectionChangeCommitted(Object sender, EventArgs e)
   at System.Windows.Forms.ComboBox.OnSelectionChangeCommitted(EventArgs e)
   at System.Windows.Forms.ComboBox.OnSelectionChangeCommittedInternal(EventArgs e)
   at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
   at System.Windows.Forms.ComboBox.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


Solution

  • For me, it appears to be a bug in either VS or with SSDT. Issue logged here: https://developercommunity.visualstudio.com/t/SQL-Schema-Comparison-Crash/10349368

    In the mean-time, while Microsoft is working on a fix, you can check that the SQL Database project is targeting the latest .NET Framework (4.8), and also make sure .NET framework SDK and tools are installed as part of your VS workloads...

    VS Installer

    Open the project file in a text editor and change the value for the TargetFrameworkVersion property to v4.8. Save and then reload the project/solution (possibly a restart of VS may be required).