Solved

Can't get enumerated value from ResourceReader for files of type bitmap

Posted on 2011-03-17
3
392 Views
Last Modified: 2012-05-11
There is a file used by my system, FormIcons.resources.  I needed to add some more resources of type .png to that file.

I chose Lutz Roeder's .NET Resourcer to add the files, it seemed pretty straightforward.  One of the first things that I noticed is that the old files, which had extensions of type .png were listed by .NET Resourcer as type "System.Byte[]".  The new files, which also had extension.png, were of type System.Drawing.Bitmap.

I tried to iterate through the files, using this code:

string fileName = "FormIcons.resources";
ResourceReader reader = new ResourceReader(ICONPATH + fileName);
IDictionaryEnumerator dictEnum = reader.GetEnumerator();
while (dictEnum.MoveNext()) {
    string name = dictEnum.Key.ToString();
    object oValue = dictEnum.Value;
    Type t = oValue.GetType();
}

No errors going through the System.Byte[] files, but when I hit the bitmaps, I got an error when I tried to access dictEnum.Value.
"Could not load file or assembly System.Drawing, Version=4.0.0.0 yadda, yadda or one of its dependencies.  The system cannot find the file specified."

However, the previous line, which assigned the .Key value to a string, didn't throw an error.  It is just the value that gives it fits.

Is there something wrong with using a file of type bitmap with a ResourceReader?  I know it isn't the .png files themselves, because when I use them as embedded resources and cast them into bitmaps directly using the assembly they work just fine.

Any ideas?
0
Comment
Question by:FrancineTaylor
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
SunnyDark earned 500 total points
ID: 35169767
I think the resourcer is compiled with a .NET framework different from yours... So I would suggest you download the source code for the resourcer:
https://github.com/lutzroeder/Resourcer/tree/master/Source
And recompile it on your computer. Then try using it as before.
0
 
LVL 1

Author Closing Comment

by:FrancineTaylor
ID: 35200281
Yes, that was it.  We are compiling our source code for .NET 3.5, but the resourcer utility was compiled under .NET 4.0.

When I recompiled the utility for 3.5 and re-edited the .resource file, it worked perfectly.
0
 
LVL 1

Author Comment

by:FrancineTaylor
ID: 35200286
One additional note: our older resources were added as type Byte[], and the new came in as Bitmap.  A check is needed to determine the type before converting:

public static Image ValueToImage(object value) {
   ImageConverter imageConverterObject = new ImageConverter();
   Image image = null;
   if (value.GetType().Equals(typeof(Bitmap))) {
      Bitmap bitmap = value as System.Drawing.Bitmap;
      image = (Image)bitmap;
   }
   else {
      image = (Image)imageConverterObject.ConvertFrom(value);
   }
   return image;
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question