This project is read-only.

.NET 4.0 library fails under mono

Feb 10, 2012 at 3:32 PM
Edited Feb 10, 2012 at 3:35 PM

Due to a bug in mono 2.10.x, System.Security.Cryptography.HashAlgorithm does not have a Dispose() method.  This causes a runtime exception in SshClient's Connect() and Dispose() methods (and possibly in other places too).

I've posted this as a bug against mono (  Xamarin can be quite slow to respond though so it might be worth considering a workaround.  The HashAlgorithm class has a Clear() method which offers equivalent functionality to Dispose().  I've tested locally that changing all calls to HashAlgorithm.Dispose() to HashAlgorithm.Clear() works under both MS and mono.

I'm happy to provide diffs but in this case, its maybe as easy to describe the changes.  The only files affected were:



The only changes were to replace Dispose() with Clear() for HashAlgorithm members.

Feb 10, 2012 at 3:59 PM


I guess I could create another version which compiles for Mono.

Or you saying that I can replace Dispose calls with Clear and it will work for both versions?

If so can you provide me with changes and I will take a look at it later.

Also, can you open it as an issue so I dont forget to look at it since it can get last with all the discussions here.




Feb 10, 2012 at 4:03 PM

Replacing Dispose calls with Clear will work with both versions.

I'll post this as an issue.

To help me post diffs, can you let me know the format you'l like them in please?  I don't believe I have access to your source control server so I can't use it to help generate diffs.

Feb 10, 2012 at 4:21 PM

ok, thanks.

Well, in the past people used to submit it as a patch, so you can do that if you like or if its few files, then just tell me what and where you changed.




Feb 10, 2012 at 6:42 PM



Can you take a look at latest source code?


I just checked in the changed need to be made for mono, only the one you described earlier in the post as well as possible memory leak in HMac<T> class.




Feb 13, 2012 at 9:59 AM
Edited Feb 13, 2012 at 9:59 AM

Hi Oleg


Thanks, the changes look good.  Unfortunately I missed one instance of Dispose in my OP.


also needs to change to call Clear to work on mono.




Feb 13, 2012 at 2:02 PM

There are also a couple of calls to Dispose remaining in


(_serverMac and _clientMac are both Dispose()d in two places - around lines 1220 & 1940)

Feb 13, 2012 at 2:31 PM

ok, I changed those too now,


By the way, I just realized that silverlight does not support dispose methods too so the way we solved that is by adding Dispose extension method that calls to the Clear internally, so may be its a good idea to do something like that for all not mono supported functions. Just an idea.


Also, if you wanted to include mono source code project so other people could use it, feel free to let me know.




Feb 13, 2012 at 2:59 PM

Thanks for fixing this so quickly Oleg!

The current format of the project is perfect for me so I don't need a mono source code project (and also don't have one to contribute).