Visual Studio Development Bookmark and Share   
 index > Visual Studio Extensibility > Add-In: Getting FileLoadException when using own button images
 

Add-In: Getting FileLoadException when using own button images

I write an add-in for and with Visual Studio 2008 standard using Vista SP1.

When I use own button images with "Commands2.AddNamedCommand2" and step over this function call, the following debug output message appears:
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll

The button image is correctly displayed in the menu afterwards though.

I can reproduce this in a new project too. Here is how I'm able to reproduce the problem:

  • Create a new Visual Studio Add-in using the corresponding template
  • Name the project "MyAddin1"
  • Open project properties and set Assemblyname to "MyAddin1"
  • Open the "MyAddin1 - For Testing.AddIn" link and modify the assembly path to point to "MyAddin1.dll"
  • Set AssemblyCulture to "en-US" in AssemblyInfo.cs
  • Create the directory "MyAddin1\bin\en-US"


How I add the image resource:
  • Add new item, General -> Resource Files
  • Name the file "Resources1.resx"
  • Doubleclick Resources1.resx to open it
  • Set its Build Action to "none"
  • Add resource -> Add existing file
  • Select a 24bit 16x16 bitmap image called 1000.bmp
  • Select "Exclude from project"
  • Open Resources1.resx in notepad and change the data name "_1000" to "1000"


How I generate the satellite dll:
  • resgen Resources1.resx
  • al.exe /embed:Resources1.resources /culture:en-US /out:MyAddin1.resources.dll
  • copy /y MyAddin1.resources.dll bin\en-US\MyAddin1.resources.dll


Now is the file "MyAddin1.resources.dll" located in "MyAddin1\bin\en-US". I switch back to Visual Studio and change the auto-generated source code to use the image resource 1000:

Command command = commands.AddNamedCommand2(_addInInstance, "MyAddin1", "MyAddin1", "Executes the command for MyAddin1", false, 1000, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);


I set a breakpoint at this line and hit F5 to start and debug MyAddin1. When I step over this line, it prints the following to the debug output pane:
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll

However, when I continue program execution and open the Tools menu, MyAddin1 button appears with my button image resource 1000.

I did try many different approaches how satellite dll's should be created. The above is how MS recommends that. I also tried articles from mz-tools, but no matter what article I follow, I always get this exception.


Any idea what could cause this exception?
Peter Schraut  Sunday, October 18, 2009 11:35 AM
Hello,

Can you get more details of the FielLoadException by going to the Debug, Exceptions window, select the FileLoadException (under Common Language Runtime Exceptions, System.IO node) and check the Thrown checkbox? That way, when the exception is thrown the debugger halts and gives you the chance of examining the exception to get more info. Ideally you should get the full file name of the offending file.

The FileLoadException exception is strange because if the problem is that VS fails to locate the satellite Dll in some folder the exception would be FileNotFoundException. FileLoadException means that the dll is found but there is an error loading it, such as it is not a .NET assembly (but a native DLL), or the CLR of the DLL is higher than what VS can manage (such as VS.NET 2003 loading a .NET 2.0 assembly or VS 2008 loading a .NET 4.0 assembly).

You can also create a dummy project that calls Assembly.LoadFromFile passing your satellite dll and examine if there is a FileLoadException loading it.

You can also use Process Monitor (procmon) from SysInternals (now Technet) to trace disk activity of devenv.exe. See:

HOWTO: Using the Process Monitor (ProcMon) tool to diagnose Visual Studio add-ins problems
http://www.mztools.com/articles/2008/MZ2008024.aspx

Somehow VS is locating a DLL that can't load.



MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about VS extensibility: http://msmvps.com/blogs/carlosq/
Carlos Quintero - MVP  1 hour 2 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Re: Variable don't show in Autos Window in Dynamically Generated Code
• What should I mock to test a developed DSL package?
• How to add a sub-item to a code file in solution hierarchy
• How to programmatically open a file and set it as ActiveDocument? (C# - VS 2005)
• Logging in DSL Tool Contex
• Solution folders in Solution.Projects
• Insert Images in code (visual studio code editor)
• Where can i get more documents of DLS Tools for developer?
• How to make VS.NET 2003 always run the Build Events no matter whether the project is changed or not?
• Problem while Renaming an item