我在项目中使用ICSharp.SharpZipLib.dll时,提示异常TypeLoadException, 使用过这个DLL的朋友进来帮个忙阿,小弟正着急了,到底是怎么回事.到底该怎么弄

解决方案 »

  1.   

    从来只用winrar~~~~~~~~~~~下载个SharpZipLib看看是否也出这个问题
      

  2.   

    给你个源码你先看看,我做个小程序测试一下。或者你用的时候是如何出错的?能否在详细说一下?http://www.codeproject.com/KB/cs/Zip_UnZip.aspx
      

  3.   

    我用File.openRean(@"\Program Files\Demo.rar")时报的错,是咋回事呢?
      

  4.   

    自己测试成功,附测试截图:你的File.openRean方法,我没听过,是否打错了?
      

  5.   

    打开文件的方法应该用:            OpenFileDialog f = new OpenFileDialog();
                f.Multiselect = false;
                if (f.ShowDialog() == DialogResult.OK)
                {
                    textBoxFileName.Text = f.FileName;
                }
      

  6.   

    附源码,供参考:主窗体:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using ICSharpCode.SharpZipLib.Zip;
    using System.IO;
    using System.Threading;namespace ZipTest
    {
        public partial class FormZip : Form
        {
            public FormZip()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                radioButtonZip.Checked = true;
            }        private void buttonOpenFile_Click(object sender, EventArgs e)
            {
                //show a openfiledialog to select a file
                OpenFileDialog f = new OpenFileDialog();
                f.Multiselect = false;
                if (f.ShowDialog() == DialogResult.OK)
                {
                    textBoxFileName.Text = f.FileName;
                }
            }        private void buttonOK_Click(object sender, EventArgs e)
            {
                if (textBoxFileName.Text != "")
                {
                    if (radioButtonZip.Checked == true)
                    {
                        //start a new thread to zip it
                        Thread th = new Thread(new ThreadStart(Zip));
                        th.Start();
                    }
                    else
                    {
                        //start a new thread to unzip it
                        Thread th = new Thread(new ThreadStart(UnZip));
                        th.Start();
                    }
                }
            }        private void Zip()
            {
                toolStripStatusLabel1.Text = "Zipping...";
                SetButtonOK(false);
                ZipHelp.Zip(textBoxFileName.Text, textBoxFileName.Text + ".zip", 4096);
                toolStripStatusLabel1.Text = "Done";
                SetButtonOK(true);
            }        private void UnZip()
            {
                toolStripStatusLabel1.Text = "UnZipping...";
                SetButtonOK(false);
                ZipHelp.UnZip(textBoxFileName.Text, Path.GetDirectoryName(textBoxFileName.Text), 4096);
                toolStripStatusLabel1.Text = "Done";
                SetButtonOK(true);
            }        //the method to set button's state
            private void SetButtonOK(bool Enable)
            {
                if (buttonOK.InvokeRequired)
                    buttonOK.Invoke(new SetEnableCallBack(SetButtonOK), new object[] { Enable });
                else
                    buttonOK.Enabled = Enable;
            }        //delegate to call back
            delegate void SetEnableCallBack(bool Enable);
        }
    }ZipHelp.cs类using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using ICSharpCode.SharpZipLib.Zip;namespace ZipTest
    {
        class ZipHelp
        {
            /// <summary>
            /// Zip a file
            /// </summary>
            /// <param name="SrcFile">source file path</param>
            /// <param name="DstFile">zipped file path</param>
            /// <param name="BufferSize">buffer to use</param>
            public static void Zip(string SrcFile, string DstFile, int BufferSize)
            {
                FileStream fileStreamIn = new FileStream(SrcFile, FileMode.Open, FileAccess.Read);
                FileStream fileStreamOut = new FileStream(DstFile, FileMode.Create, FileAccess.Write);
                ZipOutputStream zipOutStream = new ZipOutputStream(fileStreamOut);            byte[] buffer = new byte[BufferSize];            ZipEntry entry = new ZipEntry(Path.GetFileName(SrcFile));
                zipOutStream.PutNextEntry(entry);            int size;
                do
                {
                    size = fileStreamIn.Read(buffer, 0, buffer.Length);
                    zipOutStream.Write(buffer, 0, size);
                } while (size > 0);            zipOutStream.Close();
                fileStreamOut.Close();
                fileStreamIn.Close();
            }        /// <summary>
            /// UnZip a file
            /// </summary>
            /// <param name="SrcFile">source file path</param>
            /// <param name="DstFile">unzipped file path</param>
            /// <param name="BufferSize">buffer to use</param>
            public static void UnZip(string SrcFile, string DstFile, int BufferSize)
            {
                FileStream fileStreamIn = new FileStream(SrcFile, FileMode.Open, FileAccess.Read);
                ZipInputStream zipInStream = new ZipInputStream(fileStreamIn);
                ZipEntry entry = zipInStream.GetNextEntry();
                FileStream fileStreamOut = new FileStream(DstFile + @"\" + entry.Name, FileMode.Create, FileAccess.Write);            int size;
                byte[] buffer = new byte[BufferSize];
                do
                {
                    size = zipInStream.Read(buffer, 0, buffer.Length);
                    fileStreamOut.Write(buffer, 0, size);
                } while (size > 0);            zipInStream.Close();
                fileStreamOut.Close();
                fileStreamIn.Close();
            }
        }
    }
      

  7.   

    我现在是在做PDA开发,要在PDA上下载一个RAR包,然后用代码解压此包.
    是File.OpenRead(RAR包);
      

  8.   


    这个压缩解压都支持的~~~~~~~~//打开文件后,文件名在textBoxFileName中,调用UnZip方法        private void UnZip()
            {
                toolStripStatusLabel1.Text = "UnZipping...";
                SetButtonOK(false);            //注意调用自己写的类ZipHlep.cs
                ZipHelp.UnZip(textBoxFileName.Text, Path.GetDirectoryName(textBoxFileName.Text), 4096);
                toolStripStatusLabel1.Text = "Done";
                SetButtonOK(true);
            }
      

  9.   

    使用你的这个类也提示TypeLoadExceptyion异常,这是为什么呢?
      

  10.   

    自己指定文件夹就行了,你可以再加一个SaveFileDialog对话框,将路径名赋值给ZipHelp类即可,然后给ZipHelp类加个参数就行了
      

  11.   

    运行到ZipInputStream zipInStream = new ZipInputStrem(fileStreanIn);
    的时候报TypeLoadException异常,这是怎么回事呢?我自己写的类也是在这里报错这个异常
      

  12.   


    测试没发现啊,你怎么操作的呢?
    再说刚才你问的保存路径问题,在ZipHelp.cs类中
     public static void UnZip(string SrcFile, string DstFile, int BufferSize)string DstFile参数是目标路径
      

  13.   

    能否把你使用的ICSharpCode.SharpZipLib.Zip; 发我一份,是不是我这份的版本有问题?
    我是这样调用的UnZip(@"\Program Files\Demo.rar",@"\Program Files\Demo.rar",2048);
      

  14.   


    115网盘上传了一个,组件在bin\debug下http://u.115.com/file/t3e1632ce
      

  15.   

    我知道你的原因,你弄的是rar文件,这个不支持rar的,如需要rar支持,可以试试使用7z,或者你能不能不打包成rar?打包成zip就可以解决。看这下面就知道,没有支持rar的功能:
    What is #ziplib? SharpZipLib is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform.
    http://www.icsharpcode.net/
      

  16.   

    我说的试试7z,是指7z的命令行版本,但是7z的命令行单文件版本不支持rar,dll版本才支持,可是你是需要在pda上使用,是否有支持pda的7z版本,还不知道。
    如果在windows上解压rar文件,我知道有个unrar.exe,也有unrar.dll,是免费的,可以调用。不过是否有适合你pda使用的unrar版本,你可以到winrar的官网看看,这是unrar的下载链接,看是否有支持pda平台的方案:
    http://www.rarlab.com/rar_add.htm如果万一不行,不知道你能不能不使用rar——改用zip??? 你说:“我现在是在做PDA开发,要在PDA上下载一个RAR包,然后用代码解压此包.”
      

  17.   

    http://www.rarlab.com/rar_add.htm
    如果这上面没有支持你那pda的unrar版本,你还可以在那上面下载unrar源代码,然后自己编译成适合你那pda平台的版本,然后就可以调用了。
      

  18.   

    小弟现在就在用这个DLL,但我发现了一样东西:就是楼主你写的文件名后辍是不是.rar要是的话,那只能压缩,不能解压,因为不支持.rar的解压,一定要用.zip还有就是一个:一定要写全物理路径
      

  19.   

    那么还是用winrar最好了呵呵,什么格式都支持
      

  20.   

    压缩成rar,那个不会支持了,你说的文件后缀名为rar,倒是实际格式可以不是rar,这个倒可以理解。winrar是一个商业产品,貌似没有支持rar压缩的软件,好压中好像带了rar.exe,但是rar.exe是winrar中用来压缩rar的,是有版权的,所以好压也没有把rar的压缩功能添加进去。
      

  21.   

    7z也支持完整支持那些格式,当然,只支持解压rar,不支持压缩成rar,因为winrar版权的缘故。但是winrar有没有pda的版本?另外是需要授权的,麻烦。何不用zip呢???