C# 在Mono中使用.NET GZipStream类

C# 在Mono中使用.NET GZipStream类,c#,.net,mono,gzip,gzipstream,C#,.net,Mono,Gzip,Gzipstream,我试图从中建立一个例子。使用命令gmcsgzip.cs,我收到了错误消息。gzip.cs与msdn中的源相同 似乎我需要在编译时添加引用。少了什么 gzip.cs(57,32): error CS1061: Type `System.IO.FileStream' does not contain a definition for `CopyTo' and no extension method `CopyTo' of type `System.IO.FileStream' could be fo

我试图从中建立一个例子。使用命令
gmcsgzip.cs
,我收到了错误消息。gzip.cs与msdn中的源相同

似乎我需要在编译时添加引用。少了什么

gzip.cs(57,32): error CS1061: Type `System.IO.FileStream' does not contain a definition for `CopyTo' and no extension method `CopyTo' of type `System.IO.FileStream' could be found (are you missing a using directive or an assembly reference?)
/Library/Frameworks/Mono.framework/Versions/2.10.1/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error)
gzip.cs(86,40): error CS1061: Type `System.IO.Compression.GZipStream' does not contain a definition for `CopyTo' and no extension method `CopyTo' of type `System.IO.Compression.GZipStream' could be found (are you missing a using directive or an assembly reference?)
/Library/Frameworks/Mono.framework/Versions/2.10.1/lib/mono/gac/System/2.0.0.0__b77a5c561934e089/System.dll (Location of the symbol related to previous error)
Compilation failed: 2 error(s), 0 warnings
解决了的
为了使用.NET 4函数,我应该使用“dmcs”,而不是“gmcs”。

Stream.CopyTo
只出现在.NET 4中-它可能还没有出现在Mono中(或者您需要更新的版本)

不过,编写类似的扩展方法很容易:

public static class StreamExtensions
{
    public static void CopyTo(this Stream input, Stream output)
    {
        byte[] buffer = new byte[16 * 1024];
        int bytesRead;
        while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
        {
            output.Write(buffer, 0, bytesRead);
        }
    }
}

我使用的是最新的mono 2.10.2。@prosseek:那么他们可能还没有包括它。我发现我没有使用支持.NET 4.0的dmcs。它使用dmcs编译OK。谢谢你的帮助。