System.InvalidCastException error...

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

Hello all and thanks in advance,

I'm running a vb.net program and part of it copies files
from one server to another.

It generally works fine but once in a while I get this
error:

System.InvalidCastException: QueryInterface for interface
Scripting.IFileSystem3 failed.
at Scripting.FileSystemObjectClass.FolderExists(String
FolderSpec)


the line it fails at looks like this:

If fso.FolderExists(srcDir2) Then
....
End IF

Could some one please give me some insight as to why this
error keeps poping up.

Thanks,
Michael
 
Michael said:
Hello all and thanks in advance,

I'm running a vb.net program and part of it copies files
from one server to another.

It generally works fine but once in a while I get this
error:

System.InvalidCastException: QueryInterface for interface
Scripting.IFileSystem3 failed.
at Scripting.FileSystemObjectClass.FolderExists(String
FolderSpec)


the line it fails at looks like this:

If fso.FolderExists(srcDir2) Then
...
End IF

Could some one please give me some insight as to why this
error keeps poping up.

Thanks,
Michael

Am I missing something or are you still using the Scripting COM objects? If
you are, you should really consider using the System.IO namespace. It will
be much easier.

Jeremy
 
Michael
It is preferable to use the methods in File and Directory classes of
System.IO to manipulate files, rather than using scripting (ie.
FileSystemObject)
eg
Imports System.IO
If Directory.Exists("...") Then
.....
End If

Stephen
 
Back
Top