2012-03-10 572 views
12

錯誤:無法加載文件或組件ICSharpCode.SharpZipLib ...當使用NuGet包ExcelDataReader

Could not load file or assembly 'ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' or one of its dependencies. The system cannot find the file specified.`

堆棧:

[FileNotFoundException: Could not load file or assembly 'ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' or one of its dependencies. The system cannot find the file specified.]
Excel.Core.ZipWorker.Extract(Stream fileStream) +0
Excel.ExcelOpenXmlReader.Initialize(Stream fileStream) +78

[Asp.Net MVC3 C#]

使用NuGet包ExcelDataReader我試圖簡單地打開保存在文件系統上的.xlsx文件。這裏所使用的代碼:

string filePath = HttpContext.Server.MapPath("~/blank3.xlsx"); 
FileStream stream = System.IO.File.Open(filePath, FileMode.Open, FileAccess.Read); 
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); 

下面是NuGet包的網站: http://exceldatareader.codeplex.com/

是怎麼回事?這應該沒有困難。

回答

12

我遇到了同樣的問題;爲了解決這個問題,我在他們的codeplex項目上找到了合適的強名稱程序集。

http://exceldatareader.codeplex.com下載源代碼,從他們的LIB目錄中抓取程序集,並從我的項目中引用它。

+2

您能否更清楚地瞭解您的流程? – 2013-03-26 20:03:18

0

ICSharpCode.SharpZipLib是強名稱程序集。程序集版本號必須完全匹配,否則將無法加載。請檢查程序集版本。

+1

我在哪裏可以找到組件?它不包含在任何包或我的web.config文件中。 – 2012-03-10 01:32:58

0

因爲dll是.net版本2.0,您的項目更高,如果您從nuget軟件包管理器安裝軟件包 ,它會自動使用運行時程序集綁定,web.config/app.config文件應該像這樣:

<runtime> 
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
    <assemblyIdentity name="ICSharpCode.SharpZipLib" publicKeyToken="1b03e6acf1164f73" culture="neutral" /> 
    <bindingRedirect oldVersion="0.0.0.0-0.85.4.369" newVersion="0.85.4.369" /> 
    </dependentAssembly> 
</assemblyBinding> 

1

如果你越來越是:

Could not load file or assembly 'ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' or one of its dependencies. The system cannot find the file specified.

那麼解決的辦法是下載latest(或爲您的錯誤選擇正確的versionICSharpCode.SharpZipLib.dll來自SharpZipLib website,並將其放置在ExcelDataReader的Excel.dll所在的文件夾中(無需引用它)。

相關問題