views:

80

answers:

2

hi Experts,

Can anyone pls throw light on this error ?

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in STUB_CREATOR.exe

Additional information: Exception from HRESULT: 0x800A0036 (CTL_E_BADFILEMODE)

This is the line that creates the error

Dim f As New Scripting.FileSystemObject
starter = f.OpenTextFile(stub_path.Text + "\" + cpp_file, Scripting.IOMode.ForWriting)

I have just previously opened the file for writing. but however i have closed the textstream with which i was writing into the file. am i doing anyth worng here ?

A: 

I can't answer on the specific error, but why are you using Scripting.FileSystemObject? There are so many classes in the .NET framework that will do the job for you. In your case, I would suggest looking into the File.OpenWrite method.

Fredrik Mörk
+1  A: 

Is the file writeable? E.g. has the file been closed from the last write or is it still locked (this could easily happen if you are relying on the Garbage Collector to close the file or even release a COM object like FileSystemObject).

Process Monitor can be very helpful to see what the result of the underlying FileOpen is.

One wonders why from VB.net you are using Scripting rather than System.Io? Particularly System.Io.StreamWriter?

Richard