Solved

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

Posted on 2011-03-17
3
375 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now