locked
Unable to use .resX file GIF image resources in CLR managed C++ after upgrade to VS2010 RRS feed

  • Question

  • I have an application that was developed in non-CLR C++ (unmanaged) in VS2003 (or earlier) but is working in VS2005 after some converting. Note that I didn’t do that converting. My employer decided to update the code to CLR VS2010 for easier maintenance. I am a C# programmer and haven’t done C++ for a while and not within VS so I’m not the most experienced in this task.

    I’ve set it to CLR and corrected the errors and most of the warnings, but I’m having a problem with some image resources in the Form1.resX file (took me a while to even figure out that the resources were IN that .resx file).

    I can see them in there and the Form [Design] editor can see the resource and paints the image as a background for its tab:

    this->tabPage1->BackgroundImage = (safe_cast(resources->GetObject("tabPage1.BackgroundImage")));

    The resX file is version 1.3 of the schema or so it says rather than the 2.0 that a newly created windows forms application has but seems OK otherwise.

    So the call seems correctly formed and it’s good enough for the design editor to show the image in the background of the tab inside Visual Studio. But when you run it you get an error:

    An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

    Additional information: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "PRG.Form1.resources" was correctly embedded or linked into assembly "PRG" at compile time, or that all the satellite assemblies required are loadable and fully signed.

    As you can see, the culture is neutral so the fact that there is no culture in the call seems right. I tried deleting the culture tag from the resource entirely but that had no effect. I don’t know quite what the program wants me to do in order to get this image to come up in the running application. 

    Just wanted to add the line that connects the resource file to the form because i'm thinking that could be a problem but I don't know quite how.

    System::Resources::ResourceManager ^ resources = gcnew System::Resources::ResourceManager(C5MLV::Form1::typeid);

    As an experiment, I tried manually adding the background image directly to the form. It erased the existing resources in the .resX file and replaced them with a file at Version 2.0 with just that new image. Unfortunately it didn't work, it got the same error. Since this is a program that has been upgraded continuously, I suspect there are some issues associated with repeated conversion and this is why adding the image doesn't work -- there is probably some code in there from previous VS versions that is problematic to the program when it runs, but I'm not sure quite how to track that down.

    Any suggestions?


    Dave Griffin

    Tuesday, May 27, 2014 2:23 PM

Answers

  • Hi,

    Thanks for posting here.

    According to your description, I think the issue is caused by upgrading between different versions of visual studio. The similar issues in links below may help you understand.

    Can't load resource from .resx after upgrade to 2010

    http://support.microsoft.com/kb/318603

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by DaveGriffin Wednesday, May 28, 2014 1:47 PM
    Wednesday, May 28, 2014 6:49 AM

All replies

  • I still don't know what is going on, but I've had some success working around this with the following procedure:

    1. Pull up the ResX file and export all the graphics to the desktop.

    2. Delete all the lines to read resources and connect the .resX file with the Form1. Delete the .resX file

    3. Go to each tab and click. Go to the properties pane and set each pane to it's picture. Everthing shows up in the visual editor.

    4. Compile -- I get 59 errors, all of which reflect the fact that the Visual editor changed a lot of the UI controls to non static versions.

    5. Change all the now non-static controls back to static, one at a time to avoid changing anything else.

    6. Compile and run. Graphics now appear.

    But why? Perhaps this crudeness if just the problem of multiple VS upgrades. Not sure I have the experience to just rewrite the tool though I'd love to try in C#.


    Dave Griffin

    Tuesday, May 27, 2014 7:04 PM
  • Hi,

    Thanks for posting here.

    According to your description, I think the issue is caused by upgrading between different versions of visual studio. The similar issues in links below may help you understand.

    Can't load resource from .resx after upgrade to 2010

    http://support.microsoft.com/kb/318603

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by DaveGriffin Wednesday, May 28, 2014 1:47 PM
    Wednesday, May 28, 2014 6:49 AM
  • The actual change that seems to work is based on the Microsoft Support article but not quite what they say to do. I right clicked on the Form1.resX file under Form1.h and selected Properties. Then under ConfigurationProperties under ManagedResources under General, I changed the resource logical name:

    $(IntDir)C5MLV.Form1.resources

    to

    C5MLV.Form1.resources

    And that made the resources work. So the support article is right about the source of my problem, but it suggested a change which didn't quite work. There was another article that had something similar but this is what seemed to do the trick. Thanks for your help.

    


    Dave Griffin

    • Proposed as answer by janhec Wednesday, December 19, 2018 3:30 PM
    Wednesday, May 28, 2014 1:46 PM
  • Thanks, Dave!

    This is afaik the only correct answer, and I sampled a few.

    It's simple and to the point (but the point is not very easy to find).

    In VS2017 there are 2 minor differences:

    - Resource Logical Name is under Managed Resources -> general

    - The field is (in my case) initially empty.

    I spent a lot of time on this minor problem. So, again, thanks and may the gods always be with you.

    Jan

    Wednesday, December 19, 2018 3:40 PM