System.InvalidCastException: Cast from string " ERROR

  • Thread starter Thread starter raines
  • Start date Start date
R

raines

Hi:
I have a VB.Net application that results in the error above on a
Win2000 PC. I do not see the error on WinXP PCs. Here are the lines of
code that has the problems:


Dim filename2 As String



filename2 = "C:\Documents and Settings\merklw\Desktop\New
Folder\01110511.HUP"

FileOpen(22, filename2, OpenMode.Input) 'This is where the error
occurs.


The file exists and can be opened with NotePad. This is strange to me
since I use the same type of open statement in other places within the
code.


What does the:


Cast from string "
message mean? Any ideas how to fix it?


Thanks,
Jim
 
When you put a breakpoint on the line causing the error does the variable
filename2 still have it's value, or is it an empty string?

-Zorpy
 
The Win2000 PC does not have VB.net installed and I have limited access
to it. I did put some debugging info into the code (opened a text file
& wrote out the file name) and the specified name is what was written
to the debugging text file.
 
Try replacing the FileOpen with the .NET file classes:
File.Open("Path", FileMode.Open, FileAccess.Read)

I usually prefer to work with a reader:
Dim st As StreamReader = New StreamReader("Path")
 
When you say you have limited access what do you mean? Are you talking with
the view of Windows security?

I agree with the other user suggesting IO.StreamReader, but also look into
FileIOPermissions because there are a few people experiecing the same problem
& setting file permissions has overcome this error.
 
I tried this, but it did not solve the problem. I have now found a XP
PC, that I have access to, that experiences the same problem. This XP
PC does not have VB.Net installed either. I have installed the .Net
SDK, but when the problem appears, I get the error box, but JIT does
not start. Any idea how I can get JIT to start?

Thanks,
Jim
 
No not Windows security. I mean the PC is physically about 800 miles
from here and I cannot remote desktop to it.

I tried the IO.StreamReader, but that did not fix the problem.

I checked the file permission, and all looks good.

I have now found a XP PC here that has the same problem. BUT, I cannot
get JIT to start. The XP PC here does not have VB.Net installed, but I
installed the .Net SDK.

Any ideas how to get JIT to work. I have been looking around, but have
not found how to do it.

Thanks,
Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top