CType cast with a variable

I have a hashtable that I pass into a session. I use a function to get the value back out of the hashtable in the session.

I have to cast everything to a string when i pass it to the hashtable but when I get the value back out of the hashtable from the session i know what datatype i want to pass it back as.

So i pass into the function the Key and the returned DataType. The problem i am having is the CType will not allow for my variable that tells it what type to return. It keeps telling me that it is not a type.

I even tried passing in a type from a function.


    Public Shared Function ConfigSetting( _
                                       ByVal columnName As String, _
                                      ByVal returnDataType As String) As Object

              Dim ht As New Hashtable
              ht = HttpContext.Current.Session("ConfigSettings")
              Dim myValue = ht(columnName)
              Dim convertType As System.Type =  GetTypeByName(returnDataType.Trim)


              Return CType(columnValue, convertType)

        End If
    End Function




    Public Shared Function GetTypeByName(ByVal TypeName As String) As Type
        Dim AssemblyName As String = "System.Type"

        Dim oAssembly As [Assembly]
        oAssembly = [Assembly].Load(AssemblyName)
        Return oAssembly.GetType(TypeName, True, True)

    End Function




-L


LantraxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dancebertCommented:
>I have to cast everything to a string when i pass it to the hashtable

That's not a requirement for a hashtable.  The value added to a Hashtable is type object, so it can be anything.  If you store it as it's original datatype then there is no conversion problem when retrieving it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LantraxAuthor Commented:
i knew that but i was having problems with it when i set the session to the hashtable.  I use hashtables all over the place and never have to cast it to a string but when i tried to pass the hashtable to the session it kept erroring out.

I'll look into it more.

Thanks
-L
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.