Solved

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

Posted on 2008-10-14
1
186 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now