Solved

How can I assign "Me" reference from a class to a value?

Posted on 2008-10-14
1
188 Views
Last Modified: 2013-11-07
I am trying to write a LoadFromFile() Sub that will deserialize a file from the HD into my class object, but I cant do it because " 'Me' cannot be target of an assignment ". Right now I am deserializing into a temporary object and then assigning member by memebr to the Me instance. Is thera a way around this?
Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
        Dim output As FileStream
        Dim fileName As String = file.FullName
 
        Try
            output = New FileStream(fileName, FileMode.Open, FileAccess.Read)
            Dim tempCon As CConnectionData.CSettings
            tempCon = formatter.Deserialize(output)
            Me.m_szDatabase = tempCon.m_szDatabase
            Me.m_szLoginName = tempCon.m_szLoginName
            Me.m_szPassword = tempCon.m_szPassword
            Me.m_szSQLServer = tempCon.m_szSQLServer
            Me.m_nAuthenticationType = tempCon.m_nAuthenticationType
            output.Flush()
            output.Close()
        Catch ex As System.Runtime.Serialization.SerializationException
            Console.WriteLine("Error Reading from File. " & ex.Message)
        End Try

Open in new window

0
Comment
Question by:aferia
1 Comment
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 22711439
to avoid this situation, you can invoke the deserialization class from outside an instance of your class, maybe form a static (Shared) sub, like:

Public Shared Sub Deserialize(filename as String) as CConnectionData.CSettings

     ... all your stuff here

End Sub
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question