Question : VB.Net 2010: ResourceManager.GetObject fails with silent exception on x64

I am preparing my VB.NET based Excel COM Addin for Excel 2010 64-bit using Visual Studio 2010.

I am building it using Release|Any CPU. Excel 2010 x64 loads it as expected but I can't get a custom ribbon image to display.

The image is stored as a 32-bit PNG file (width 32px, height = 32px) in the resources section of my project.

The following function works as expected when running on Excel 2007 in x86 mode but not when running on Excel 2010 x64.

Public Function RibbonGetImage(ByVal Ctrl As Office.IRibbonControl) As Object
    RibbonGetImage = EZXL32_ribbon ' some sort of silent exception is thrown here
    ' no error messages, addin continues to work
    MsgBox "After accessing EZXL32_ribbon" ' execution does NOT reach this point in x64
End Function

EZXL32_ribbon is a function that VS created in the project's Resources.Designer.vb file and is used to retrieve the image as a System.Drawing.Bitmap

Public ReadOnly Property EZXL32_ribbon() As System.Drawing.Bitmap
        Dim obj As Object = ResourceManager.GetObject("EZXL32_ribbon", resourceCulture)
        Return CType(obj,System.Drawing.Bitmap)
    End Get
End Property

Does anyone have an idea why calling EZXL32_ribbon() causes some sort of silent exception when running on x64?

Answer : VB.Net 2010: ResourceManager.GetObject fails with silent exception on x64

Thanks. I wasn't really sure what you were talking about so I decided to try and isolate the problem by placing the code, in its most simplified form, in a test function that I could call after the addin's (and Excel's) startup had completed. If it failed there, my next step was to create a stand-alone example project containing only this code fragment to demonstrate the problem and then post back here.

The problem revealed itself as soon as I ran the code fragment after Excel startup.

The try/catch does not catch the exception when this code runs at Excel startup. It simply fails silently.

When run after startup, the code does catch the exception and the exception's error message explained exactly what my problem was: The resource could not be found. Duh!

It turns out that this is because I am playing around with the project's namespace in order to build the addin for two different product names and namespaces. Problems with some of the conditional compilation commands I used caused the product I was testing to look for the resource in the wrong class.
Random Solutions  
programming4us programming4us