Hi dlemstra/ team members
I am trying to add Magick.NET-x64.dll reference in my project but always getting
"Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format. "
Have posted detailed error message below the message.
Please note that this is working fine Magick.NET-x86.dll on VS 2012.
Few config details of my local machine:
VS: VS 2012
OS: Windows 7 Home Basic 64 bit
Have empty: 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
Have installed: x64 version of Visual C++ Redistributable for Visual Studio 2012
Application targets: It was any CPU, but I changed it to target x64
Have tried with dll present in
Magick.NET-6.8.6.801-Q16-x64-net40-client and also Magick.NET-6.8.6.801-Q16-x64-net20
Could you please let me know what could be the issue.
****************************
Server Error in '/' Application.
Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.
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.BadImageFormatException: Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.
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 'Magick.NET-x64' could not be loaded.
=== Pre-bind state information ===
LOG: User = ar-PC\Ran
LOG: DisplayName = Magick.NET-x64
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Magick.NET-x64 | 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/Ran/Desktop/MvcApplication1/MvcApplication1/
LOG: Initial PrivatePath = C:\Users\Ran\Desktop\MvcApplication1\MvcApplication1\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Ran\Desktop\MvcApplication1\MvcApplication1\web.config
LOG: Using host configuration file: C:\Users\Ran\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/Ran/AppData/Local/Temp/Temporary ASP.NET Files/root/e5a55955/235a416b/Magick.NET-x64.DLL.
LOG: Attempting download of new URL file:///C:/Users/Ran/AppData/Local/Temp/Temporary ASP.NET Files/root/e5a55955/235a416b/Magick.NET-x64/Magick.NET-x64.DLL.
LOG: Attempting download of new URL file:///C:/Users/Ran/Desktop/MvcApplication1/MvcApplication1/bin/Magick.NET-x64.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'Magick.NET-x64' 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 'Magick.NET-x64' 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 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
Comments: ** Comment from web user: SoopahMan **
I am trying to add Magick.NET-x64.dll reference in my project but always getting
"Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format. "
Have posted detailed error message below the message.
Please note that this is working fine Magick.NET-x86.dll on VS 2012.
Few config details of my local machine:
VS: VS 2012
OS: Windows 7 Home Basic 64 bit
Have empty: 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
Have installed: x64 version of Visual C++ Redistributable for Visual Studio 2012
Application targets: It was any CPU, but I changed it to target x64
Have tried with dll present in
Magick.NET-6.8.6.801-Q16-x64-net40-client and also Magick.NET-6.8.6.801-Q16-x64-net20
Could you please let me know what could be the issue.
****************************
Server Error in '/' Application.
Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.
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.BadImageFormatException: Could not load file or assembly 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.
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 'Magick.NET-x64' could not be loaded.
=== Pre-bind state information ===
LOG: User = ar-PC\Ran
LOG: DisplayName = Magick.NET-x64
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Magick.NET-x64 | 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/Ran/Desktop/MvcApplication1/MvcApplication1/
LOG: Initial PrivatePath = C:\Users\Ran\Desktop\MvcApplication1\MvcApplication1\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Ran\Desktop\MvcApplication1\MvcApplication1\web.config
LOG: Using host configuration file: C:\Users\Ran\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/Ran/AppData/Local/Temp/Temporary ASP.NET Files/root/e5a55955/235a416b/Magick.NET-x64.DLL.
LOG: Attempting download of new URL file:///C:/Users/Ran/AppData/Local/Temp/Temporary ASP.NET Files/root/e5a55955/235a416b/Magick.NET-x64/Magick.NET-x64.DLL.
LOG: Attempting download of new URL file:///C:/Users/Ran/Desktop/MvcApplication1/MvcApplication1/bin/Magick.NET-x64.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'Magick.NET-x64' 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 'Magick.NET-x64' 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 'Magick.NET-x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
Comments: ** Comment from web user: SoopahMan **
The Closed message on this bug misunderstands the bug. This bug isn't caused by marking the overall Assembly x64 or not; it's caused by not having this installed on the server:
http://stackoverflow.com/a/18258259/176877
The fact VS2012 redistributables are necessary to get a .Net program to deploy is somewhat unfortunate, but much more unfortunate is the fact the runtime exception is production-only (since local dev will generally have Visual Studio and this redistributable installed) and so vague and misleading. Ideally it just throws a clearer exception linking to that download page, like "ImageMagick requires the VS2012 VC++ Redistributable, even in server environments."