Unhandled COMException in internal static method GetActiveConfigurationName(EnvDTE.Project automationObject) of Utilities


When I provide my own project type with the following template, exception is thrown as I close projects of my own type.
Exception is thrown in Line 404 of Utilities.cs.
My project template is like this:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Configuration Condition=" '$(Configuration)'=='' ">Debug</Configuration>
<ConfigurationName Condition=" '$(ConfigurationName)' == '' ">$(Configuration)</ConfigurationName>
<OutputPath Condition=" '$(OutputPath)'=='' ">output\Debug</OutputPath>
<Target Name="Build">
<Message Text="It is an empty target." />
The code where unhandled COMException is thrown.
internal static string GetActiveConfigurationName(EnvDTE.Project automationObject)
if(automationObject == null)
    throw new ArgumentNullException("automationObject");
string currentConfigName = string.Empty;
if(automationObject.ConfigurationManager != null)
EnvDTE.Configuration activeConfig = automationObject.ConfigurationManager.ActiveConfiguration;
    if(activeConfig != null)
       currentConfigName = activeConfig.ConfigurationName;
return currentConfigName;