2012-03-10 573 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所在的文件夹中(无需引用它)。

相关问题