Doesn't load personal snippets directory

Aug 23, 2009 at 2:53 AM

Is there a reason that the snippet editor does not load the user's personal snippets directory?  It would seem that this would be an important snippet directory to load each time the snippet editor runs since that is where the user typically stores personal snippets.  All that gets loaded are the built-in snippets.  I am using Visudal Basic Express 2008 if that matters.

Thanks for any info.

Coordinator
Aug 24, 2009 at 1:39 AM
Hi DrMajSir,

In Visual Studio click on the Tools menu and open the "Code Snippets
Manager" and check to see if the user's personal snippet directory is
there. If you add it, the change won't propagate until after Visual Studio
is closed.
Coordinator
Aug 29, 2009 at 11:54 PM
Hi Akhmetov,

The problem with the code you added is it forces all paths in the users
documents folder to have "Visual Studio 2008" added to it. This is wrong on
a number of counts. First we support multiple versions of Visual Studio.
Second, but most importantly, users can add other paths, anywhere on their
file system including anywhere in the My Documents folder, so you cannot
force the "Visual Studio 2008" into all paths.
The problem is not with the code, it is with the registry settings. Open up
the "Code Snippets Manager" from inside Visual Studio, add the proper path,
close Visual Studio and restart.
Aug 31, 2009 at 6:48 AM

Hi Bill and Akhmetov,

I'm not sure that I understand all that Akhmetov is saying in his posts.  To answer Bill's question:

Yes, my personal snippets directory is in the MS Visual Basic 2008 Express Edition Code Snippets Manager.  In fact, it has been there ever since VB 2008 Express was installed on my computer.  (i.e. it was installed as a default during the installation process)  If it helps, here is the path: 

C:\Users\DrMajSir\Documents\Visual Studio 2008\Code Snippets\Visual Basic\My Code Snippets

I first discovered this problem when I added another path to the Code Snippets Manager.  (One I had created for some snippets I downloaded for a book I'm reading on VB 2008)  I was able to successfully added the new directory into VB 2008 Express.  However, every time I loaded up the code snippets editor, the directory I manually added to VB 2008 using the snippets manager, mysteriously disapeared when I would reopen VB 2008.  After going back and forth bewteen the code snippet editor and VB 2008 several times, I was able to deduce that the code snippet editor was the one removing the manually added directory.  It was during this "testing" that I noticed that the code snippet editor did not load the "My Code Snippets" directory.  So I decided to move the other snippet directory I had downloaded to be a sub-directory under "My Code Snippet".  VB 2008 Express was happy and the code snippet editor stopped removing the reference.  (I suspect partly becuase it doesn't even find the "My Code Snippets" directory.)  However, this "fix" for the dissappearing directory (from VB 2008) is not really a solution because it now means that only the built-in code snippets are available within the code snippet editor.

Bill:  What is your suggested solution?  Assuming you have one.

Thanks,
DrMajSir

Coordinator
Aug 31, 2009 at 8:05 AM
Hi DrMajSir,

It sounds like the registry maybe being re-initialized. This may-be due to
the express versions showing other languages as being installed even though
they aren't.

Try setting a break point on line 435 of the Products.vb file and launch
from the IDE in debug mode.

If regKey Is Nothing OrElse regKey.ValueCount = 0 Then
--> If Me.IsInstalled Then Me.Product.InitializeUserRegistry()
End If

If the Me.Product.InitializeUserRegistry is being called, then that's the
likely culprit. I'd hazard a guess it's getting bad product/language
information. Make a note of the product and the language: language would be
the Me reference at the breakpoint, and the product can be obtained via the
Me.Product.
Once you've determined that, investigate the registry and see if you can
find the rogue language entry and report back your findings.

Also, can you tell me what products are listed in the drop down combo on the
left hand side of the Snippet Editor ?, eg: "Visual Studio 2008", "Visual
Basic 2008 Express Edition" etc ..

At this point of time without actually knowing what is causing the problem,
my guess is it will be around the call to InitializeUserRegistry. The
problem with that method being is it resets the entire product rather than
per language per product. So simple fix would be to refactor the method to
take a language and only initialize one language per call.
Sep 1, 2009 at 3:06 AM

Bill,

I did as you requested and the program stopped at the line you indicated.  I took a snapshot of the screen showing the me reference expanded in the locals window.  However, I can't figure out a way to attach it to a posting (maybe that's by design!)  However, I did upload it to a private Picasa Web Album which should be reachable by clicking below.

Visual Basic

I hope this helps!

Coordinator
Sep 1, 2009 at 12:55 PM
Hi DrMajSir,

It does help some. The problem appears to be in finding the localised name
for CSharp. It should be something like "Visual C#".
Why VB Express is reporting Visual C# as being installed is a question I
can't answer ;) If you can, put a break point on the GetLocalisedName
method and see what is going on there.

