Could not load file or assembly 'DotNetOpenAuth.AspNet' or one of its dependencies - asp.net

I have an Asp.net project, and in said projects web.config i have
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
(already followed a should-be-fix from another post)
but on runtime i get
Could not load file or assembly 'DotNetOpenAuth.AspNet' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
When I open up the properties of my project, and go to refrences, i can see that there is a DotNetOpenAuth.Core entry, a DotNetOpenAuth.AspNet entry, a DotNetOpenAuth.OAuth entry,a DotNetOpenAuth.OAuth.Consumer entry, a DotNetOpenAuth.OpenId entry, and a DotNetOpenAuth.OpenId.RelyingParty entry, and theyre all set to Copy Local = true.
What could possibly be going wrong?
EDIT:
heres the full error log, looks like its still trying to load 4.3.0.0 to me
Assembly Load Trace: The following information can be helpful to determine why the assembly 'DotNetOpenAuth.AspNet' could not be loaded.
=== Pre-bind state information ===
LOG: User = MegaBadTouch\James
LOG: DisplayName = DotNetOpenAuth.AspNet
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: DotNetOpenAuth.AspNet | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/James/Documents/Visual Studio 2012/Projects/Archive/Archive/
LOG: Initial PrivatePath = C:\Users\James\Documents\Visual Studio 2012\Projects\Archive\Archive\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\James\Documents\Visual Studio 2012\Projects\Archive\Archive\web.config
LOG: Using host configuration file: C:\Users\James\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\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/James/AppData/Local/Temp/Temporary ASP.NET Files/root/47d58003/7c1d4013/DotNetOpenAuth.AspNet.DLL.
LOG: Attempting download of new URL file:///C:/Users/James/AppData/Local/Temp/Temporary ASP.NET Files/root/47d58003/7c1d4013/DotNetOpenAuth.AspNet/DotNetOpenAuth.AspNet.DLL.
LOG: Attempting download of new URL file:///C:/Users/James/Documents/Visual Studio 2012/Projects/Archive/Archive/bin/DotNetOpenAuth.AspNet.DLL.
LOG: Using application configuration file: C:\Users\James\Documents\Visual Studio 2012\Projects\Archive\Archive\web.config
LOG: Using host configuration file: C:\Users\James\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.0.0.
LOG: Post-policy reference: DotNetOpenAuth.AspNet, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246
LOG: Attempting download of new URL file:///C:/Users/James/AppData/Local/Temp/Temporary ASP.NET Files/root/47d58003/7c1d4013/DotNetOpenAuth.AspNet.DLL.
LOG: Attempting download of new URL file:///C:/Users/James/AppData/Local/Temp/Temporary ASP.NET Files/root/47d58003/7c1d4013/DotNetOpenAuth.AspNet/DotNetOpenAuth.AspNet.DLL.
LOG: Attempting download of new URL file:///C:/Users/James/Documents/Visual Studio 2012/Projects/Archive/Archive/bin/DotNetOpenAuth.AspNet.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'DotNetOpenAuth.AspNet' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
[FileLoadException: Could not load file or assembly 'DotNetOpenAuth.AspNet, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Could not load file or assembly 'DotNetOpenAuth.AspNet, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +258
System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
[HttpException (0x80004005): Could not load file or assembly 'DotNetOpenAuth.AspNet, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874840
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

I had the same error It was that one of the references that you have added might have got missed . all you need to do is drop the references and add them back manually . or copy your code into a new solution it would work .I copied my code into a " new empty project " and ran it . it had no problems then .
Open a new empty project with new classes and aspx and copy just your code into it , it should work .

I changed the versions to 4.1.0.0 and it worked for me.
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780CCD10D57B246" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780CCD10D57B246" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
</assemblyBinding>

Related

Could not load file or assembly kre-clr-win - How can I specify the KRE?

I'm trying to build my first application with ASP.NET 5 in the Visual Studio 2015 CTP. I just published the app to the file system and copied the folder up to my AWS EC2 instance. I setup the application in IIS so it points to the wwwroot directory from my published app.
I keep getting the Yellow Screen of Death (YSOD) when trying to run the app. Looking at the Event Viewer, I can see an unhandled exception being thrown:
Exception message: Could not load file or assembly 'file:///C:\inetpub\wwwroot\appname\approot\packages\kre-clr-win-x64.1.0.0-beta3\bin\kre.clr.managed.dll' or one of its dependencies
Sure enough, that file doesn't exist on disk. It was never published with my application. I do, however, have the x86 version: kre-clr-win-x86.1.0.0-beta3. That directory was published with my app.
So for some reason my app is being published with kre-clr-win-x86, but when I try to run the published app it's looking for kre-clr-win-x64. How do I fix this issue?
Edit
Here is the generated web.config in the published wwwroot folder:
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta3" />
<add key="runtime-path" value="..\approot\packages" />
<add key="kre-version" value="1.0.0-beta3" />
<add key="kre-clr" value="clr" />
<add key="kre-app-base" value="..\approot\src\appname" />
</appSettings>
</configuration>
Edit 2
As part of publishing a web.cmd file was generated (although I'm not sure what the file's particular use-case is) and if I run it the app gets served on localhost:5000. If I visit the page locally, it works. So it may be something related to the IIS pipeline?
Here's the full stack trace:
Exception information:
Exception type: FileNotFoundException
Exception message: Could not load file or assembly 'file:///C:\inetpub\wwwroot\Gastropub\approot\packages\kre-clr-win-x64.1.0.0-beta3\bin\kre.clr.managed.dll' or one of its dependencies. The system cannot find the file specified. at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence) at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo) at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName) at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName) at AspNet.Loader.Bootstrapper.InitializeNet45(String runtimePackagePath, AppDomain targetDomain, String packagesDir, IObjectHandle& handle, String[]& args) at AspNet.Loader.Bootstrapper.LoadApplicationNet45(String appId, String appConfigPath, IProcessHostSupportFunctions supportFunctions, LoadApplicationData* pLoadAppData, Int32 loadAppDataSize, String runtimePackagePath, String appBasePath) at AspNet.Loader.Bootstrapper.LoadApplication(String appId, String appConfigPath, IProcessHostSupportFunctions supportFunctions, LoadApplicationData* pLoadAppData, Int32 loadAppDataSize) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Web.Hosting.ProcessHost.System.Web.Hosting.IProcessHostLite.ReportCustomLoaderError(String appId, Int32 hr, AppDomain newlyCreatedAppDomain)
--- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters) at System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException)
If you are deploying the application on a 64 bit OS, you need to use the 64 bit KLR.
This is how you bundle an application with the KLR:
kpm bundle --runtime kre-clr-win-x64.1.0.0-beta3
That will produce a folder that contains your application, its dependencies and the CLR. Just copy to the webserver and you should be good to go.

