Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Losing references to My.Resources Images
 

Losing references to My.Resources Images

Hi all,

I can't be the only one who experiences this, what I call the Alzheimer's Effect, butwhat must be a bug with VS. My questions are 1) do other people experience the bug (described below), and 2) has anyone found a functional workaround, including bug reports on the issue (my bug search came up empty except for toolstrip-specificissues)?

The issue

I tend to make forms with buttons (in Flat Style) that employ images (both background or foreground) with no text. I import the images through the property grid and everything works great... until some random time later when the designer can no longer load because it loses the reference to the My.Resources "property" for image(s). 9 out of 10 projects will never experience this issue and I am not really doing anything different for the one that does. I should note that the resources are definitely there and are not renamed or manipulated in any way. I can only imagine that the resource file has lost its pointer to the embedded resource itself. However, it must be with how the Designer accesses the resource because the images are always loaded at run time -- I just can;t see them in the designer (I can;t see anything because it throws a hard designer error with the red error message).

The problem can be worked around by adding a new image -- but with a different name (reloading with the same name will not resolve it) or by manually removing the class's Designer code that references the resource (thus causing the button control to be blank). Also, this occurs with toolstrip buttons at the same time as forms buttons.

However, this work around is short-lived at best because eventually (and more frequently the 2nd or 3rd time around) the same thing happens with the new images. It's like the project itself is corrupted. Eventually I have to give up and migrate my code to a new, fresh project and load in image resources afresh -- which can be a major pain! I've even had a case where I cut-and-pasted the form's controls to the new project and caused the new project to become corrupted. Very frustrating!

