-1

我在这方面遇到了异常,任何人都可以帮助我吗?

Exception:Unable to cast COM object of type 'System.__ComObject' to interface type 'SevenZip.IInArchive'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{23170F69-40C1-278A-0000-000600600000}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

代码:

private void UnZip(string zipToExtract, string unzipDirectoryl) // Extract zip/lot file in same directory
    {

            #region Extraction test - ExtractFiles
            using (var tmp = new SevenZipExtractor(zipToExtract))
            {
                if (this.progressBar1.InvokeRequired)
                {
                    progressBar1.Invoke(new Action(delegate()
                    {
                        progressBar1.Maximum = tmp.ArchiveFileData.Count;
                        progressBar1.Value = 0;
                    }));
                }
                else
                {
                    progressBar1.Maximum = tmp.ArchiveFileData.Count;
                    progressBar1.Value = 0;

                }
                for (int i = 0; i < tmp.ArchiveFileData.Count; i++)
                {
                    tmp.ExtractFiles(unzipDirectoryl, tmp.ArchiveFileData[i].Index);

                    int tempval = 0,tot=0;
                    if (this.progressBar1.InvokeRequired)
                    {
                        progressBar1.Invoke(new Action(delegate() { progressBar1.Value++; tempval = progressBar1.Value; progressBar1.Refresh(); tot = progressBar1.Maximum; }));
                    }
                    else
                    {
                        progressBar1.Value++; //pseudo-code
                        progressBar1.Refresh();
                        tempval = progressBar1.Value;
                        tot = progressBar1.Maximum;
                    }
                    //progressBar1.Value += 1;
                    //progressBar1.Refresh();

                    if (this.label3.InvokeRequired)
                    {
                        label3.Invoke(new Action(delegate() { label3.Text = ((tempval * 100) / (tot)).ToString(); label3.Refresh(); }));
                    }
                    else
                    {
                        label3.Text = ((tempval * 100) / (tmp.ArchiveFileData.Count)).ToString();
                        label3.Refresh();
                    }
                    if (!tmp.ArchiveFileData[i].IsDirectory)
                    {
                        FileInfo f = new FileInfo(unzipDirectoryl + "\\" + tmp.ArchiveFileData[i].FileName);
                        if (f.Length == 0)
                        {
                            status("Error :Zero byte file observed: \\" + tmp.ArchiveFileData[i].FileName, Color.Red);
                        }
                    }
                }
                // To extract more than 1 file at a time or when you definitely know which files to extract,
                // use something like
                //tmp.ExtractFiles(@"d:\Temp\Result", 1, 3, 5);
            }

            #endregion

    } 

我得到了自己的解决方案:这种变化让我得到了完美的结果,但为什么?

int temp= tmp.ArchiveFileData.Count;
if (this.progressBar1.InvokeRequired)
            {
                progressBar1.Invoke(new Action(delegate()
                {
                    progressBar1.Maximum = temp;
                    progressBar1.Value = 0;
                }));
            }
4

1 回答 1

1

它将帮助我摆脱异常:

int temp= tmp.ArchiveFileData.Count;
if (this.progressBar1.InvokeRequired)
        {
            progressBar1.Invoke(new Action(delegate()
            {
                progressBar1.Maximum = temp;
                progressBar1.Value = 0;
            }));
        }
于 2013-04-24T05:40:00.903 回答