Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureCLR by

For some unit tests, I need to be able to read the contents of a MemoryStream after it has been closed. As this isn't possible, I want to create a memory stream proxy where the call to Close is a no-op, allowing me to read from it even when code outside of my control has attemped closing it. This however won't work.


(import [System.IO MemoryStream StreamWriter])
(let [stream (proxy [MemoryStream] [] (Close [] (println "close!")))]
  (doto (StreamWriter. stream)
        (.Write "testing")


Execution error (InvalidProgramException) at System.Diagnostics.StackFrame/Write (NO_FILE:0).
Cannot create boxed ByRef-like values.

While it's evident my proxied Close method is called, an error is thrown just after.

1 Answer

0 votes

Issue created. Two other instances have been reported (including my own encounter).
From my initial digging, it is related to overloads of methods such as Write on arguments of types such as ReadOnlySpan. I'm going to guess a problem with stack-allocated object that are not handled properly in IL-generation.

JIRA issue CLRCLR-132 created for this.