ASP.NET 无法加载程序集

11
我的电脑崩溃了,我现在无法在Visual Studio 2008中启动之前工作正常的ASP.NET Web应用程序 - 出现以下错误:
=== Pre-bind state information ===
LOG: User = Adam-PC\Adam
LOG: DisplayName = log4net
 (Partial)
LOG: Appbase = file:///C:/Users/Adam/Desktop/SV/sview/Src/StoredProcedureTest/SV.Common.Web/
LOG: Initial PrivatePath = C:\Users\Adam\Desktop\SV\sview\Src\StoredProcedureTest\SV.Common.Web\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Adam\Desktop\SV\sview\Src\StoredProcedureTest\SV.Common.Web\web.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Adam/AppData/Local/Temp/Temporary ASP.NET Files/root/b898aa04/e528dbc7/log4net.DLL.
LOG: Attempting download of new URL file:///C:/Users/Adam/AppData/Local/Temp/Temporary ASP.NET Files/root/b898aa04/e528dbc7/log4net/log4net.DLL.
LOG: Attempting download of new URL file:///C:/Users/Adam/Desktop/SV/sview/Src/StoredProcedureTest/SV.Common.Web/bin/log4net.DLL.
LOG: Using application configuration file: C:\Users\Adam\Desktop\SV\sview\Src\StoredProcedureTest\SV.Common.Web\web.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821
ERR: Failed to complete setup of assembly (hr = 0x80070057). Probing terminated.

Stack Trace: 


[FileLoadException: Could not load file or assembly 'log4net' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]

[FileLoadException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
   System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +54
   System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +232
   System.Web.Compilation.BuildManager.CompileGlobalAsax() +51
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +337

[HttpException (0x80004005): Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +58
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +512
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +729

[HttpException (0x80004005): Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8921851
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +259

你尝试重新添加引用了吗? - IrishChieftain
是的,我尝试过了。那是一个临时文件缓存问题。请看下面。 - Adam Levitt
3个回答

22
答案是我必须删除这个文件夹的所有内容:

C:/Users/Adam/AppData/Local/Temp/Temporary ASP.NET Files/root/


@frabiacca 我在一次停电后遇到了同样的问题,与Kev的答案有关。 - muglio

19

在 BSOD 之后,我遇到了相同的错误代码,但是在 .Net 4.0 MVC 3 项目的 VS 2010 中涉及 AutoMapper.dll。对于我而言,解决方法是删除以下路径中的内容:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\temp

(此处为 Windows 7 x64)

似乎当引用 DLL 的临时副本因系统故障而损坏时,就会出现“Bind result: hr = 0x80070057. The parameter is incorrect.”错误消息。解决方法是删除此临时副本。然后,当您重新编译时,编译器将把原始 DLL 重新复制到临时文件夹。


2
同样的事情,只不过我不得不删除 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root 的内容。 - cchamberlain
2
您可能需要检查 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files(请注意 Framework64)。 - DJA
我的问题通过删除 %LocalAppData%\Temp\Temporary ASP.NET Files\ 的内容得到了解决,但是因为提供了一个扎实的问题解释,所以还要点个赞。 - muglio

7

需要检查和删除的完整路径列表:

%LocalAppData%\Temp\Temporary ASP.NET Files\
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\
%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\
%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\
%SystemRoot%\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接