Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

resources.GetObject("imageList1.ImageStream") throws System.Reflection.TargetInvocationException

821 views
Skip to first unread message

Jan Pfeil

unread,
Aug 30, 2002, 12:40:10 PM8/30/02
to
Hello NG,

I'm in trouble with a simple ImageList component which doesn't load my
images. Consider the following steps I used to create a simple Windows forms
application with VS:

1. New Project, C#, Windows Application
2. Add ImageList component imageList1 to Form1
3. in imageList1 properties open the 'Image Collection Editor' for Images
and add a simple copy.bmp
4. build and run the application

What I get here is an TargetInvocationException at this line
this.imageList1.ImageStream =
((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.Im
ageStream")));

Later I want to use imageList1 to fill ToolbarButtons with images.
What am I doing wrong? I got the same effect on the SDK sample TreeViewCtl
but I fixed it by recreating the imagelist and it worked. Now I´m confused.
Below I paste the generated code and the console output.

cu
Jan

>>>
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace imagelist
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
public System.Windows.Forms.ImageList imageList1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream =
((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.Im
ageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(288, 262);
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}

<<<

>>> console output >>>
'DefaultDomain': Loaded
'f:\windows\microsoft.net\framework\v1.0.3705\mscorlib.dll', No symbols
loaded.

'imagelist': Loaded 'S:\Source\Net\test\imagelist\bin\Debug\imagelist.exe',
Symbols loaded.

'imagelist.exe': Loaded
'f:\windows\assembly\gac\system.windows.forms\1.0.3300.0__b77a5c561934e089\s
ystem.windows.forms.dll', No symbols loaded.

'imagelist.exe': Loaded
'f:\windows\assembly\gac\system\1.0.3300.0__b77a5c561934e089\system.dll', No
symbols loaded.

'imagelist.exe': Loaded
'f:\windows\assembly\gac\system.drawing\1.0.3300.0__b03f5f7f11d50a3a\system.
drawing.dll', No symbols loaded.

An unhandled exception of type 'System.Reflection.TargetInvocationException'
occurred in mscorlib.dll

Additional information: Exception has been thrown by the target of an
invocation.

Unhandled Exception: System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. --->
System.InvalidOperationException: Failed to load ImageList.

at System.Windows.Forms.ImageListStreamer..ctor(SerializationInfo info,
StreamingContext context)

--- End of inner exception stack trace ---

at System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object
target, SerializationInfo info, StreamingContext context)

at
System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Objec
t obj, SerializationInfo info, StreamingContext context)

at
System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder
holder)

at System.Runtime.Serialization.ObjectManager.DoFixups()

at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(Head
erHandler handler, __BinaryParser serParser, Boolean fCheck,
IMethodCallMessage methodCallMessage)

at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.DeseriaThe
program '[3996] imagelist.exe' has exited with code 0 (0x0).

lize(Stream serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage)

at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream, HeaderHandler handler)

at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(S
tream serializationStream)

at System.Resources.ResourceReader.LoadObject(Int32 pos)

at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean
ignoreCase)

at System.Resources.ResourceManager.GetObject(String name, CultureInfo
culture)

at System.Resources.ResourceManager.GetObject(String name)

at imagelist.Form1.InitializeComponent() in
s:\source\net\test\imagelist\form1.cs:line 60

at imagelist.Form1..ctor() in s:\source\net\test\imagelist\form1.cs:line 23

at imagelist.Form1.Main() in s:\source\net\test\imagelist\form1.cs:line 79

<<<

Yan-Hong Huang[MS]

unread,
Sep 1, 2002, 11:39:03 PM9/1/02
to
A reason of this problem is that:

You have a manifest file for devenv.exe which is the VS .NET IDE. Please
get rid of the manifest file and the sample works again.

Best regards,
yhhuang
VS.NET, Visual C++
Microsoft

This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com

0 new messages