P
PeterB
I know SP2 has been cancelled but I want to highlight this anyway and make
sure it is brought to MS' attention (if it indeed is a bug and not just bad
code from me )
I have written a small test program which demonstrates the bug. The code is
below and is not very complex.
The whole issue is when I reference a own made .NET System Library dll
(which also is within the solution in my case), and this dll uses the
System.Drawing namespace and I instantiate or use the Bitmap class I recieve
an unhandled System.TypeLoadException.
The code is REALLY simple and works for PPC2002 and PPC2003 without SP2 (but
not with).
THE CODE:
This is the actual test program. It needs a reference to ImgDll (see below).
"myImg" is the instance of the "MyImg" class inside the dll.
using System;
using System.Drawing;
using System.Windows.Forms;
using ImgDll;
namespace TestProj
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
static string path = "TestProj.Images.";
Bitmap noPic = null;
MyImage myImg;
public Form1()
{
InitializeComponent();
myImg = new MyImage();
noPic = myImg.Get("noPic");
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(128, 8);
this.pictureBox1.Size = new System.Drawing.Size(96, 136);
//
// button1
//
this.button1.Location = new System.Drawing.Point(152, 152);
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.MinimizeBox = false;
this.Text = "Form1";
}
#endregion
static void Main()
{
try
{
Application.Run(new Form1());
}
catch( System.TypeLoadException typeExc )
{
MessageBox.Show(typeExc.Message);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
this.pictureBox1.Image = myImg.Get("e01");
}
}
}
And this is the System Library dll code, you need two images in the
application directory named noPic.gif and e01.gif:
using System;
using System.Reflection;
using System.Drawing;
namespace ImgDll
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class MyImage
{
Bitmap noPic = null;
static string extension = ".gif";
static string path = "ImgDll.";
public MyImage()
{
noPic = new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(path +
"noPic" + extension ));
}
public Bitmap Get( string strImgName )
{
if( strImgName != "" )
{
string[] tmp = strImgName.Split('.');
strImgName = tmp[0];
strImgName = tmp[0].ToLower();
try
{
Bitmap bmp = new Bitmap(Assembly.GetExecutingAssembly().
GetManifestResourceStream(path + strImgName + extension));
return bmp;
}
catch( Exception exc )
{
return noPic;
}
}
return null;
}
}
}
Any comments???
/ Peter
sure it is brought to MS' attention (if it indeed is a bug and not just bad
code from me )
I have written a small test program which demonstrates the bug. The code is
below and is not very complex.
The whole issue is when I reference a own made .NET System Library dll
(which also is within the solution in my case), and this dll uses the
System.Drawing namespace and I instantiate or use the Bitmap class I recieve
an unhandled System.TypeLoadException.
The code is REALLY simple and works for PPC2002 and PPC2003 without SP2 (but
not with).
THE CODE:
This is the actual test program. It needs a reference to ImgDll (see below).
"myImg" is the instance of the "MyImg" class inside the dll.
using System;
using System.Drawing;
using System.Windows.Forms;
using ImgDll;
namespace TestProj
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
static string path = "TestProj.Images.";
Bitmap noPic = null;
MyImage myImg;
public Form1()
{
InitializeComponent();
myImg = new MyImage();
noPic = myImg.Get("noPic");
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(128, 8);
this.pictureBox1.Size = new System.Drawing.Size(96, 136);
//
// button1
//
this.button1.Location = new System.Drawing.Point(152, 152);
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.MinimizeBox = false;
this.Text = "Form1";
}
#endregion
static void Main()
{
try
{
Application.Run(new Form1());
}
catch( System.TypeLoadException typeExc )
{
MessageBox.Show(typeExc.Message);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
this.pictureBox1.Image = myImg.Get("e01");
}
}
}
And this is the System Library dll code, you need two images in the
application directory named noPic.gif and e01.gif:
using System;
using System.Reflection;
using System.Drawing;
namespace ImgDll
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class MyImage
{
Bitmap noPic = null;
static string extension = ".gif";
static string path = "ImgDll.";
public MyImage()
{
noPic = new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(path +
"noPic" + extension ));
}
public Bitmap Get( string strImgName )
{
if( strImgName != "" )
{
string[] tmp = strImgName.Split('.');
strImgName = tmp[0];
strImgName = tmp[0].ToLower();
try
{
Bitmap bmp = new Bitmap(Assembly.GetExecutingAssembly().
GetManifestResourceStream(path + strImgName + extension));
return bmp;
}
catch( Exception exc )
{
return noPic;
}
}
return null;
}
}
}
Any comments???
/ Peter