升级到Visual Studio 2015后,为什么我的自定义片段会引发新错误? [英] Why are my custom snippets throwing a new error after upgrading to Visual Studio 2015?

查看:73
本文介绍了升级到Visual Studio 2015后,为什么我的自定义片段会引发新错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想知道是否在Visual Studio 2013或2015的IVsExpansionManager.InvokeInsertionUI()中进行了更改.我们有一组自定义片段,这些片段与Visual Studio扩展一起安装.在Visual Studio下一切正常 2012.将项目升级到Visual Studio 2015后,InvokeInsertionUI会引发错误对象引用未设置为对象实例".您能发现下面的代码有什么问题吗?

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;
}

kinds数组似乎有问题,因为删除它不会出错.

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 insert  

在最后一次调用中,所有Visual Studio片段都正确显示,包括我们放在自定义文件夹"Visual Studio"中的自定义片段.

With this last call, all Visual Studio snippets are showing properly, INCLUDING our custom snippets that we placed in a sub-folder named "Visual Studio".

关于我们在升级到VS 2015之后,为什么上面的代码为什么会引发错误,您有什么建议吗?谢谢

Do you have any suggestion as to why the code above started throwing an error after we upgraded to VS 2015?  Thank you

推荐答案

Lesergeur,

Hi lesergeur,

根据IVsExpansionManager.InvokeInsertionUI的文档(链接如下),vs2012和vs2015之间是相同的.我建议您可以减少种类的数量并检查它是否有效.我似乎是某种原因引起的.

From the document of IVsExpansionManager.InvokeInsertionUI (link as below), there are the same between vs2012 and vs2015. I would suggest that you could reduce the number of kinds and check if it works. I seems that some kinds cause the issue.

https://msdn.microsoft.com/zh-CN/library/microsoft.visualstudio.textmanager.interop.ivsexpansionmanager.invokeinsertionui(v=vs.110).aspx

如果问题仍然存在,能否请您通过OneDrive提供一个简单的演示,我们将在您的身边重现您的问题,并尝试找到解决问题的解决方案.

If the issue still exist, Could you please provide a simple demo via OneDrive, we'll reproduce your issue on our side and try to find a solution to resolve it.

最诚挚的问候,

吴可乐


这篇关于升级到Visual Studio 2015后,为什么我的自定义片段会引发新错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