-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: spprivate
Message 3 in Discussion
BUG: "Object Variable or With Block Variable Not Set" Error Message When You Access a
Public Object VariableView products that this article applies to. This article was
previously published under Q316478 SYMPTOMSWhen you access a public object variable
of a Component Object Model (COM) component in Visual Basic .NET, you may receive the
following error message:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred
in microsoft.visualbasic.dll
Additional information: Object variable or With block variable not set CAUSEThis
behavior can occur if all of the following conditions are true: You define a
public variable in the COM component.
-and- The variable is of the Object type.
-and- You reference this COM component by using late binding.When you access the
public object by using late binding, Visual Basic .NET fails to set the BindingFlags
enumeration properly.
The BindingFlags enumeration is used to specify the flags that control binding and the
way in which the search for members and types is conducted by reflection.
RESOLUTIONTo resolve this issue, use either of the following methods: Use early
binding to access the public object.
-or- Define a public property instead of the public variable. STATUSMicrosoft has
confirmed that this is a bug in the Microsoft products that are listed at the
beginning of this article. MORE INFORMATION Steps to Reproduce the Problem When You
Create the COM Component Create a new ActiveX DLL project in Microsoft Visual
Basic 6.0.
Class1 is created by default. Type the following code in the General Declarations
section of the module:Public obj As Object
Compile this project to Project1.dll. When You Create the Visual Basic .NET
Application Create a new Visual Basic .NET console application, and then
reference Project1.dll. Type the following code:Module Module1 Sub Main()
Dim obj1 As Object obj1 = New Project1.Class1() obj1.obj =
Nothing 'This line causes the error. Console.Read() End Sub End Module
Run the project.
You receive the error message described in the "Symptoms" section of this article.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]