Reply
Solved! Go to solution

Cannot access a disposed object

"Cannot access a disposed object.\r\nObject name: 'Form1'."

I am getting this error when no source object is selectd when using the Match Properties command at:

http://www.surfandcode.in/2014/09/match-properties-for-solid-edge-part-1.html

The project files are at:

https://drive.google.com/folderview?id=0BzmOvKOt3iz4bHNqeEloLW8ydFE&usp=sharing#list

 

I believe some files have been lost when moving the solutions folder, like App.Config, but any specific help is highly appreciated.

 

~Tushar

 

2 REPLIES
Solution
Solution
Accepted by topic author Tushar
‎08-26-2015 04:32 AM

Re: Cannot access a disposed object

[ Edited ]

I think the problem is that you are trying to close the form before it has showed.

 

If you change the "Me.Close()" instructions for "End" or "Exit Sub" it works fine.

 

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        On Error Resume Next

	oApp = Marshal.GetActiveObject("SolidEdge.Application")
	If oApp Is Nothing Then
		MessageBox.Show("Solid Edge should be running.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Information)
		'Me.Close()
		'Exit Sub
		End
	End If

	oDoc = oApp.ActiveDocument
	If Not TypeOf oDoc Is SolidEdgeDraft.DraftDocument Then
		MessageBox.Show("A Draft document should be open.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Error)
		'Me.Close()
		'Exit Sub
		End
	Else
		oSSetSource = oDoc.SelectSet
		If oSSetSource.Count > 1 Then
			MessageBox.Show("Select only one source object.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
			'Me.Close()
			'Exit Sub
			End
		ElseIf oSSetSource.Count <= 0 Then
			MessageBox.Show("Select a source object first.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
			'Me.Close()
			'Exit Sub
			End
		ElseIf oSSetSource.Count = 1 Then
			oSource = oSSetSource.Item(1)
			If TypeOf oSource Is SolidEdgeFrameworkSupport.Line2d Or _
			TypeOf oSource Is SolidEdgeFrameworkSupport.Arc2d Or _
			TypeOf oSource Is SolidEdgeFrameworkSupport.Circle2d Or _
			TypeOf oSource Is SolidEdgeFrameworkSupport.Ellipse2d Or _
			TypeOf oSource Is SolidEdgeFrameworkSupport.EllipticalArc2d Or _
			TypeOf oSource Is SolidEdgeFrameworkSupport.BSplineCurve2d Or _
			TypeOf oSource Is SolidEdgeFrameworkSupport.Point2d Then
			sLayer = oSource.Layer
			iColor = oSource.Style.LinearColor
			dWidth = oSource.Style.Width
			sLtype = oSource.Style.DashName
			Else
			MessageBox.Show("Not a valid source object.", sTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
				'Me.Close()
				'Exit Sub
				End
			End If
		End If
	End If
End Sub

 

Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
Development: VB.NET

Re: Cannot access a disposed object

You are gem Hector.

End worked for me though Exit Sub still displayed the dialog.

High time for me to get down and carefully understand the subtle differences.

 

Thanks for the reply and the solution.

 

Regards,

~Tushar