Any help (other than sympathy - but that's okay too)?

Dig-Boy  Thursday, February 14, 2008 2:27 PM
I had the same exact issue just now. I've never had it before and I've used resources for my images for the past few years. I was able to solve it by closing all of my forms, changing the "application type" under "Project Properties" --> "Application" tab from "Class Library" to something different. I used "Console Application". After that, I was finally able to open my form designer again!
  • Proposed As Answer byjtizzle Wednesday, April 15, 2009 9:45 PM
  • Marked As Answer byDig-Boy Thursday, April 16, 2009 12:00 AM
  •  
jtizzle  Wednesday, April 15, 2009 9:45 PM

UPDATE:

I started this thread because it just happened to me with my current project - a user control. After posting I decided to start again by creating a new user control project. Just so I could confirm some of what I wrote above, I selected all the controls from the corrupted project's form designer (with no images set since I had to delete them all to see the designer again)and copied them to clipboard. I then pasted the controls into the new project's designer (for the user control) successfully.

Next I opened the Resources tab of project properties and manually added the PNG images into the resource manager, jumped back to the control designer and set each control's Image property to one of the embedded images (about 10 total). Everything worked fine.

I then started to work on another VS project and left this one open in the background of Windows and a few hours later activated this project again and tried to view the designer and... BAM! I got the error screen with the message...

The type 'MRF.My.Resources.Resources' has no property named '(the name of the image without extention)'.

at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

...One of these messages for each of my images. (Note: "MRF" is the name of the project's namespace.) I'm curious if maybe its the fact that the VS instance stayed idle for a few hours that has something to do with it. Thinking back I'd say it almost always occurs -- at least the first time -- after coming back to a project that has stayed open. ALso, I can;t say with certainty that it occurs with anything other than PNG images -- I use them to ahieve the transparency without having to resort to Transparency colors.

Any thoughts?

Edit: I found this MSDN help topic on the error object itself...

http://msdn2.microsoft.com/en-us/library/tkxkyzsd.aspx

The basis of this error is that the Get call for the property is expecting a type that is different than the one being returned. It makes me wonder if there is something inherently wrong with the way the resource manager handles PNG images since it has to return a bitmap (sure, a PNG is a bitmap but maybe there's something in the transparency that's malfunctioning?)

Dig-Boy  Thursday, February 14, 2008 6:28 PM

same problem here Sad

PowerMetal  Wednesday, May 14, 2008 4:46 PM
Thanks for the comiseration. I sure hope they fixed this is 2008.

Dig-Boy  Wednesday, May 14, 2008 4:49 PM

This also just happened to me for the first time. I was using .ico and .gif. Sad to say that I don't have an answer and it is VERY annoying. I will keep looking, but I'm hesitant to use My.Resources to load images now...

mfreese11  Thursday, July 17, 2008 6:49 PM

I got the same problem both in vc++2005 and in vc++2008. And, I heppened findan interesting thing that if I type some number in the project name(just like "myproject V1.0")when I create a project, then this problem will never appear. All ofthe things are competely consistent except the project name!

PS: I used .jpg and .bmp image
ISWORD  Thursday, August 07, 2008 2:18 AM

That's a very interesting connection -- and of course equaly as perplexing as the issue itself. For the purposes of recreating the solution, do you mean that you rename the project after the My.Resources failure and the issue goes away? Are there any other steps (i.e. reload the images again, etc.)?

As a follow-up I ended up still loading images into My.Resources (through the Resources tab) but assign the images to teh controls at runtime in teh Load event of the forms. It's been stable without fail but very annoying.

Thanks for the help

Dig-Boy  Thursday, August 07, 2008 11:22 AM
~DigBoy~ wrote:

That's a very interesting connection -- and of course equaly as perplexing as the issue itself. For the purposes of recreating the solution, do you mean that you rename the project after the My.Resources failure and the issue goes away? Are there any other steps (i.e. reload the images again, etc.)?

As a follow-up I ended up still loading images into My.Resources (through the Resources tab) but assign the images to teh controls at runtime in teh Load event of the forms. It's been stable without fail but very annoying.

Thanks for the help


I create a new solution, manully add all controls, resource again…�br>When I first encountered this issue in a project, I tried entering the project name with or without numerals for about five times respectively. At each time, the project which name including number worked well, and others would encounter this issue. So I always type number in project name after that…� |||
ISWORD  Thursday, August 07, 2008 2:27 PM
do you try to clean / rebuild / then close VS and open it again? it make the designer to work again for me, but some time later I have to repeat this f*kin process
PowerMetal  Thursday, August 07, 2008 5:45 PM

I see that if I close the form that crashed.... select "RELEASE" and then "DEBUG" again on the combo from the IDE, open the form again and it works and don't crash Smile If it help you please visit my blog and post a comment Smile good luck

Fabian Silva

http://fabian-silva.blogspot.com/

PowerMetal  Tuesday, September 16, 2008 5:57 PM

Thanks for the suggestion Fabian. I will try it as soon as I can get a project's form to fail on me. I have a recent project that got the same issue and so I just set the background image on a button and tried to get the designer to fail but it didn't. I'll let it hang around a while open on my desktop and see if it can be persuaded and I'll try your suggestion once it takes.

Thanks.

Dig-Boy  Tuesday, September 16, 2008 6:35 PM

Good luck with the designer, if the bug not appears...better for all of us =)

PowerMetal  Sunday, October 05, 2008 4:02 PM
Same problem here. PNG files in embedded resources used on a form. Visual Studio 2008 SP1.

Did anyone raise this with Microsoft Connect??
Laughing John  Friday, March 27, 2009 12:14 PM
Amazing how many hits this thread has received (2000 at this point).

I have to say that I have not had this issue recur since I started the thread (fingers crossed). Maybe posting was good luck. However, I have almost always now loaded my images at runtime rather than design time, so the absence may speak more of that approach than anything else -- despite the fact it was a work around. I'm not religious about it and I use VS almost every day all day long so it should have happened again at some time.

A mystery for the ages I suppose... the ages because MS will never get around to it.
Dig-Boy  Tuesday, March 31, 2009 1:11 AM
Check that your images has the following specifications:

an standard size: i.e: 24x24, 32x32, 48x48, etc.
the deep colors must be 24b or 32b

This issue seems like a bug report by me in the 2005 version of VS.

Do you have installed some addin like CodeRush that uses resources into your project?
Tabas  Thursday, April 02, 2009 12:33 AM
No -- no funny business, just straight VS2005. It's been a while now, but I could easily believe I was using non-standard image sizes since I make most of them myself in an editor.

Can you provide a link that describes the "need" for standard sizes and/or color depths?

Also, are you saying that you submitted a bug report? If so, do you have a link or reportId for that, or can you post the contents of that report? I'd be very interested to see it.

Thanks for the insight.
Dig-Boy  Thursday, April 02, 2009 11:51 AM
I had the same exact issue just now. I've never had it before and I've used resources for my images for the past few years. I was able to solve it by closing all of my forms, changing the "application type" under "Project Properties" --> "Application" tab from "Class Library" to something different. I used "Console Application". After that, I was finally able to open my form designer again!
  • Proposed As Answer byjtizzle Wednesday, April 15, 2009 9:45 PM
  • Marked As Answer byDig-Boy Thursday, April 16, 2009 12:00 AM
  •  
jtizzle  Wednesday, April 15, 2009 9:45 PM


Thanks for the advice. I haven't had a chance to try it yet. However, I just had the issue come up again with a project so I might get the chance. Strangely, I get a different error message -- before it was a red (I believe) colored message on a white background. Now I get this very long XML string as one line. Not sure what has changed in my system to have this occur.

I marked it as answer since I believe your story. Hopefully it will help others.

Dig-Boy  Thursday, April 16, 2009 12:02 AM
I am having the exact same issue. Opening a clean project and copying everything over simply isn't something I'm willing to do - this project is quite large. I have also tried most of the other home remedies with no luck. My problem seems to have the following characteristics:

1) I have multiple forms with user controls. Most of my user controls have images (.png) for various buttons, tool bars, etc.
2) The problem seemed to start after I tried to put a user control on a form, got an error about the constructor for the control (didn't have a Public New with
no parameters). The control was not added to the form, but immediately after, I now have this problem with being able to view ANY of my controls or forms
in the designer that have any reference to one of my images.

This looks like some kind of corruption to me. BTW, I'm using VS2008 with SP1.

I think at this point I'm going to revert to my last backup and hope for the best.

Because of CONSTANT problems with VS2008, luckily I backup OFTEN.
RavenRose  Thursday, May 14, 2009 12:08 AM

You can use google to search for other answers

Custom Search

More Threads

• ListView MultiSelect property issue
• Need to make individual cells in DataGridView read-only programmatically.
• default toolbox tab for usercontrol
• Design problem...
• Custom checkbox and radiobutton control
• Change component icon
• Create custom Controls for Win Forms book, sample, etc
• Move scrollbar at top position
• PropertyGrid.Site
• painting over controls