Could not load file or assembly 'System.Management.Automation'
Asked Answered
T

1

9

I've written an asp.net MVC 3 web application ('ADReporter') on my local machine that uses Powershell to retrieve some data. If I run this application locally, everything works fine. Now I'm trying to run it on my Windows 2008 server but when i'm trying to access it, i get following stack trace:

Server Error in '/ADReporter' Application.

Could not load file or assembly 'System.Management.Automation' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)

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 'System.Management.Automation' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)

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 'System.Management.Automation' could not be loaded.

Stack Trace: 


[FileLoadException: Could not load file or assembly 'System.Management.Automation' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]

[FileLoadException: Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
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 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
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 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254


EDIT
Output of Assembly Binding Log Viewer:

*** Assembly Binder Log Entry  (18/03/2013 @ 11:17:06) ***

The operation failed.
Bind result: hr = 0x80131045. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Windows\SysWOW64\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = IIS APPPOOL\ASP.NET v4.0
LOG: DisplayName = System.Management.Automation (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Management.Automation | 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:/inetpub/wwwroot/ADReporter/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\ADReporter\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\adreporter\96209fa5
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\adreporter\96209fa5
LOG: AppName = f817618b
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\ADReporter\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/adreporter/96209fa5/f817618b/System.Management.Automation.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/adreporter/96209fa5/f817618b/System.Management.Automation/System.Management.Automation.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/ADReporter/bin/System.Management.Automation.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\inetpub\wwwroot\ADReporter\bin\System.Management.Automation.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy.
LOG: Using application configuration file: C:\inetpub\wwwroot\ADReporter\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: Post-policy reference: System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
ERR: Setup failed with hr = 0x80131045.
ERR: Failed to complete setup of assembly (hr = 0x80131045). Probing terminated.

Can please someone help me? I looked for this error for days now... Thanks in advance!

Try answered 18/3, 2013 at 9:47 Comment(11)
This article could help : codeproject.com/Articles/560816/…Plunder
Windows Management Framework 3.0 is installed on the server right?Varlet
@JasonEvans I already tried to add the assembly to the Global Assembly Cache (GAC) but I failed to succeed.Try
What does the Assembly Binding Log Viewer (FUSLOGVW.exe) show? (It gives far more detail about why an assembly failed to load.) But I expect @C.B. has the correct answer.Burnt
You need to install PowerShell 3.0 (by installing WMF 3) to get that assembly. You cannot deploy it on its own.Burnt
@JonathanKortleven Your local machine was x64?Varlet
@C.B. No, my local machine is x86, server architecture is x64. Is this a problem?Try
@Burnt was right. Had to install WMF 3, I only updated Powershell to version 3.0 and installed WinRM 3.0. Thanks guys, searched a long time for this error!Try
@JonathanKortleven I think so. Your application refercence to a x32 assembly, but maybe WMF3.0 is the x64 version on serverVarlet
@C.B. I don't think you can install only x64 WMF, here the x64 install includes both x86 and x64 assemblies.Burnt
@Burnt Thank you for the info, I've never checked it ;)Varlet
T
15

The problem was that I did not install Windows Management Framework 3.0 on the server correctly.

Download link: http://www.microsoft.com/en-us/download/details.aspx?id=34595

Try answered 18/3, 2013 at 10:49 Comment(1)
Correct link: microsoft.com/en-gb/download/details.aspx?id=34595 I too had to restart when installing this. (What year is it?)Revel

© 2022 - 2024 — McMap. All rights reserved.