gpt4 book ai didi

c# - 无法正确加载底层压缩例程

转载 作者:行者123 更新时间:2023-12-05 07:43:40 24 4
gpt4 key购买 nike

我不能再在我的 UWP 应用程序中使用 System.IO.Compression 库,我需要它来压缩未压缩过大以适合独立存储的字符串。我怀疑这是在我更新所有 Nuget 包时开始的。我不断收到以下错误,代码如下,

EDIT 这似乎只发生在 DEBUG 模式下。当我在 RELEASE 模式下编译我的应用程序并部署到设备或本地机器时,它可以在两者上运行。但是当我尝试调试时,它崩溃了(崩溃发生在稍后的代码中,该代码尝试使用解压缩的字符串,该字符串不包含任何内容,因为压缩/解压缩静默失败 - 在 using 语句中 - 并且我的应用程序中的其余代码已执行)

留言

The underlying compression routine could not be loaded correctly.

堆栈跟踪

at System.IO.Compression.Deflater.DeflateInit(CompressionLevel compressionLevel, Int32 windowBits, Int32 memLevel, CompressionStrategy strategy) at System.IO.Compression.Deflater..ctor(CompressionLevel compressionLevel, Int32 windowBits) at System.IO.Compression.DeflateStream.InitializeDeflater(Stream stream, Boolean leaveOpen, Int32 windowBits, CompressionLevel compressionLevel) at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionMode mode, Boolean leaveOpen, Int32 windowBits) at System.IO.Compression.DeflateStream..ctor(Stream stream, CompressionMode mode, Boolean leaveOpen) at myApp.Utilities.Extensions.Compress(String uncompressedString) at myApp.ExtendedSplash.d__17.MoveNext()

我想这可能与此有关

Unzipping throws an "The underlying compression routine could not be loaded correctly"

我不知道该怎么办。是否有不依赖于 System.IO 的替代 Zip 库,我可以在 UWP 中使用? - 我尝试安装 DotNetZip,但无法安装。

代码

public static class Extensions
{
/// <summary>
/// Compresses a string and returns a deflate compressed, Base64 encoded string.
/// </summary>
/// <param name="uncompressedString">String to compress</param>
public static string Compress(this string uncompressedString)
{
var compressedStream = new MemoryStream();
var uncompressedStream = new MemoryStream(Encoding.UTF8.GetBytes(uncompressedString));

using (var compressorStream = new DeflateStream(compressedStream, CompressionMode.Compress, true))
{
uncompressedStream.CopyTo(compressorStream);
}

return Convert.ToBase64String(compressedStream.ToArray());
}

/// <summary>
/// Decompresses a deflate compressed, Base64 encoded string and returns an uncompressed string.
/// </summary>
/// <param name="compressedString">String to decompress.</param>
public static string Decompress(this string compressedString)
{
var decompressedStream = new MemoryStream();
var compressedStream = new MemoryStream(Convert.FromBase64String(compressedString));

using (var decompressorStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
{
decompressorStream.CopyTo(decompressedStream);
}

return Encoding.UTF8.GetString(decompressedStream.ToArray());
}
}

最佳答案

clrcompression.dll 文件很可能已损坏。清理并构建或重建解决方案。

关于c# - 无法正确加载底层压缩例程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43554648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com