Solved

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

Posted on 2011-03-17
3
389 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Help 27 57
C# LINQ ForEach() question 6 54
Tracing a live website down to the files which support it 2 25
I need help adding validation to my MVC.Net view 6 6
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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