The refactoring I mentioned earlier to initialize the registry per language
instead of per product will fix the problem you are having but it doesn't
get to the underlying issue of why C# is reported as being installed, yet
the localized name fails. I'd be concerned if the LCID is being reported
wrong. If it fails to find the C# resource assembly in GetLocalisedName,
does it find the VB one ?

Thanks
Sep 2, 2009 at 8:05 AM

Bill,

I did as you requested and placed a break point on GetLocalisedName.  The program calls the function three times and stepping through it produces the following set of changes to variables:

1st visit to GetLocalisedName:
Me = 
		IsInstalled	True	Boolean
		LocalisedName	"Visual Basic"	String
		Name	"Basic"	String
+		Product	{SnippetEditor.Utility.Product}	SnippetEditor.Utility.Product
			HKLMRegistryPath	"SOFTWARE\Wow6432Node\Microsoft\VBExpress\9.0"	String
			IsInstalled	True	Boolean
	+		Languages	Count = 3	SnippetEditor.Utility.Language.LanguageCollection
			LCID	1033	Integer
			Name	"Visual Basic 2008 Express Edition"	String
			RegistryPath	"SOFTWARE\Microsoft\VBExpress\9.0"	String
		SnippetsPath	"%InstallRoot%\VB\Snippets\%LCID%\WPF\;%InstallRoot%\Common7\IDE\VBExpress\Snippets\%LCID%\application\;%InstallRoot%\Common7\IDE\VBExpress\Snippets\%LCID%\common code patterns\;%InstallRoot%\Common7\IDE\VBExpress\Snippets\%LCID%\data\;%InstallRoot%\Common7\IDE\VBExpress\Snippets\%LCID%\fundamentals\;%InstallRoot%\Common7\IDE\VBExpress\Snippets\%LCID%\other\;%InstallRoot%\Common7\IDE\VBExpress\Snippets\%LCID%\windowsforms\;%MyDocs%\Code Snippets\Visual Basic\My Code Snippets\;"	String

NOTE:  The last directory in the SnippetsPath above should be:
	%MyDocs%\Visual Studio 2008\Code Snippets\Visual Basic\My Code Snippets
	(i.e. it appears to be missing the "Visual Studio 2008" portion)

rootKey =
 		Name	"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VBExpress\9.0\Languages\CodeExpansions\Basic"	String
		SubKeyCount	2	Integer
		ValueCount	7	Integer

resIDString =	"1533"	String
package =	"{019971D6-4685-11D2-B48A-0000F87572EB}"	String

packageKey =	{Microsoft.Win32.RegistryKey}	Microsoft.Win32.RegistryKey
			Name	"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VBExpress\9.0\Packages\{019971D6-4685-11D2-B48A-0000F87572EB}\SatelliteDll"	String
			SubKeyCount	0	Integer
			ValueCount	2	Integer

path =		"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\"	String
path =		"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\1033"	String
path =		"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\1033\msvb7ui.dll"	String

resIDString =	"Visual Basic"	String

End of 1st visit to GetLocalisedName



2nd visit to GetLocalisedName:
Me = 
		IsInstalled	True	Boolean
		LocalisedName	"CSharp"	String
		Name	"CSharp"	String
+		Product	{SnippetEditor.Utility.Product}	SnippetEditor.Utility.Product
			HKLMRegistryPath	"SOFTWARE\Wow6432Node\Microsoft\VBExpress\9.0"	String
			IsInstalled	True	Boolean
	+		Languages	Count = 3	SnippetEditor.Utility.Language.LanguageCollection
			LCID	1033	Integer
			Name	"Visual Basic 2008 Express Edition"	String
			RegistryPath	"SOFTWARE\Microsoft\VBExpress\9.0"	String
		SnippetsPath	""	String

rootKey =
		Name	"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VBExpress\9.0\Languages\CodeExpansions\CSharp"	String
		SubKeyCount	1	Integer
		ValueCount	0	Integer

resIDString =	""	String

Note:  The IsNumeric test on line 409 fails and the function returns:  ""

End of 2nd visit to GetLocalisedName



3rd visit to GetLocalisedName:
Me =
		IsInstalled	True	Boolean
		LocalisedName	"XML"	String
		Name	"XML"	String
+		Product	{SnippetEditor.Utility.Product}	SnippetEditor.Utility.Product
			HKLMRegistryPath	"SOFTWARE\Wow6432Node\Microsoft\VBExpress\9.0"	String
			IsInstalled	True	Boolean
	+		Languages	Count = 3	SnippetEditor.Utility.Language.LanguageCollection
			LCID	1033	Integer
			Name	"Visual Basic 2008 Express Edition"	String
			RegistryPath	"SOFTWARE\Microsoft\VBExpress\9.0"	String
		SnippetsPath	"%InstallRoot%\xml\%LCID%\Snippets\;%MyDocs%\Code Snippets\XML\My Xml Snippets\;"	String

