“Object reference not set to an instance of an object” message is shown on SQL Server Management Studio startup

Applies to

SQL Server Management Studio add-ins

Problem description

In some cases, with various ApexSQL add-ins integrated into the same host, after an upgrade of one or more add-ins, the user might be unable to launch the host application successfully.

During the splash screen, a warning message is displayed with the following or similar text:

  • The ‘Stub’ package did not load correctly.
  • The problem may have been caused by a configuration change or by the installation of another extension. You can get more information by examing the file ‘C:\Users\BPetrovi\AppData\Roaming\Microsoft\AppEnv\15.0\ActivityLog.xml’
  • Restarting Visual Studio could help resolve this issue.
  • Continue to show this error message?

The ‘Stub’ package did not load correctly message on SQL Server Management Studio startup

The above message is shown for a split second followed by multiple “Object reference not set to an instance of an object” dialog boxes as shown below in a way that has or seems to have no end:

Object reference not set to an instance of an object dialog boxes on SQL Server Management Studio startup

The only way to get SSMS to startup is to quickly close all of those “Object reference not set to an instance of an object” dialog boxes by clicking the OK button (best to hold Enter from the keyboard). Besides, the warning about the Stub package not being loaded correctly should also be closed by clicking either the Yes or No button.

When all of the piled-up messages are closed, the host application is started. However, this workaround is only temporary as with each SSMS launch the issue is continuing firmly.


This problem usually occurs because of the order in which the ApexSQL add-ins are installed and integrated into SQL Server Management Studio. Namely, some ApexSQL add-ins are less frequently released and include references to some files and versions that don’t exist in the configuration files or are named incorrectly.

For example, if we have ApexSQL Refactor 2021 pre-installed into SSMS 18, and then an installation of ApexSQL Unit Test is run and integrated into the same host – this behavior is most likely to occur as, during the ApexSQL Unit Test installation, configuration files are overwritten forcing the incorrect name convention.

First of all, we need to check if the root cause is what’s described above or something else. A good starting point is to check the ActivityLog.xml file listed in the first warning message

Workaround 1

Close the host application if it’s “running” using the method described in the problem description section and follow these steps:

  1. Go to the path from the warning message and open the ActivityLog.xml file in any text editor (preferably Notepad++)

    Highlighted location to the ActivityLog.xml file

    • Note: AppData folder is a hidden folder, make sure to enable showing hidden files and folders in the File Explorer

    Option “Show hidden files, folders, and drives” under Hidden files and folders

  2. Go to Search | Find… of press Ctrl + F from the keyboard and type “apexsql” in the Find what box and click Find All in Current Document option

    Searching for an error in the ActivityLog.xml file

  3. See if an error is logged with the following description (there should be 4 identical entries):

    <description>CreateInstance failed for package [Stub]Source: &apos;mscorlib&apos; Description: Could not load type &apos;ApexSql.Common.Extensibility.Stub&apos; from assembly &apos;ApexSql.Common.Extensibility.Stub.18, Version=7.0.978.0, Culture=neutral, PublicKeyToken=3b936d7fbc8f6b28&apos;.&#x000D;&#x000A;System.TypeLoadException: Could not load type &apos;ApexSql.Common.Extensibility.Stub&apos; from assembly &apos;ApexSql.Common.Extensibility.Stub.18, Version=7.0.978.0, Culture=neutral, PublicKeyToken=3b936d7fbc8f6b28&apos;.&#x000D;&#x000A; at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)&#x000D;&#x000A; at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)&#x000D;&#x000A; at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)&#x000D;&#x000A; at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)</description>

    Could not load type &apos;ApexSql.Common.Extensibility.Stub&apos; from assembly &apos;ApexSql.Common.Extensibility.Stub.18

    If the above or similar error is logged, then we need to examine the content of the configuration .pkgdef file.

  4. Go to the following path: C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Extensions\ApexSQLStub and open ApexSql.Common.Extensibility.Stub.18.pkgdef in any text editor

    • Note: The path might be different depending on the SSMS version. The easiest way to get to the targeted path is to right-click the SQL Server Management Studio icon, choose the Properties option, and then Open File Location:

      SQL Server Management Studio 18 Properties window

      This will get you to the IDE folder in File Explorer where you’re just two steps from the configuration file. Simply navigate to Extension | ApexSQLStub for all of SSMS versions:

      Path to ApexSql.Common.Extensibility.Stub.18.pkgdef in File Explorer

  5. Change the highlighted text from “ApexSql” to “ApexSQL” and save changes

    ApexSql.Common.Extensibility.Stub.18.pkgdef file in Notepat++

    • Note: If saving changes fails, run the text editor as an administrator, and try again:

      Failed saving changes to ApexSql.Common.Extensibility.Stub.18.pkgdef file

      When saved, launch SQL Server Management Studio and the problem should be resolved

Workaround 2

Another possible solution is to examine Programs and Features from Control Panel and look for the last installed ApexSQL add-in that caused the issue. In this case, ApexSQL Unit Test was the last installed add-in.

Re-run the installation of an add-in that was installed on an older date to fix the issue. For example, ApexSQL Refactor was installed a day before when everything was fine, meaning it will overwrite the configuration file and make things alright again:

Programs and Features with highlighted ApexSQL Refactor


Waiting for fix in future releases of ApexSQL add-ins.