Could not load file or assembly for all of my dll

My asp.net application worked great until 2 days ago when suddenly it show the error below in the run time. It seems Visual Studio can't access any of .dlls. If I have and exclude one of dlls the page shows another error for next dll. what should I do?
Server Error in '/CargoPortal' Application.
Could not load file or assembly 'PersianDateControls 2.0' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileLoadException: Could not load file or assembly 'PersianDateControls 2.0' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'PersianDateControls 2.0' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileLoadException: Could not load file or assembly 'PersianDateControls 2.0' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
[FileLoadException: Could not load file or assembly 'PersianDateControls 2.0, Version=2.0.3505.24227, Culture=neutral, PublicKeyToken=null' 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 'PersianDateControls 2.0, Version=2.0.3505.24227, Culture=neutral, PublicKeyToken=null' 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.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +600
System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125
System.Web.Compilation.BuildManager.CompileCodeDirectories() +265
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +320
[HttpException (0x80004005): Could not load file or assembly 'PersianDateControls 2.0, Version=2.0.3505.24227, Culture=neutral, PublicKeyToken=null' 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 'PersianDateControls 2.0, Version=2.0.3505.24227, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8995539
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +259
Version Information: Microsoft .NET Framework Version:2.0.50727.8000; ASP.NET Version:2.0.50727.8001
Try to clean bin folder and the temp folder at the following location :
C:\Users\your_username\AppData\Local\Temp\Temporary ASP.NET
Do the same for all frameworks , if your application is running under 4.0 you should delete the Temp folder under 4.0
I created a new project from begin and problem solved

BadImageFormatException exception

I am trying to run a WCF service which i created in Visual studio 2012.
I am getting below error in the page.
> Exception Details: System.BadImageFormatException: Could not load file
> or assembly 'dllname' or one of its dependencies. An attempt was made
> to load a program with an incorrect format.
>
> -------------------------------------------------------------------------------- Assembly Load Trace: The following information can be helpful to
> determine why the assembly 'dllname' could not be loaded.
>
> === Pre-bind state information === LOG: User = IIS APPPOOL\DefaultAppPool LOG: DisplayName = dllname (Partial) WRN:
> Partial binding information was supplied for an assembly: WRN:
> Assembly Name: dllname | Domain ID: 2 WRN: A partial bind occurs when
> only part of the assembly display name is provided. WRN: This might
> result in the binder loading an incorrect assembly. WRN: It is
> recommended to provide a fully specified textual identity for the
> assembly, WRN: that consists of the simple name, version, culture, and
> public key token. WRN: See whitepaper
> http://go.microsoft.com/fwlink/?LinkId=109270 for more information and
> common solutions to this issue. LOG: Appbase =
> file:///D:/wwwroot/website/WebServices/ LOG: Initial PrivatePath =
> D:\wwwroot\website\WebServices\bin Calling assembly : (Unknown).
> === LOG: This bind starts in default load context. LOG: Using application configuration file:
> D:\wwwroot\website\WebServices\web.config LOG: Using host
> configuration file:
> C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config LOG: Using
> machine configuration file from
> C:\Windows\Microsoft.NET\Framework\v4.0.30319\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:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary
> ASP.NET Files/webservices/febcb7de/76686d13/dllname.DLL. LOG:
> Attempting download of new URL
> file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary
> ASP.NET Files/webservices/febcb7de/76686d13/dllname/dllname.DLL. LOG:
> Attempting download of new URL
> file:///D:/wwwroot/website/WebServices/bin/dllname.DLL. ERR: Failed to
> complete setup of assembly (hr = 0x8007000b). Probing terminated.
>
> -------------------------------------------------------------------------------- Stack Trace:
>
> [BadImageFormatException: Could not load file or assembly 'dllname' or
> one of its dependencies. An attempt was made to load a program with an
> incorrect format.]
> System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String
> codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
> StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
> throwOnFileNotFound, Boolean forIntrospection, Boolean
> suppressSecurityChecks) +0
> System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String
> codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
> StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
> throwOnFileNotFound, Boolean forIntrospection, Boolean
> suppressSecurityChecks) +34
> System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName
> assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly,
> StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
> throwOnFileNotFound, Boolean forIntrospection, Boolean
> suppressSecurityChecks) +152
> System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
> Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr
> pPrivHostBinder, Boolean forIntrospection) +77
> System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
> Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
> forIntrospection) +16 System.Reflection.Assembly.Load(String
> assemblyString) +28
> System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
> assemblyName, Boolean starDirective) +38
>
> [ConfigurationErrorsException: Could not load file or assembly
> 'dllname' or one of its dependencies. An attempt was made to load a
> program with an incorrect format.]
> System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
> assemblyName, Boolean starDirective) +752
> System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
> +218 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo
> ai) +130
> System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection
> compConfig) +170
> System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
> +91 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String
> preStartInitListPath) +258
> System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
> System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager
> appManager, IApplicationHost appHost, IConfigMapPathFactory
> configMapPathFactory, HostingEnvironmentParameters hostingParameters,
> PolicyLevel policyLevel, Exception appDomainCreationException) +516
>
> [HttpException (0x80004005): Could not load file or assembly 'dllname'
> or one of its dependencies. An attempt was made to load a program with
> an incorrect format.]
> System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
> System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
> +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
> wr, HttpContext context) +254
>
>
>
> --------------------------------------------------------------------------------
I googled about it and i already tried couple of things.
1) Enable 32 bit application in application pool
2) Made target in project properties as "Any CPU"
3) deleted temporary files, recycled app pool, reset IIS etc
Please help if you have any more suggestions.
It looks like you're trying to load a 64 bit assembly into a 32 bit application pool. I say this because I see C:\Windows\Microsoft.NET\Framework\v4.0.30319\ in the stack trace. If it was a 64 bit application pool, it would use Framework64. Disable "enable 32 bit" and try again.

