Code snippet failed to load

Category: c# ide

Question

Scoutn on Tue, 28 Apr 2009 20:21:44


I am getting the following error from VS 2008. 'Code Snippet titled [Method Stub - Body] failed to load.  Verify that refactoring snippets are recognized in the Code Snippet Manager and that the snippet files are valid on disk.' This happens when I try to override a method using intellisense or when I try to implement an interface.

I have tried repairing Visual Studio, as well as trying to import the snippets from another installation that works. I have removed and added the folders as well. (C:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Refactoring).

I'm at a loss here. Does anyone have any suggestions? I've searched for a solution but there isn't much out there.

Replies

Lenny S on Tue, 28 Apr 2009 20:30:24


Do you get and warning signs on your folders in code snippet manager?

LS

Scoutn on Tue, 28 Apr 2009 20:51:24


Yes, I had a couple on some of the Excel folders under Office Development. I removed the Office Development folder, but it didn't resolve the problem.

Lenny S on Tue, 28 Apr 2009 20:55:48


did you restart vs after removing them?

Scoutn on Tue, 28 Apr 2009 21:02:41


I just tried removing all the folders from the snippet manager, shutting down VS, renamed C:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets\1033\SnippetsIndex.xml to .old, renamed C:\Users\[user]\AppData\Local\Microsoft\VisualStudio\9.0\1033\ExpansionsXML.xml to .old, restarted VS, and I am still getting the error. Frustrating! I wish I could remember what I did to cause this to happen!

Harry Zhu on Tue, 05 May 2009 09:46:28


Hi,

Please take the following steps:

1 open code snippet manager(ctrl+k,ctrl+b).
2 select the language (such as c#).
3 add the three folders(  Refactoring、Visual C#、OfficeDevelopment) which locate at :
C:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets\1033.

Harry

Scoutn on Tue, 12 May 2009 19:03:22


Hi Harry -  I've tried that but the problem is still there. Any other suggestions?

CoolDadTx on Tue, 12 May 2009 19:30:47


1) Go to <VSDir>\VC#\Snippets\1033\Refactoring. 
2) Open MethodStub.snippet.
3) Verify the snippet can be opened in an XML viewer such as VS or IE (probably have to rename it to XML first).
4) If that doesn't work then post the file contents so we can look at it.

Also please confirm what edition and SP of VS2008 you are running and if you have any third party addins installed that might impact the snippets such as CodeRush or ReSharper.

Michael Taylor - 5/12/09
http://p3net.mvps.org

Scoutn on Wed, 13 May 2009 16:04:03


Michael,

I am using version 9.0.30729.1 of VS.

I renamed the file to MethodStud.snippet.xml and it opened fine in IE. I did have ReSharper installed but have since uninstalled it and then repaired the VS installation. Below is the contents of the MethodStub snippet.

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Method Stub - Body</Title>
            <Description>Snippet for generating method stub with a body</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Refactoring</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal Editable="true">
                    <ID>signature</ID>
                    <Default>signature</Default>
                </Literal>
                <Literal>
                    <ID>Exception</ID>
                    <Function>SimpleTypeName(global::System.NotImplementedException)</Function>
                </Literal>
            </Declarations>
            <Code Language="csharp">
                <![CDATA[$signature$
{
 	$end$throw new $Exception$();
}]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

CoolDadTx on Wed, 13 May 2009 17:31:48


If you click on a method call somewhere in your code and then press Ctrl+K,M what happens?  Does the problem occur on a new project as well?

Michael Taylor - 5/13/09
http://p3net.mvps.org

Scoutn on Wed, 13 May 2009 17:54:22


The same error occurs with Ctrl+K,M. It happens with new projects as well. It seems to only be the MethodStub snippets as the others in the Refactoring directory work.

CoolDadTx on Wed, 13 May 2009 18:12:31


At this point I'd say the snippet is valid and something else is causing the failure.  Whether it was ReSharper or something else I can't say.  You don't happen to have an extra set of snippets in the snippet manager that might collide with the existing one do you?

The only thing that I can think of at this point is to try deleting your user data for VS (AppData, etc.) and then see if that resolves the problem.  It's a long shot at this point.  You might also consider looking in the Windows Event Log.  VS will generate warnings in the log for errors in templates.  I'm not sure if it does for snippets as well.

Michael Taylor - 5/13/09
http://p3net.mvps.org


Scoutn on Wed, 13 May 2009 19:38:58


I appreciate your time. Unfortunately clearing the user data didn't help either. Oh well, life goes on. :)

chenoon on Tue, 26 May 2009 14:08:32


I had the same message. It may not be the same issue because it was easy to repair, but in case :

In the Code Snippet Manager (ctrl+k,ctrl+b), my "Refactoring" and "Visual C#" folders were empty (no items).

1/ I removed both of them
2/ I clicked "Add...",
3/ I Selected the folder "C:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Refactoring"
5/ I Did the same with the Visual C# folder.

Then I could see the items inside the folder, like in this screenshot :
http://www.codeguru.com/dbfiles/get_image.php?id=10793&lbl=SNIP07_JPG&ds=20051020

saqib Mushtaq on Tue, 15 Dec 2009 12:15:45


Thanks Alot Harry ,,, it Works

Andrew_VMC on Tue, 20 Jul 2010 06:49:19


I just had the same issue with VS2008; I tried repairing VS, uninstalling/reinstalling, and removing/adding folders in code snippet manager; nothing worked.

Finally what resolved it for me was renaming ExpansionsXML.xml located in C:\Users\<your username>\AppData\Local\Microsoft\VisualStudio\9.0\1033\, and restarting VS.  This regenerated the file, and resolved the issue.   I still have no idea what caused this - it started suddenly while I was coding, out of the blue.  Pretty frustrating.  I was actually on the verge of re-installing Windows when I finally fixed it.

 

wtheronjones on Mon, 13 Sep 2010 02:27:05


Renaming the ExpansionsXML.xml and restarting VS worked for me! 

Thanks for posting your solution!

jrummell on Thu, 17 Mar 2011 17:36:09


Finally what resolved it for me was renaming ExpansionsXML.xml located in C:\Users\<your username>\AppData\Local\Microsoft\VisualStudio\9.0\1033\, and restarting VS.  This regenerated the file, and resolved the issue.   I still have no idea what caused this - it started suddenly while I was coding, out of the blue.  Pretty frustrating.  I was actually on the verge of re-installing Windows when I finally fixed it.

 

This worked for me as well.

Ebbnflow on Wed, 06 Jul 2011 19:41:02


Someone else logged into my computer and tested this. The code snippets worked under his login. This proved that the issue was a profile setting. I fixed this by doing two things:

  • I renamed the 9.0 folder to 9.0_test (because I didn't want to delete it just yet) found in Application Data and in Local Settings.
    • D:\documents and settings\'your user name'\Application Data\Microsoft\VisualStudio\9.0
    • D:\documents and settings\'your user name'\Local Settings\Application Data\Microsoft\VisualStudio\9.0

I then opened VS2008 and tested snippets. Everything worked fine.

Keenan Newton on Wed, 25 Jan 2012 03:40:01


This resolved my issue for VS 2010... I looked at the ExpansionsXML.xml file and numerous closing tags were missing.

abatishchev on Mon, 07 May 2012 07:47:54


Indeed, removing %LocalAppData%\Microsoft\VisualStudio\10.0\Extensions.xml fixes all the issues with non-working snippets. Thanks!

MikeEz3 on Fri, 16 Nov 2012 14:49:26


Removing the Extensions.xml file and restarting worked for me as well.

Using VS 2010