Microsoft KB Archive/272490

= BUG: Error 0x800A02E0 &quot;Cannot Save an Uninitialized Class&quot; on Visual Basic Component =

Article ID: 272490

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Internet Information Server 4.0
 * Microsoft Internet Information Services 5.0
 * Microsoft Active Server Pages 4.0

-



This article was previously published under Q272490



SYMPTOMS
When you create a Visual Basic ActiveX dynamic-link library (DLL) from Active Server Pages (ASP) or from another Microsoft Transaction Server component with CreateInstance and call a method on it that writes to a PropertyBag object, you may receive the following error message when you call the WriteProperty method on the PropertyBag:

Error Type:

SomeComponent (0x800A02E0)

Cannot save an uninitialized class. You must use the global InitProperties method to initialize the class, or load the class from a PropertyBag before trying to save it.

This problem does not occur when you create the component from Visual Basic with the New keyword.



CAUSE
This problem occurs because the IPersistStream::InitNew method is not called on the component that is saved. When the component is created from Visual Basic with New, the Visual Basic runtime calls InitNew for you.



RESOLUTION
To work around this problem, create the component through a factory component in Visual Basic so that Visual Basic creates the component and calls InitNew on the IPersistStreamInit interface.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a new Visual Basic ActiveX DLL. Rename the project &quot;MyBag&quot; and the class &quot;CBag&quot;. Set the persistable property of CBag to &quot;1 persistable&quot;.  Add the following code and compile: Private n As Long

Private Sub Class_InitProperties n = 12 End Sub

Private Sub Class_ReadProperties(PropBag As PropertyBag) n = PropBag.ReadProperty(&quot;n&quot;) End Sub

Private Sub Class_WriteProperties(PropBag As PropertyBag) PropBag.WriteProperty &quot;n&quot;, n End Sub

Public Function Serialize As Byte

Dim pbgState As PropertyBag Set pbgState = New PropertyBag pbgState.WriteProperty &quot;TestSerialize&quot;, Me  Serialize = pbgState.Contents Set pbgState = Nothing End Function   Create an ASP page named Mybag.asp, and paste the following code: <%   set bag = Server.CreateObject(&quot;Bag.CBag&quot;) bag.Serialize response.write &quot;Done&quot; %>                    In your browser, open the page. You receive the above-mentioned error.</li></ol>

Workaround
<ol> Add another class to the project named CBagFactory.</li>  Add a function called CreateBag as follows: Public Function CreateBag As CBag Set CreateBag = New CBag End Function </li> Recompile the DLL.</li>  Replace the ASP code with the following code: <%   set fac = Server.CreateObject(&quot;Bag.CBagFactory&quot;) set bag = fac.CreateBag bag.Serialize response.write &quot;Done&quot; %>                   </li> In your browser, run the ASP page. You do not receive the error message.</li></ol>

<div class="references_section">