System.ObjectDisposedException

rapture

Member
Joined
May 19, 2005
Messages
10
Programming Experience
Beginner
When I have the following line of code at the end of my file:

myApp.DefInstance.Close()

I am getting a System.ObjectDisposedException at the end of my program execution. The program works fine except for this issue. When I omit this line I don't get the exception, but the process still exists in Task Manager. Any idea on how to resolve this ?

Thanks
 

rapture

Member
Joined
May 19, 2005
Messages
10
Programming Experience
Beginner
Here is the applicable code. This was once VB6 app upgraded to VB.NET. Please ignore formatting problems of the code during cut and paste. Everything runs fine till it gets to the InstallProgress.DefInstance.Close() part.

Thanks


VB.NET:
[size=2][color=#0000ff]Option [/color][/size][size=2][color=#0000ff]Strict [/color][/size][size=2][color=#0000ff]Off[/color][/size]
[size=2][color=#0000ff]Option [/color][/size][size=2][color=#0000ff]Explicit [/color][/size][size=2][color=#0000ff]On[/color][/size]
[size=2][color=#0000ff]Imports[/color][/size][size=2] VB = Microsoft.VisualBasic[/size]
[size=2][color=#0000ff]Imports[/color][/size][size=2] Microsoft.Win32
[/size][size=2][color=#0000ff]Friend[/color][/size][size=2][color=#0000ff]Class[/color][/size][size=2] InstallProgress[/size]
[size=2][color=#0000ff]Inherits[/color][/size][size=2] System.Windows.Forms.Form
 
 
#[/size][size=2][color=#0000ff]Region[/color][/size][size=2] "Windows Form Designer generated code "[/size]
[size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2]()
[/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].New()
 
 
 
 


[/size][size=2][color=#0000ff]If[/color][/size][size=2] m_vb6FormDefInstance [/size][size=2][color=#0000ff]Is[/color][/size][size=2][color=#0000ff]Nothing[/color][/size][size=2][color=#0000ff]Then[indent][/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] m_InitializingDefInstance [/size][size=2][color=#0000ff]Then

 
 
[/color][/size][size=2]m_vb6FormDefInstance = [/size][size=2][color=#0000ff]Me
 
 

[/indent][/color][/size][size=2][color=#0000ff]Else

 
 
[/color][/size][size=2][color=#0000ff]Try[/color][/size][size=2] 
 
 
 
 


[/size][size=2][color=#008000]'For the start-up form, the first instance created is the default instance.[indent][/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType [/size][size=2][color=#0000ff]Is[/color][/size][size=2][color=#0000ff]Me[/color][/size][size=2].GetType [/size][size=2][color=#0000ff]Then[/color][/size]

 
 
[size=2]m_vb6FormDefInstance = [/size][size=2][color=#0000ff]M[/color][/size]
[size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
 
 

[/indent][/color][/size][size=2][color=#0000ff]Catch

 
 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Try
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2][color=#008000]'This call is required by the Windows Form Designer.
 
[/color][/size][size=2]InitializeComponent()
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
[/color][/size][size=2][color=#008000]'Form overrides dispose to clean up the component list.
[/color][/size][size=2][color=#0000ff]Protected[/color][/size][size=2][color=#0000ff]Overloads[/color][/size][size=2][color=#0000ff]Overrides[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Dispose([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] Disposing [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Boolean[/color][/size][size=2])
[/size][size=2][color=#0000ff]If[/color][/size][size=2] Disposing [/size][size=2][color=#0000ff]Then
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2][color=#0000ff]Not[/color][/size][size=2] components [/size][size=2][color=#0000ff]Is[/color][/size][size=2][color=#0000ff]Nothing[/color][/size][size=2][color=#0000ff]Then
[/color][/size][size=2]components.Dispose()
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
[/color][/size][size=2][color=#0000ff]MyBase[/color][/size][size=2].Dispose(Disposing)
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub[/color][/size]
 
 
 
 
 
[size=2][color=#0000ff]'Start of sub[/color][/size]
 
[size=2][color=#0000ff][size=2][color=#0000ff]Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2][color=#000000] InstallProgress_Load([/color][/size][size=2][color=#0000ff]ByVal[/color][/size][size=2][color=#000000] eventSender [/color][/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#000000] System.Object, [/color][/size][size=2][color=#0000ff]ByVal[/color][/size][size=2][color=#000000] eventArgs [/color][/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#000000] System.EventArgs) [/color][/size][size=2][color=#0000ff]Handles[/color][/size][size=2][color=#0000ff]MyBase[/color][/size][size=2][color=#000000].Load[/color]
 
[/size][size=2][color=#008000]
[/color][/size][size=2]InstallProgress.DefInstance.Show()
InstallProgress.DefInstance.Refresh()
 
[/size][size=2]'some code goes here
 
PBar.Value = 10
InstallProgress.DefInstance.Refresh()
 
 
[size=2]Status.Text = "Copying new program files..."
PBar.Value = 40
InstallProgress.DefInstance.Refresh()
 
'some code goes here 
 
 
[size=2]Status.Text = "Importing required windows registry settings..."
PBar.Value = 70
InstallProgress.DefInstance.Refresh()
 
'some code goes here 
 
 
'End of sub
[size=2]InstallProgress.DefInstance.Close()
 
[/size][/size][/size][/size][/color][/size]
 

kulrom

Well-known member
Joined
May 10, 2005
Messages
2,854
Location
Republic of Macedonia
Programming Experience
10+
Maybe this:
PHP:
 If m_vb6FormDefInstance Is Nothing OrElse 
m_vb6FormDefInstance.IsDisposed Then
m_InitializingDefInstance = True
m_vb6FormDefInstance = Me
m_InitializingDefInstance = False
End If

instead:

PHP:
 If m_vb6FormDefInstance IsNothingThen 
If m_InitializingDefInstance Then 
m_vb6FormDefInstance = Me

but i'm not sure this is causing the error ... as i'm not fully familiar with vb6. Only know vb6 equivalents and stuff. But if you decide to unchain yourself from this vb6 code (if i may, sorry if i say something wrong) and if there is anyway i could help you with vb.net code, just let me know ... Cheers ;)
 
Top Bottom