Property is reset on COM+ object if ContextUtil.SetComplete() is called
I've got two classes deployed as COM+ components, let's say ClassA and ClassB. ClassA has some public properties. ClassB sets values for those properties and calls a method of ClassA. The method itself does not modify the value of the property.
After the call the values of the properties are reset to default values for the corresponding types. This only happens if the called method includes statement ContextUtil.SetComplete(). Once I comment out the statetment the values of the properties remain same as they were before the method call, which is what I expect.
Do I overllok some basic concept of COM+ objects and their contexts? I would expect the property value to remain the same in any case.
Here's the simplified listing for the code:
Option Strict Off
Option Explicit On
Imports System.EnterpriseServices
<Transaction(TransactionOption.Required)> _
Public Class ClassA
Inherits ServicedComponent
Private _propertyA As String
Pub开发者_StackOverflowlic Property PropertyA() As String
Get
Return Me._propertyA
End Get
Set(ByVal Value As String)
Me._propertyA = Value
End Set
End Property
Public Sub MethodA()
' Do something
ContextUtil.SetComplete() ' If this is called the Str property is reset after return from this call
End Sub
End Class
<Transaction(TransactionOption.Required)> _
Public Class ClassB
Inherits ServicedComponent
Public Sub MethodB()
Dim a As ClassA = New ClassA()
a.PropertyA = "A"
a.MethodA()
' After this call the value of a.PropertyA is reset to Nothing if ContextUtil.SetComplete() was called inside MethodA()
End Sub
End Class
Have you tried calling Commit on the Transaction, IE: ContextUtil.MyTransactionVote = TransactionVote.Commit. It could be that you are making changes and then setting the Context to complete before the changes have actually been committed.
精彩评论