Hi All

I have been keeping a keen eye on the mono implementation of Windows Forms project for quite some time now. After every release I would go test some small apps that was originally developed for windows. I have always had trouble with this one specific test app. I have mono 1.1.17.1 installed.

I compiled the source code on my Linux box successfully, but receive the following error during execution:

Mono System.Windows.Forms Assembly [$auto_build_revision$]
Gtk colorscheme read

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at System.Windows.Forms.MimeIconEngine.GetIconIndexForMimeType (System.String mime_type) [0x00000]
  at System.Windows.Forms.UnixFileSystem..ctor () [0x00000]
  at System.Windows.Forms.MWFVFS..ctor () [0x00000]
  at System.Windows.Forms.FolderBrowserDialog+FolderBrowserTreeView..ctor (System.Windows.Forms.FolderBrowserDialog parent_dialog) [0x00000]
  at (wrapper remoting-invoke-with-check) FolderBrowserTreeView:.ctor (System.Windows.Forms.FolderBrowserDialog)
  at System.Windows.Forms.FolderBrowserDialog..ctor () [0x00000]
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.FolderBrowserDialog:.ctor ()
  at dev.Cleanup.Cleanup.InitializeComponent () [0x00000]
  at dev.Cleanup.Cleanup..ctor () [0x00000]
  at (wrapper remoting-invoke-with-check) dev.Cleanup.Cleanup:.ctor ()
  at dev.Cleanup.Cleanup.Main () [0x00000]

Please see attached the source file for this little program "Cleanup.cs"

Here is the command line for compiling the source code.


$ gmcs -target:winexe -out:Cleanup.exe -r:System.Windows.Forms -r:System.Drawing -r:System.Data Cleanup.cs


I dont know if this is something specific in the code that is causing this problem, or whether is an actual bug.

Regards

Gideon de Swardt

http://sonskyn-techno.blogspot.com



