icon resources exception - HELP!!!

G

Guest

I have added a ToolBar (toolBar) and an ImageList (ToolBarImageList) controls
to my Form, the ImageList has only 1 icon and the toolBar has only 1 button
with this icon.

The icon file is residing tin the project folder, and all looks fine in the
resource editor and compile ok.

But at runtime InitializeComponent() function fail at the following line:

this.ToolBarImageList.ImageStream =
((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ToolBarImageList.ImageStream")));

It causes to exception throwing as follow:

"An unhandled exception of type
'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

Additional information: Could not find any resources appropriate for the
specified culture (or the neutral culture) in the given assembly. Make sure
"ViewerForm.resources" was correctly embedded or linked into assembly
"Viewer".
baseName: ViewerForm locationInfo: Logger.Viewer.ViewerForm resource file
name: ViewerForm.resources assembly: Viewer, Version=1.0.1937.22886,
Culture=neutral, PublicKeyToken=null"

I had the same problem when I tried to add an icon to the the Form itself to
appear at the left of the caption bar.

Can anybody tell me what this is happening?
 
D

Dennis Myrén

Have you set "Build Action" to "Embedded Resource" for this icon?
If not do that by brining up the properties window for the icon and set that
property.
 
G

Guest

Hi Dennis,

Thanks for yuour reply.

The icon is NOT added to the project workspace (is not present at the
Solution Explorer).
And when I added it to the project workspace, and set it to embedded
Resource' it didn't help at all.

I have another project also with ToolBar and ImageList, but in there the
icon is not inserted to the project workspace. It's just as I described and
it works fine, but I can not tell the difference.

Can you help further?
 
D

Dennis Myrén

Try this function for loading the resource:
/// <summary>
/// Loads an embedded resource.
/// </summary>
/// <param name="resourceName">The name of the resource to be
loaded.</param>
/// <returns>The loaded resource.</returns>
public static System.IO.Stream LoadResource ( string resourceName )
{
System.IO.Stream s = System.Reflection.Assembly.GetExecutingAssembly()
.GetManifestResourceStream(resourceName);
if (null == s)
throw new ResourceNotFoundException(resourceName);
return s;
}
And, the resource name is the fully qualified name.
MyProject.MySubNamespace.MyResource
// Usage:
System.IO.Stream resourceStream =
LoadResource("MyProject.MySubNamespace.MyResource");

If that does'nt help, you might want to enumerate the resources to see what
you actually have managed to embed in the executable. You could use this
function:

public static string [] EnumerateResources ( )
{
return
_System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
}
 
G

Guest

I set a breakpoint at the project that do work at the line:
this.ToolBarImageList.ImageStream =
((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ToolBarImageList.ImageStream")));

And at the Watch I see:
resources.ResourceSets {Count=0} System.Collections.Hashtable

But in the project with the exception it 0 although the icon is present in
the project with Build Action = Embedded Resource.

I find it very strange that one project works fine and the other one does
not, although they both look the same.

Any idea?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top