Solved

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 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