1

I'm writing a Visual Studio add-in and have a 16x16 bitmap resource that I would like to use as the button image for my menu item.

Following these instructions from the MSDN, I renamed the resource 1 and the file 1.bmp, then edited Resources.resx accordingly:

<data name="1" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>..\1.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

I then changed my call to Commands2.AddNamedCommand2, passing false and 1 as the arguments for MSOButton and Bitmap respectively:

Command command = commands.AddNamedCommand2(addIn, "MyAddIn", "MyAddIn", "Open MyAddIn", false, 1, ref contextGUIDS,
                                            (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

Now when I launch the add-in in Visual Studio, Commands2.AddNamedCommand2 throws a FileNotFoundException:

Additional information: Could not load file or assembly 'MyAddIn.resources, Version=0.1.3939.33205, Culture=en, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

What am I doing wrong?

EDIT: I'm doing this in Visual Studio 2005, in case that is significant.

EDIT2: The project is on github, if anyone wants to look at the source and/or try to reproduce the issue.

Phil Booth
  • 4,853
  • 1
  • 33
  • 35
  • What happens if you restore `true, 59`? Have you added the resource file in the add-in-project? Do you have many resource files? Do you reference other projects? – Albin Sunnanbo Nov 11 '10 at 20:58
  • If I restore `true, 59` the call succeeds and the smiley face icon is displayed. I have added the bitmap file as a resource in the add-in project. I do reference another project to display a user control on my tool window, although this problem persists when that code is commented out. – Phil Booth Nov 12 '10 at 13:20

1 Answers1

3

If you create the resource-only assembly manually, e.g.

resgen.exe "Path\To\Resource.resx" "Path\To\Bin\en\MyAddin.resources"
al.exe /c:en /embed:"Path\To\Bin\en\MyAddin.resources" /out:"Path\To\Bin\en\MyAddin.resources.dll"

and then set your assembly version to 0.0.0.0 (or alternatively set the resource assembly version in the al.exe command, or use the [assembly: System.Resources.SatelliteContractVersion()] attribute), you should get past the FileNotFoundException. Using resgen.exe might also tell you why the assembly isn't being generated and linked automatically.

You can also subscribe to the AppDomain.AssemblyResolve event, e.g. here, to trace or override the loading of resource (or other) assemblies.

Community
  • 1
  • 1
leakyboat
  • 430
  • 2
  • 3
  • Thanks for the help. I'm still getting the `FileNotFoundException` though. The project is on github, in case looking at it will help: https://github.com/philbooth/VisualSO – Phil Booth Nov 13 '10 at 16:43
  • Create a directory under Bin called 'en' and try the following post build: "$(VS80COMNTOOLS)..\..\SDK\v2.0\Bin\resgen.exe" "$(ProjectDir)Properties\Resources.resx" "$(TargetDir)VisualSO.resources" "$(WINDIR)\Microsoft.NET\Framework\v2.0.50727\al.exe" /c:en /embed:"$(TargetDir)VisualSO.resources" /out:"$(TargetDir)\en\VisualSO.resources.dll" /v:0.1.0.0 /productv:0.1.0.0 – leakyboat Nov 13 '10 at 23:14
  • Success! You are my hero. A legend. +100 :) – Phil Booth Nov 14 '10 at 02:19
  • I have an open source project that took the easy way out and specified an MSO icon ordinal. I could really use a little bit of help from a volunteer to refactor this into a proper icon if anyone would be willing to help me. Thanks! :) – Christopher Painter Nov 20 '14 at 02:57