I'm trying to compress some data in mono like this:
public static string Save(FlightProgram program, bool compressed)
{
using (MemoryStream ms = new MemoryStream())
{
BinaryFormatter f = new BinaryFormatter();
if (compressed)
{
using (DeflateStream gz = new DeflateStream(ms, CompressionMode.Compress))
{
f.Serialize(gz, program);
}
}
else
{
f.Serialize(ms, program);
}
return Convert.ToBase64String(ms.ToArray()).Replace('/', '_');
}
}
I'm simply getting the exception "CreateZStream". No inner exception. What's going on here ?
Stacktrace:
Could not save flight program: CreateZStream at at (wrapper managed-to-native) System.IO.Compression.DeflateStream:CreateZStream (System.IO.Compression.CompressionMode,bool,System.IO.Compression.DeflateStream/UnmanagedReadOrWrite,intptr)
at System.IO.Compression.DeflateStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen, Boolean gzip) [0x00000] in <filename unknown>:0
at System.IO.Compression.DeflateStream..ctor (System.IO.Stream compressedStream, CompressionMode mode) [0x00000] in <filename unknown>:0
at KSPComputerModule.ProgramSerializer.Save (KSPComputer.FlightProgram program, Boolean compressed) [0x00000] in <filename unknown>:0
at KSPComputerModule.FPComputer.OnSave (.ConfigNode node) [0x00000] in <filename unknown>:0 (State: None)
Surely not relevant to the OP anymore...but I finally managed to resolve this myself. It's a bug in the Mono for Windows deployment. If you delete MonoPosixHelper.dll
files from Mono/GtkSharp directories, you'll find suddenly it works. Running Process Monitor, you can see that instead of going for the mal-compiled MonoPosixHelper.dll
, it now goes for libMonoPosixHelper.dll
...which is compiled correctly.
So, to resolve permanently, either delete all MonoPosixHelper.dll files so it uses libMonoPosixHelper.dll...or, preferably, use a dllmap, adding
<dllmap dll="MonoPosixHelper" target="libMonoPosixHelper.dll" os="windows" />
to either C:\Program Files (x86)\Mono\lib\mono\gac\System\4.0.0.0__b77a5c561934e089\System.dll.config
(create if it doesn't already exist) or to the global Mono config at C:\Program Files (x86)\Mono\etc\mono\config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With