Hello, I am wondering if something was changed in IVsExpansionManager.InvokeInsertionUI() in Visual Studio 2013 or 2015. We have a set of custom snippets that are installed with our Visual Studio extention. Everything was working fine under Visual Studio 2012. Once we upgraded our project to Visual Studio 2015, InvokeInsertionUI throws the error "Object reference not set to an instance of an object". Can you spot anything wrong with the code below?
if (nCmdID == (uint)VSConstants.VSStd2KCmdID.INSERTSNIPPET)
{
// get the extension first
string ext = m_provider.GetFileExtension().ToLower();
string[] kinds = new string[5];
int kindsCounter = 0;
if (ext == ".ct")
{
kinds[kindsCounter++] = "clienttrigger";
}
if (ext == ".st")
{
kinds[kindsCounter++] = "servertrigger";
}
if (ext == ".ct" || ext == ".st")
{
kinds[kindsCounter++] = "clientservertrigger";
}
if (ext == ".ct" || ext == ".st" || ext == ".cc" || ext == ".nc" || ext == ".sc")
{
kinds[kindsCounter++] = "classtrigger";
}
kinds[kindsCounter++] = "generalfile";
// now display the snippets
IVsTextManager2 textManager = (IVsTextManager2)m_provider.ServiceProvider.GetService(typeof(SVsTextManager));
textManager.GetExpansionManager(out m_exManager);
try
{
m_exManager.InvokeInsertionUI(
m_vsTextView,
this, //the expansion client
new Guid(WCSnippetUtilities.LanguageServiceGuidStr),
null, //use all snippet types
0, //number of types (0 for all)
0, //ignored if iCountTypes == 0
kinds, //use all snippet kinds
kindsCounter, //use all snippet kinds
0, //ignored if iCountTypes == 0
"Custom Snippets", //the text to show in the prompt
string.Empty); //only the ENTER key causes insert
}
catch (Exception c)
{
System.Windows.Forms.MessageBox.Show(c.Message, "Error");
}
return VSConstants.S_OK;
}
Something seems to be wrong with the kinds array, because I get no error if I remove it.
m_exManager.InvokeInsertionUI(
m_vsTextView,
this, //the expansion client
new Guid(WCSnippetUtilities.LanguageServiceGuidStr),
null, //use all snippet types
0, //number of types (0 for all)
0, //ignored if iCountTypes == 0
null, //use all snippet kinds
0, //use all snippet kinds
0, //ignored if iCountTypes == 0"WBDK Snippets", //the text to show in the prompt
string.Empty); //only the ENTER key causes insertWith this last call, all Visual Studio snippets are showing properly, INCLUDING our custom snippets that we placed in a sub-folder named "Visual Studio".
Do you have any suggestion as to why the code above started throwing an error after we upgraded to VS 2015? Thank you