I’m trying to create and use a .NET StreamWriter object inside a classic ASP page (VBScript). Normally I would create the object like this:
Dim writer
Set writer = Server.CreateObject("System.IO.StreamWriter")
However, the constructor for StreamWriter takes a Stream object as a parameter, and the call to CreateObject fails. Even if I could get a parameterless constructor to execute without error, the BaseStream property of the StreamWriter class is read-only, so I couldn’t set it to my Stream after object creation.
Is there a way to specify constructor parameters when doing interop from VBScript to .NET in this way? And no, doing this doesn’t work:
Set writer = Server.CreateObject("System.IO.StreamWriter", stream)
My alternative would be to create my own .NET wrapper class with a paramterless constructor and register that assembly for COM interop, but I’d like to avoid that if it’s not necessary.
According to this post, and the documentation, it is not supported. You need to create a wrapper class in .NET in order to use the StreamWriter from classic ASP.