The all-new Yahoo! Mail goes wherever you go - free your email address from your Internet provider.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace dev.Cleanup
{
	/// <summary>
	/// Summary description for Cleanup.
	/// </summary>
	public class Cleanup : System.Windows.Forms.Form
	{
		private System.Windows.Forms.FolderBrowserDialog fbdFolder;
		private System.Windows.Forms.TextBox txbFolder;
		private System.Windows.Forms.Button btnBrowse;
		private System.Windows.Forms.CheckBox chbSVN;
		private System.Windows.Forms.CheckBox chbCSharp;
		private System.Windows.Forms.CheckBox chbUser;
		private System.Windows.Forms.CheckBox chbProject;
		private System.Windows.Forms.Button btnCleanUp;
		private System.Windows.Forms.CheckBox chbObj;
		private System.Windows.Forms.CheckBox chbDebug;
		private System.Windows.Forms.CheckBox chbRESX;
		private System.Windows.Forms.CheckBox chbBin;
		private System.Windows.Forms.CheckBox chbFolder;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Cleanup()
		{
			//
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Cleanup));
			this.fbdFolder = new System.Windows.Forms.FolderBrowserDialog();
			this.txbFolder = new System.Windows.Forms.TextBox();
			this.btnBrowse = new System.Windows.Forms.Button();
			this.chbSVN = new System.Windows.Forms.CheckBox();
			this.chbCSharp = new System.Windows.Forms.CheckBox();
			this.chbUser = new System.Windows.Forms.CheckBox();
			this.chbProject = new System.Windows.Forms.CheckBox();
			this.btnCleanUp = new System.Windows.Forms.Button();
			this.chbObj = new System.Windows.Forms.CheckBox();
			this.chbDebug = new System.Windows.Forms.CheckBox();
			this.chbRESX = new System.Windows.Forms.CheckBox();
			this.chbBin = new System.Windows.Forms.CheckBox();
			this.chbFolder = new System.Windows.Forms.CheckBox();
			this.SuspendLayout();
			// 
			// txbFolder
			// 
			this.txbFolder.Location = new System.Drawing.Point(8, 8);
			this.txbFolder.Name = "txbFolder";
			this.txbFolder.Size = new System.Drawing.Size(320, 20);
			this.txbFolder.TabIndex = 0;
			this.txbFolder.Text = "";
			this.txbFolder.TextChanged += new System.EventHandler(this.txbFolder_TextChanged);
			// 
			// btnBrowse
			// 
			this.btnBrowse.Location = new System.Drawing.Point(336, 8);
			this.btnBrowse.Name = "btnBrowse";
			this.btnBrowse.Size = new System.Drawing.Size(24, 23);
			this.btnBrowse.TabIndex = 1;
			this.btnBrowse.Text = "...";
			this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
			// 
			// chbSVN
			// 
			this.chbSVN.Checked = true;
			this.chbSVN.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chbSVN.Location = new System.Drawing.Point(8, 40);
			this.chbSVN.Name = "chbSVN";
			this.chbSVN.TabIndex = 2;
			this.chbSVN.Text = "SVN Folders";
			// 
			// chbCSharp
			// 
			this.chbCSharp.Checked = true;
			this.chbCSharp.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chbCSharp.Location = new System.Drawing.Point(8, 64);
			this.chbCSharp.Name = "chbCSharp";
			this.chbCSharp.TabIndex = 3;
			this.chbCSharp.Text = "C# Source Files";
			// 
			// chbUser
			// 
			this.chbUser.Checked = true;
			this.chbUser.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chbUser.Location = new System.Drawing.Point(8, 112);
			this.chbUser.Name = "chbUser";
			this.chbUser.TabIndex = 4;
			this.chbUser.Text = "User settings";
			// 
			// chbProject
			// 
			this.chbProject.Checked = true;
			this.chbProject.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chbProject.Location = new System.Drawing.Point(8, 88);
			this.chbProject.Name = "chbProject";
			this.chbProject.TabIndex = 5;
			this.chbProject.Text = "Project Files";
			// 
			// btnCleanUp
			// 
			this.btnCleanUp.Enabled = false;
			this.btnCleanUp.Location = new System.Drawing.Point(280, 136);
			this.btnCleanUp.Name = "btnCleanUp";
			this.btnCleanUp.TabIndex = 6;
			this.btnCleanUp.Text = "Clean Up";
			this.btnCleanUp.Click += new System.EventHandler(this.btnCleanUp_Click);
			// 
			// chbObj
			// 
			this.chbObj.Checked = true;
			this.chbObj.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chbObj.Location = new System.Drawing.Point(112, 40);
			this.chbObj.Name = "chbObj";
			this.chbObj.TabIndex = 7;
			this.chbObj.Text = "Obj Folders";
			// 
			// chbDebug
			// 
			this.chbDebug.Checked = true;
			this.chbDebug.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chbDebug.Location = new System.Drawing.Point(112, 64);
			this.chbDebug.Name = "chbDebug";
			this.chbDebug.TabIndex = 8;
			this.chbDebug.Text = "Debug Files";
			// 
			// chbRESX
			// 
			this.chbRESX.Checked = true;
			this.chbRESX.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chbRESX.Location = new System.Drawing.Point(112, 88);
			this.chbRESX.Name = "chbRESX";
			this.chbRESX.TabIndex = 9;
			this.chbRESX.Text = "RESX";
			// 
			// chbBin
			// 
			this.chbBin.Checked = true;
			this.chbBin.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chbBin.Location = new System.Drawing.Point(112, 112);
			this.chbBin.Name = "chbBin";
			this.chbBin.TabIndex = 10;
			this.chbBin.Text = "bin (exl Config)";
			// 
			// chbFolder
			// 
			this.chbFolder.Checked = true;
			this.chbFolder.CheckState = System.Windows.Forms.CheckState.Checked;
			this.chbFolder.Location = new System.Drawing.Point(216, 40);
			this.chbFolder.Name = "chbFolder";
			this.chbFolder.TabIndex = 11;
			this.chbFolder.Text = "Empty Folder";
			// 
			// Cleanup
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(368, 165);
			this.Controls.Add(this.chbFolder);
			this.Controls.Add(this.chbBin);
			this.Controls.Add(this.chbRESX);
			this.Controls.Add(this.chbDebug);
			this.Controls.Add(this.chbObj);
			this.Controls.Add(this.btnCleanUp);
			this.Controls.Add(this.chbProject);
			this.Controls.Add(this.chbUser);
			this.Controls.Add(this.chbCSharp);
			this.Controls.Add(this.chbSVN);
			this.Controls.Add(this.btnBrowse);
			this.Controls.Add(this.txbFolder);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Cleanup";
			this.Text = "Clean Up";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Cleanup());
		}

		private void btnBrowse_Click(object sender, System.EventArgs e)
		{
			fbdFolder.ShowDialog();
			txbFolder.Text = fbdFolder.SelectedPath;
			if (txbFolder.Text != null) 
			{
				btnCleanUp.Enabled = true;
			}
		}

		private void btnCleanUp_Click(object sender, System.EventArgs e)
		{
			this.btnCleanUp.Enabled = false;
			this.CleanUpFolder(txbFolder.Text);
			this.txbFolder.Text = null;
			MessageBox.Show("Done");
		}

		private void DeleteDirectory(string path)
		{
			string[] sub = Directory.GetDirectories(path);
			for (int index=0; index<sub.Length; index++)
			{
				this.DeleteDirectory(sub[index]);
				File.SetAttributes(sub[index], FileAttributes.Normal);
				Directory.Delete(sub[index]);
			}

			string[] file = Directory.GetFileSystemEntries(path);
			for (int index=0; index<file.Length; index++)
			{
				File.SetAttributes(file[index], FileAttributes.Normal);
				File.Delete(file[index]);
			}
		}
		/// <summary></summary>
		/// <param name="path"></param>
		private void CleanUpFolder(string path)
		{
			DirectoryInfo dirInfo;
			string[] sub = Directory.GetDirectories(path);
			for (int index=0; index<sub.Length; index++)
			{
				dirInfo = new DirectoryInfo(sub[index]);
				if ((chbSVN.Checked && (sub[index].ToUpper().EndsWith("\\.SVN") || sub[index].ToUpper().EndsWith("\\CVS") || sub[index].ToUpper().EndsWith("\\_SVN"))) || (chbObj.Checked && sub[index].ToUpper().EndsWith("\\OBJ")))
				{
					this.DeleteDirectory(sub[index]);
					Directory.Delete(sub[index], true);
				}
				else if (chbBin.Checked && sub[index].ToUpper().EndsWith("\\BIN"))
				{
					if (Directory.GetFiles(sub[index].ToUpper().Replace("\\BIN", ""), "*.config").Length == 0)
					{
						this.DeleteDirectory(sub[index]);
						Directory.Delete(sub[index], true);
					}
				}
				else
				{
					this.CleanUpFolder(sub[index]);
				}
			}
			sub = null;
			dirInfo = null;
			dirInfo = new DirectoryInfo(path);
			FileInfo[] fileInfo = dirInfo.GetFiles();
			for (int index=0; index<fileInfo.Length; index++)
			{
				string ext = fileInfo[index].Extension.ToUpper();
				if ((ext == ".CS" && chbCSharp.Checked) || (ext == ".CSPROJ" && chbProject.Checked) || (ext == ".USER" && chbUser.Checked) || (ext == ".PDB" && chbDebug.Checked) || (ext == ".RESX" && chbRESX.Checked))
				{
					fileInfo[index].Delete();
				}
			}
			if (chbFolder.Checked && dirInfo.GetDirectories().Length == 0 && dirInfo.GetFiles().Length == 0)
			{
				Directory.Delete(path);
			}
			dirInfo = null;
			fileInfo = null;
		}

		private void txbFolder_TextChanged(object sender, System.EventArgs e)
		{
			btnCleanUp.Enabled = (txbFolder.Text.Length > 0);
		}
	}
}
_______________________________________________
Mono-winforms-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Reply via email to