Click here to Skip to main content
15,913,773 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralMain Menu Item Pin
mtone2-Jul-04 7:38
mtone2-Jul-04 7:38 
GeneralRe: Main Menu Item Pin
Name Removed2-Jul-04 11:01
Name Removed2-Jul-04 11:01 
Questionhow to copy output of mschart directly to a .bmp file without using clipboard Pin
sushma nagaraj1-Jul-04 22:37
sushma nagaraj1-Jul-04 22:37 
GeneralSAVING A DATABASSE FILE Pin
len_ems1-Jul-04 19:16
len_ems1-Jul-04 19:16 
GeneralRe: SAVING A DATABASSE FILE Pin
Dave Kreskowiak2-Jul-04 3:13
mveDave Kreskowiak2-Jul-04 3:13 
GeneralRe: SAVING A DATABASSE FILE Pin
beowulfagate2-Jul-04 15:57
beowulfagate2-Jul-04 15:57 
GeneralRe: SAVING A DATABASSE FILE Pin
len_ems2-Jul-04 18:11
len_ems2-Jul-04 18:11 
GeneralInvalidCastException - Blurry eyes Pin
Ray Cassick1-Jul-04 18:38
Ray Cassick1-Jul-04 18:38 
Ok, I am about at the end of my rope here. Been looking at this code for hours and can not see what is wrong with it.

I have an object saved to a file using Binary Serialization. The file has also been DES encrypted (it is a license file).

The problem get sall the way down to where I am deserializing the MemoryStream to my variable:

Private m_designtimeLicense As New DesigntimeLicenseToken
. . .

DataFile = New FileStream(filename.ToString, FileMode.Open, FileAccess.Read, FileShare.Read)
desCrypt.Key = arrKey
desCrypt.IV = arrVector
desDecrypt = desCrypt.CreateDecryptor
cryptoStream = New CryptoStream(DataFile, desDecrypt, CryptoStreamMode.Read)
arrHoldtxt = New BinaryReader(cryptoStream).ReadBytes(DataFile.Length)
MemoryStream = New MemoryStream(arrHoldtxt)
BinaryFormatter = New BinaryFormatter
MemoryStream.Position = 0

Select Case mode
    Case ValidationType.Designtime
       m_designtimeLicense = BinaryFormatter.Deserialize(MemoryStream)

    Case ValidationType.Runtime
       m_runtimeLicense = BinaryFormatter.Deserialize(MemoryStream)

End Select

BANG! The code dies right at the first case with InvalidCastException.

I KNOW this code works because I can use the EXACT SAME CODE to open the EXACT SAME FILE and display it in the application that I wrote to create the license files.

The DesigntimeLicenseToken object is a class that I have in a completely separate assembly (so the serialization works) and it has a static version (again to the serialization has no version related issues). It’s interface has not changed at all since I started the project so it can’t be related to that.

The other kicker here is that I use the EXACT SAME CODE to deserialize another object that I use for runtime license and it works NO PROBLEM!

This code only has a problem when it is part of the constructor of a Usercontrol and gets run when I drag a copy of the Usercontrol onto a form, so it is running with the IDE in design time mode making it a PITA to debug.

Does anyone have any ideas?

I checked the types of both the variable (m_designtimeLicense) and the memory stream being deserialized and they are the same. At least they have the same full name so I have to assume that they are the same.

If I deserialize to a generic object:
Dim obj As Object
obj = BinaryFormatter.Deserialize(MemoryStream)

It does not complain. That seems really odd to me. If I then try to convert obj to DesigntimeLicenseToken the cast fails again.



Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.


GeneralRe: InvalidCastException - Blurry eyes Pin
Ray Cassick2-Jul-04 17:24
Ray Cassick2-Jul-04 17:24 
GeneralBrowser Add-on Pin
Anonymous1-Jul-04 11:21
Anonymous1-Jul-04 11:21 
GeneralRe: Browser Add-on Pin
Dave Kreskowiak2-Jul-04 3:05
mveDave Kreskowiak2-Jul-04 3:05 
GeneralCOM Add-In won't connect Pin
joseph_rich_tx1-Jul-04 10:17
joseph_rich_tx1-Jul-04 10:17 
GeneralRe: COM Add-In won't connect Pin
VenkatFor.NET2-Jul-04 8:09
VenkatFor.NET2-Jul-04 8:09 
GeneralRe: COM Add-In won't connect Pin
joseph_rich_tx2-Jul-04 8:40
joseph_rich_tx2-Jul-04 8:40 
GeneralRe: COM Add-In won't connect Pin
Anonymous2-Jul-04 12:27
Anonymous2-Jul-04 12:27 
GeneralRe: COM Add-In won't connect Pin
joseph_rich_tx3-Jul-04 14:22
joseph_rich_tx3-Jul-04 14:22 
GeneralPictureBox Pan Pin
Brad Fackrell1-Jul-04 9:10
Brad Fackrell1-Jul-04 9:10 
GeneralRe: PictureBox Pan Pin
Name Removed1-Jul-04 9:58
Name Removed1-Jul-04 9:58 
GeneralRe: PictureBox Pan Pin
Brad Fackrell1-Jul-04 10:03
Brad Fackrell1-Jul-04 10:03 
GeneralWMPlayer active x, begining of tracks get cut off Pin
Glen Conaway1-Jul-04 7:30
Glen Conaway1-Jul-04 7:30 
GeneralTrigering Application at specified intervals Pin
kashif_kazi1-Jul-04 4:53
kashif_kazi1-Jul-04 4:53 
GeneralRe: Trigering Application at specified intervals Pin
Dave Kreskowiak1-Jul-04 5:33
mveDave Kreskowiak1-Jul-04 5:33 
GeneralRe: Trigering Application at specified intervals Pin
kashif_kazi1-Jul-04 19:58
kashif_kazi1-Jul-04 19:58 
GeneralRe: Trigering Application at specified intervals Pin
Dave Kreskowiak2-Jul-04 2:46
mveDave Kreskowiak2-Jul-04 2:46 
GeneralRe: Trigering Application at specified intervals Pin
kashif_kazi2-Jul-04 19:59
kashif_kazi2-Jul-04 19:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.