s3c
s3c

Reputation: 153

Using pythonnet to pass stream to .net DLL

I'm working with a .NET DLL file processor, but can't seem to get the stream passing working. I have the following relevant methods.

EmbedFile(string): bool
EmbedFile(Stream): bool

When using the string version, it works as expected when given a filename.

encoder.EmbedFile("test.dat")

However, I'm not sure what to pass to the stream version. I've tried io.BytesIO and a file handle, but both give me the following.

TypeError: No method matches given arguments for EmbedFile

What is the correct oject to pass to a .NET method that takes a Stream parameter?

Upvotes: 0

Views: 501

Answers (1)

Michael Piazza
Michael Piazza

Reputation: 26

I know this is a late reply, but have you tried importing a .NET class that inherits from Stream, then constructing an instance in Python.

import clr
from System import File
from System.IO import FileStream

def main():   
    path = "path\\to\\file.dat"

    clrFile = File(path)

    clrFileStream = FileStream(clrFile)

    returnValue = EmbedFile(clrFileStream)

Note: this could require additional import(s) if more .NET parameters are present in the derived Stream's constructor.

Upvotes: 1

Related Questions