I have developed a application which is in its testing phase the application runs well in most time but in one or two computer specifically i am getting this every time i run the application on them .............Please help me to fix the bug...
i am posting the error message below...........
************** Exception Text **************
System.NullReferenceException:
Object reference not set to an instance of an object.
at
ComputerLabMangementProject.
at System.Windows.Forms.Form.
at
System.Windows.Forms.Form.
at
System.Windows.Forms.Control.
at System.Windows.Forms.Control.
at System.Windows.Forms.Control.
at System.Windows.Forms.Control.
at
System.Windows.Forms.
at System.Windows.Forms.
at System.Windows.Forms.Form.
at System.Windows.Forms.Form.
at
ComputerLabMangementProject.
at System.Windows.Forms.Control.
at System.Windows.Forms.Control.
at System.Windows.Forms.
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4200
(NetFxQFE.050727-4200)
CodeBase: file:///C:/Windows/Microsoft.
------------------------------
ComputerLabMangementProject
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Program%20Files/
------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4016
(NetFxQFE.050727-4000)
CodeBase: file:///C:/Windows/assembly/
------------------------------
System
Assembly
Version: 2.0.0.0
Win32 Version: 2.0.50727.4205
(VistaSP2GDR.050727-4200)
CodeBase: file:///C:/Windows/assembly/
------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4016
(NetFxQFE.050727-4000)
CodeBase: file:///C:/Windows/assembly/
------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4016
(NetFxQFE.050727-4000)
CodeBase: file:///C:/Windows/assembly/
------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4016
(NetFxQFE.050727-4000)
CodeBase: file:///C:/Windows/assembly/
------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4016
(NetFxQFE.050727-4000)
CodeBase: file:///C:/Windows/assembly/
------------------------------
System.Data.DataSetExtensions
Assembly Version: 3.5.0.0
Win32 Version: 3.5.30729.1 built by:
SP
CodeBase: file:///C:/Windows/assembly/
------------------------------
System.Core
Assembly Version: 3.5.0.0
Win32 Version: 3.5.30729.1 built by: SP
CodeBase: file:///C:/Windows/assembly/
------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4016
(NetFxQFE.050727-4000)
CodeBase: file:///C:/Windows/assembly/
------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4016
(NetFxQFE.050727-4000)
CodeBase: file:///C:/Windows/assembly/
------------------------------
Sam HobbsPosted Jul 5, 2010, 5:32 PM
My guess is that it is not documented. Probably there is a documented API that you could use and should use instead.
rajPosted Jul 5, 2010, 8:27 AM
all i have fixed the bug the issues was with registry sub key actually any computer which is new and have never used the usb mass device the subkey usbstor is not created and hence i was getting error for only some specific computer ...... now i have fixed the bug i now check wether the subkey exits or not if not exist i create the subkey and hence no null refferrence..........
rajPosted Jul 5, 2010, 6:57 AM
Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true).SetValue("Start", 4);
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("StartMenuLogoff", 1);
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("NoClose", 1);
if ((int)Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true).GetValue("Start") == 3);
all other subsequent registry read wwrite operation line......
if i comment all such registry read write code than the error goes away......therefore it is sure that the proplem is in the code for registry read write but i find no clue as how to fix it as i have written such registry read write code but never faced such exception a quick help will be highly apreaciated
rajPosted Jul 5, 2010, 4:32 AM
Marimuthu ArigovindasamyPosted Jul 5, 2010, 4:06 AM
As per the error message, pbm is in the FormLogOut_Load event only.
rajPosted Jul 5, 2010, 2:51 AM
here is the code for FormLogout please go through it
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Threading;
using System.Diagnostics;
namespace ComputerLabMangementProject
{
public partial class FormLogOut : FormBaseLabMangement
{
public FormLogOut()
{
InitializeComponent();
}
private void FormLogOut_Load(object sender, EventArgs e)
{
string userType;
// TODO: This line of code loads data into the 'databaseDataSetGetUserType.Users' table. You can move, or remove it, as needed.
this.usersTableAdapter.Fill(this.databaseDataSetGetUserType.Users);
userType = this.usersTableAdapter.GetUserTypeQuery(Program.frmLogin.UserName).ToString();
//disposes keyboard hook
Program.kh.Dispose();
//shows Task bar
Taskbar.Show();
if (userType != "Administrator" && userType != "Faculty")
{
//this will disable pen drive
Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true).SetValue("Start", 4);
//MessageBox.Show("Pen");
//this refresh registry
//System.Diagnostics.Process.Start(@"c:\windows\System32\RUNDLL32.EXE", "user32.dll, UpdatePerUserSystemParameters");
}
if(userType!="Administrator")
{
//this line will edit registry for removing log off and turn off from xp start menu i have disabled for testing in vista
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("StartMenuLogoff", 1);
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("NoClose", 1);
//Put code to disable task manager
Process[] myProcesses;
// Returns array containing all instances of Explorer.
myProcesses = Process.GetProcessesByName("explorer");
foreach (Process myProcess in myProcesses)
{
//myProcess.CloseMainWindow();
myProcess.Kill();
}
System.Diagnostics.Process.Start(@"Explorer.EXE");
}
if ((int)Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true).GetValue("Start") == 3)
this.ButtonRequestUsb.Enabled = false;
}
private void ButtonChangePassword_Click(object sender, EventArgs e)
{
FormChangePassword frmChangepassword = new FormChangePassword();
DialogResult resultChangePassword = frmChangepassword.ShowDialog();
/*if (frmChangepassword.Sucess == 1)
{
this.Activate();
frmChangepassword.Dispose();
}
else*/
if (resultChangePassword == DialogResult.Cancel)
{
this.Activate();
frmChangepassword.Dispose();
}
}
private void ButtonLogOff_Click(object sender, EventArgs e)
{
DialogResult Sure = MessageBox.Show("Are You Sure You Want to Log off Machine", "Alert", MessageBoxButtons.YesNo);
if (Sure == DialogResult.Yes)
{
FormFeedback frmFeedBack = new FormFeedback();
frmFeedBack.ShowDialog();
if (frmFeedBack.LogOutStatus)
{ //MessageBox.Show("LOgoff");
Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true).SetValue("Start", 3);
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("StartMenuLogoff", 0);
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("NoClose", 0);
ShutDown.Exit(0, 4);
}
else
{
if (frmFeedBack.FeedBack)
{
frmFeedBack.Dispose();
this.Activate();
this.Show();
}
else
{
frmFeedBack.Activate();
frmFeedBack.Show();
}
}
}
else
this.Activate();
}
private void ButtonTurnOff_Click(object sender, EventArgs e)
{
DialogResult Sure = MessageBox.Show("Are You Sure You Want to Turn off Machine", "Alert", MessageBoxButtons.YesNo);
if (Sure == DialogResult.Yes)
{
FormFeedback frmFeedBack = new FormFeedback();
frmFeedBack.ShowDialog();
if (frmFeedBack.LogOutStatus)
{ //MessageBox.Show("Turn Off");
Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true).SetValue("Start", 3);
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("StartMenuLogoff", 0);
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("NoClose", 0);
ShutDown.Exit(1, 0);
}
else
{
if (frmFeedBack.FeedBack)
{
frmFeedBack.Dispose();
this.Activate();
this.Show();
}
else
{
frmFeedBack.Activate();
frmFeedBack.Show();
}
}
}
else
this.Activate();
}
private void ButtonSignOut_Click(object sender, EventArgs e)
{
DialogResult Sure = MessageBox.Show("Are You Sure You Want to Sign Out off Machine", "Alert", MessageBoxButtons.YesNo);
if (Sure == DialogResult.Yes)
{
FormFeedback frmFeedBack = new FormFeedback();
frmFeedBack.ShowDialog();
if (frmFeedBack.LogOutStatus)
{
Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true).SetValue("Start", 3);
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("StartMenuLogoff", 0);
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", true).SetValue("NoClose", 0);
Application.Restart();
}
else
{
if (frmFeedBack.FeedBack)
{
frmFeedBack.Dispose();
this.Activate();
this.Show();
}
else
{
frmFeedBack.Activate();
frmFeedBack.Show();
}
}
}
else
this.Activate();
}
private void ButtonRequestUsb_Click(object sender, EventArgs e)
{
this.ButtonRequestUsb.Enabled = false;
Thread usbThread = new Thread(new ThreadStart(ClassUsbRequest.Request));
usbThread.Start();
}
public delegate void EnableButtonUsbRequest(bool b);
public void changeEnable(bool a)
{
if (this.ButtonRequestUsb.InvokeRequired)
{
this.ButtonRequestUsb.Invoke(new EnableButtonUsbRequest(this.changeEnable), true);
}
else
this.ButtonRequestUsb.Enabled = a;
}
}
}
I am also giving the code for BaseForm which the logOutform inherits
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ComputerLabMangementProject
{
public partial class FormBaseLabMangement :Form
{
protected override void WndProc(ref System.Windows.Forms.Message m)
{
try
{
if (m.Msg != 0x0010)
{
base.WndProc(ref m);
}
else
{
//Windows has send the WM_CLOSE message to your form.
//Ignore this message will make the window stay open.
}
}
catch (Exception ex)
{
MessageBox.Show("error no 0001");
LogAppend.Append(ex.ToString());
}
}
public FormBaseLabMangement()
{
InitializeComponent();
}
}
}
Please try to help me now............ I am unable to catch in which line the error is.........But i can undertand that this error is with regard to windows messaging to my application
Marimuthu ArigovindasamyPosted Jul 4, 2010, 8:11 PM
Reason for the pbm: when Object value is null, when u r accessing the object's function it will throw this error.
For an example, DateTime dateT = null;
when I access dateT.ToString() it throws error.