I have a class in an assembly that I wish to be a singleton. I want it to be created by my Server application then allow Another application on the same machine to access this class instance.
I am using this lazy loading implementation to ensure only one instance exists:
Private Shared ReadOnly _instance As New Lazy(Of PersonX)(Function() New PersonX(), System.Threading.LazyThreadSafetyMode.ExecutionAndPublication)
Public Shared ReadOnly Property Instance() As PersonX
Get
Return _instance.Value
End Get
End Property
And then I am using a Private Sub New with the following remoting code:
Dim uri As String = String.Format("tcp://{0}:{1}/PersonX", "localhost", 1976)
RemotingServices.Marshal(Person.Instance, uri)
RemotingConfiguration.RegisterActivatedServiceType(GetType(PersonX))
The in my Calling code I create my first instance with:
Dim PersonX as SingletonTestClass.PersonX = SingletonTestClass.PersonX.Instance
I am using the following code to connect to the instance using remoting:
Dim newPerson As SingletonTestClass.PersonX
Dim uri As String = String.Format("tcp://{0}:{1}/PersonX", "localhost", 1976)
newPerson = CType(Activator.GetObject(GetType(SingletonTestClass.PersonX), uri), SingletonTestClass.PersonX)
But now when I try to access the object properties I get an error Requested Service not found on this line:
newPerson.Name = "Fred"