Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why can I get below [test] statement not to work ?

I' trying to convert my class [KDM_USERSETTINGS] single instance into an object and then back into another instance of the same class

The code breaks when trying to cast back the object into the new instance
What Am I Missing ?

(In the actual app I'm trying to copy the data between two dll's)

Dim OBJ As Object = {CType(Original, KDM_UserSettings)}

              Dim I As New KDM_UserSettings

              I = DirectCast(OBJ, KDM_UserSettings)



1 solution

Do you have KDMUser_Settings defined in two different places, even though they have the same name and structure?

This is a common misconception in .NET, even though the two types look exactly the same, they cannot be cast between each other. There are ways around this but its mostly using unmanaged code and pointers.
Share this answer
Georg Kohler 29-Oct-13 22:04pm    
KDMuser_settings is defined in a module that's added by reference to the DLL (That way they are always the same) - but that probably still counts as two separate definitions ....
What's frustrating, is that it seems like the data is right there at you're finger tip (at least in the debugger)
Ron Beyer 29-Oct-13 22:08pm    
Is the DLL used by both assemblies? Or is it really defined two different times?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900