System.InvalidCastException error...

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
 
J

Jeremy Cowles

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
 
S

Stephen Muecke

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
 

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

Top