This project is read-only.
Wednesday, January 23, 2013

Missing Menus Again!

I thought I had this problem solved earlier, but it stood up to confront me again yesterday, this time though for a different reason. I noticed this problem several days ago once I was far enough along in the project to have something to test running in the Visual Studio experimental instance. Basically the package seemed to install itself as an extension, but the menu items did not appear within either of the context menus it was intended to use.

Errors I made within the project's VSCT file turned out to be the cause. Since this is the first extension I've worked on, it is the first time I've had to write such a file. As everyone who has done this knows it can be pretty difficult to write a valid VSCT file, if you don't know what your are doing. In my case it seemed to make sense after a while, but those first occasions of satisfaction were illusions.

To resolve those problems I started working on a simple extension project building it up a piece at a time until I was able to see the pattern needed. Then I created a mock up version of the menu I needed for XHM within that just so I could see the menus in place, without wiring up the commands. Once that was done I moved the code back into the XHM source, and completed the wiring so that the commands would execute.

Then I started testing XHM again.

Once I could see that the menus were visible, and that the commands were firing, I updated the source here at CodePlex, and continued my tests to look for other bugs. About halfway through the day I lost the menus. This was a real surprise to me, because at that point I could not think of any significant changes that I made to the source since uploading it to CodePlex. To be certain of that I refreshed my copy from the repository, rebuilt and tested again. Still no luck.

A Goggle search found several articles and forums that discussed problems of a similar nature, but I could find no solution there. It did give some ideas though for what to look for, and tools to use. On one forum I found that VSCT Power Toys could read a library to see if it included the menus among its resources. Yes, I could see that the menus I wrote were compiled and included in the DLL. It also told me that I could see what libraries were in use by a debugged project using the "Modules" option under DEBUG/Windows. I could not find my DLLs. But the menus are loaded before a DLL is loaded (at least in this case), so that did not necessarily indicate a problem. Finally VSCT Power Toys could tell me if my menus were being imported into Visual Studio by the menu manager. My menus were not.

This gave me the clue I needed to find the root cause. I knew my menus were being compiled and included in my libraries, and that my library was being recognized by Visual Studio as being installed. The reason the library was not in the "Modules" window is that it had not yet been opened by Visual Studio. Something was missing that tells Visual Studio that there are menus to load.

A comparison of various files in the compiled output with a working extension revealed the missing component. The pkgdef file created during the compile was missing a command to create a registry key that controls the loading of the menus. Okay, that gets me closer to a solution, but it is not the root cause. What was needed to make the compile process write that command? I checked the project file, comparing it line by line with a project file from a working project. Nothing showed up. I checked the manifest file to see if anything was there. Still nothing. Finally after several hours of what seemed like an impossible search, I learned that the pkgdef file is created as the result of attributes set on the package definition class.

A look at XamlHelpmeetPackage.cs revealed a missing attribute:

[ProvideMenuResource("Menus.ctmenu", 1)]

The absence of that one line was the root cause of the missing menus.

But if that is the case, how was I able to see the menus earlier in the day? I did not remove the line in the middle of the day. It had never been in the file. My guess is that the menus were left over from the test I did in the test project earlier, and since I simply reused the GUID and IDs from that project with XHM, the menus continued to appear, and work, until I refreshed the experimental instance of Visual Studio. Refreshing removes all of the changes made by previous installs, and leaves a fresh instance of Visual Studio for the next test.

One thing to learn from this is the importance of not reusing GUIDs in your projects. The GUIDs are meant to prevent this kind of confusion. It is a good lesson learned, even if not a profitable way to learn it.

Last edited Jan 23, 2013 at 3:13 PM by gloder, version 1

Comments

No comments yet.