【问题标题】:Using .NET GZipStream Class with Mono将 .NET GZipStream 类与 Mono 一起使用
【发布时间】:2011-05-11 15:49:30
【问题描述】:

我正在尝试从GZipStream Class 构建一个示例。使用命令gmcs gzip.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”。

【问题讨论】:

    标签: c# .net mono gzip gzipstream


    【解决方案1】:

    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 编译好。感谢您的帮助。
    猜你喜欢
    • 2018-06-12
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多