NOTE:  The last directory in the SnippetsPath above should be:
	%MyDocs%Visual Studio 2008\Code Snippets\XML\My Xml Snippets
	(i.e. it appears to be missing the "Visual Studio 2008" portion)

rootKey =
		Name	"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VBExpress\9.0\Languages\CodeExpansions\XML"	String
		SubKeyCount	2	Integer
		ValueCount	6	Integer

resIDString =	"#200"	String
resIDString =	"200"	String

id =		200	UInteger

package =	"{87569308-4813-40a0-9cd0-d7a30838ca3f}"	String

packageKey =
		Name	"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VBExpress\9.0\Packages\{87569308-4813-40a0-9cd0-d7a30838ca3f}\SatelliteDll"	String
		SubKeyCount	0	Integer
		ValueCount	2	Integer

path =		"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\Xml\"	String
path =		"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\Xml\1033"	String
path =		"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\Xml\1033\Microsoft.XmlEditorUI.dll"	String

resIDString =	"XML"	String

End of 3rd visit to GetLocalisedName


Again, I hope this helps. While I was collecting this information, I noticed that all though Visual C# is NOT installed on my machine,
there are Visual C# sub-directories the Code Snippets and Templates directories within my Visual Studio 2008 directory in my "Documents"
folder.

DrMajSir

Coordinator
Sep 2, 2009 at 12:16 PM
Hi DrMajSir,

Thanks !! So the problem is the registry is showing CSharp in the HKLM
CodeExpansions, but it doesn't have the necessary information such as
DisplayName or Package etc. So really the Snippet Editor should be ignoring
that CSharp entry. I think the following replacement of the IsInstalled
method, line 331 of products.vb will fix that part of the problem..

Public ReadOnly Property IsInstalled() As Boolean
Get
Using languageKey As RegistryKey =
Registry.LocalMachine.OpenSubKey(Me.Product.HKLMRegistryPath & "\" &
Me.Product.CodeExpansionsPath & "\" & Me.Name, False)
Return CStr(languageKey.GetValue("DisplayName", "")) <>
Nothing
End Using
End Get
End Property



The second part of the problem is the "Visual Studio 2008" missing from the
snippet path. That's due to what Visual Studio interprets %My Docs% as
meaning. It seems in some cases it interprets it as the My Documents
folder, and in others My Documents\Visual Studio 2008. I'll have to look
into that one further. In the meanwhile add the folder from inside the
snippet editor and it should be okay.
Coordinator
Sep 2, 2009 at 1:23 PM

Regarding the missing "Visual Studio 2008" in some paths, that's a problem with the %MyDocs% replacement variable. To Fix, change the ReplaceVars function to the following:

Line 373 of Products.vb:

Private Function ReplaceVars(ByVal strIn As String) As String

Dim strOut As String

If strIn = Nothing Then Return ""

strOut = strIn.Replace("%MyDocs%", GetMyDocs)

strOut = strOut.Replace("%InstallRoot%\", GetInstallRoot)

strOut = strOut.Replace("%LCID%", Me.Product.LCID.ToString)

Return strOut

End Function

And then add the following function:

Private Function GetMyDocs() As String

If Me.Product Is Nothing Then Return My.Computer.FileSystem.SpecialDirectories.MyDocuments

Dim docsPath As String

Using hkey As RegistryKey = Registry. CurrentUser.OpenSubKey(Me.Product.RegistryPath)

docsPath = hkey.GetValue("VisualStudioLocation", "").ToString

End Using

If docsPath = Nothing Then docsPath = My.Computer.FileSystem.SpecialDirectories.MyDocuments

Return docsPath

End Function

NOTE: I haven’t tested this yet, but it looks like it should fix it.

Coordinator
Sep 2, 2009 at 2:55 PM

I have updated the products.vb file.

http://snippeteditor.codeplex.com/SourceControl/changeset/view/36425#391917

 

Sep 3, 2009 at 1:24 AM

Bill,

Awesome!  I tested the new products.vb and I can confirm that it works.  I can now add directories
either in the Snippets editor or VB and they are reflected in both programs during the next restart.

The fix also made the My Snippets directory appear and removed the C Sharp directory.

Thanks!

DrMajSir

 

Coordinator
Sep 3, 2009 at 3:07 AM
Hi DrMajSir,

Thanks :)

Glad you raised the bug and very appreciative of your help in tracking down
the cause. Thanks :)