ASP.NET Can't Load Assembly

My computer crashed and I'm now unable to start my previously working ASP.NET Web Application in Visual Studio 2008 -- getting the following error:
=== 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
The answer is I had to delete this folder's contents:
C:/Users/Adam/AppData/Local/Temp/Temporary ASP.NET Files/root/
After a BSOD, I had same error code but with AutoMapper.dll in VS 2010 for a .Net 4.0 MVC 3 project. The resolution for me was to delete the contents of:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\temp
(This is on Windows 7 x64)
It seems the error message 'Bind result: hr = 0x80070057. The parameter is incorrect.' can be caused when a temporary copy of a referenced DLL becomes corrupted by a system failure. The resolution is to remove this temporary copy. Then when you re-compile the compiler will re-copy the original DLL to the temporary folder.
Full list of paths to check and delete:
%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\

PolicyException when using DotNetOpenAuth library

When I drop the DotNetOpenAuth dll into my /bin directory, my app won't run with the following stack trace. Has anyone had any experience with this library? I've gone through their docs and suspect I'm not deploying it correctly. My web app should be running with full trust on my local machine, so it's unclear what permissions it's asking for that can't be acquired.
Thanks!
Tom
[PolicyException: Required permissions cannot be acquired.]
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +10238142
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +97
[FileLoadException: Could not load file or assembly 'DotNetOpenAuth, Version=3.3.1.9337, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +166
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190
[ConfigurationErrorsException: Could not load file or assembly 'DotNetOpenAuth, Version=3.3.1.9337, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11207304
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +388
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +232
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +48
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +210
System.Web.Compilation.BuildProvidersCompiler..ctor(VirtualPath configPath, Boolean supportLocalization, String outputAssemblyName) +76
System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +11196482
System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +185
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +551
[HttpException (0x80004005): Could not load file or assembly 'DotNetOpenAuth, Version=3.3.1.9337, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +76
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +1012
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters) +1025
[HttpException (0x80004005): Could not load file or assembly 'DotNetOpenAuth, Version=3.3.1.9337, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11301302
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4338644
Oddly, I found the solution was related to this.
The application pool identity has a
property called Load User Profile.
When this value is false, you may
receive the error shown above. To
resolve this, open IIS Manager and
navigate to your application pool
identity. You will find the setting in
the Advanced Settings window. Change
it to true.
I found that when I set it to true, the library began working again. When I flipped it back to false it continued to work even after service restarts and app pool recycles. So, strangely everything seems okay now.
It looks like Code Access Security does not consider DotNetOpenAuth to be loading with full trust. It only needs medium trust, actually, but here is the list of minimum permissions DotNetOpenAuth requests:
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Execution = true)]
[assembly: WebPermission(SecurityAction.RequestMinimum, ConnectPattern = #"http://.*")]
[assembly: WebPermission(SecurityAction.RequestMinimum, ConnectPattern = #"https://.*")]
The second couple MAY be missing from some Medium trust configurations, but again if you're running with full trust it should be a non-issue.
Try adding <trust level="Full"/> to your web.config file in its <system.web> section and see if that either helps, or generates an error that will help you narrow down the problem.

Resources