?
Solved

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

Posted on 2011-03-17
3
Medium Priority
?
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
SunnyDark earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

801 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