C# .net web application with dll deployed from matlab - c#

I searched the similar problem on the website which seems a 32/64 bit thing. But I still can't figure it out even by the method provided such as toggling between 86/64 target platform
The software used here are Visual Studio 2010 and Matlab 2015a. I am testing on a very simple Matlab code in a single .m file which is supposed to plot a sine curve in a figure. There is no input or output for this program:
function [] = testPlot()
x = 0:pi/100:2*pi;
y = sin(x);
%Create a line plot of the data.
figure % opens new figure window
plot(x,y)
It is deployed to dll named testPlotN using matlab NE builder (I guess the dll should be 64bit), which is planned to use in a c# web project. I can successfully test it on a c# console application (no matter the target platform is x86 or x64 seemingly)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using testPlotN; //dll
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
testP obj = new testP();//class from dll
obj.testPlot();//matlab function
Console.ReadKey();
}
}
}
However when I test it in a c# web application, with the main file WebForm1.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
hello my name is<asp:TextBox ID="TextBox1" runat="server"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="OK" />
<br />
<br />
<br />
<asp:Label ID="lbloutput" runat="server"></asp:Label>
<br />
</div>
</form>
</body>
</html>
And on click call for the button is in the file WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading.Tasks;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using testPlotN;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
testP obj = new testP();
obj.testPlot();
}
}
}
When I use choose any cpu by default as platform target when building, it shows the page perfectly without any problem
1
But when I click the button, the error came out
Server Error in '/' Application.
--------------------------------------------------------------------------------
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
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: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Source Error:
Line 36: testP obj = new testP();
Line 37: obj.testPlot();
Line 38: }
Source File: C:\Users\M\Documents\Visual Studio 2010\Projects\WebApplication2\WebApplication2\WebForm1.aspx.cs Line: 36
Stack Trace:
[BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]
MathWorks.MATLAB.NET.Arrays.MWArray.mclmcrInitialize2(Int32 primaryMode) +0
MathWorks.MATLAB.NET.Arrays.MWArray..cctor() +553
[TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception.]
MathWorks.MATLAB.NET.Utility.MWMCR..cctor() +1864
[TypeInitializationException: The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception.]
testPlotN.testP..cctor() +97
[TypeInitializationException: The type initializer for 'testPlotN.testP' threw an exception.]
testPlotN.testP..ctor() +0
WebApplication2.WebForm1.Button1_Click(Object sender, EventArgs e) in C:\Users\M\Documents\Visual Studio 2010\Projects\WebApplication2\WebApplication2\WebForm1.aspx.cs:36
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9659822
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639
While I turned to x64 target platform, the first page can not even show up! And the error message appeared immediately
Server Error in '/' Application.
--------------------------------------------------------------------------------
Could not load file or assembly 'WebApplication2' 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 'WebApplication2' 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 'WebApplication2' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = WebApplication2
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: WebApplication2 | Domain ID: 5
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/M/Documents/Visual Studio 2010/Projects/WebApplication2/WebApplication2/
LOG: Initial PrivatePath = C:\Users\M\Documents\Visual Studio 2010\Projects\WebApplication2\WebApplication2\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\M\Documents\Visual Studio 2010\Projects\WebApplication2\WebApplication2\web.config
LOG: Using host configuration file:
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/M/AppData/Local/Temp/Temporary ASP.NET Files/root/3bb260af/e3ca09a0/WebApplication2.DLL.
LOG: Attempting download of new URL file:///C:/Users/M/AppData/Local/Temp/Temporary ASP.NET Files/root/3bb260af/e3ca09a0/WebApplication2/WebApplication2.DLL.
LOG: Attempting download of new URL file:///C:/Users/M/Documents/Visual Studio 2010/Projects/WebApplication2/WebApplication2/bin/WebApplication2.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'WebApplication2' 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) +36
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) +21
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Could not load file or assembly 'WebApplication2' 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) +738
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +92
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +290
System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531
[HttpException (0x80004005): Could not load file or assembly 'WebApplication2' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9920756
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +456
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.81.0
I have spent two days to debug this. But I still can't figure it out even by the method provided such as toggling between 86/64 target platform and setting of iis to enable 32 bit application.
Any clue would be much appreciated!

the problem was resolved in my case by enabling
Use the 64 bit version of IIS Express for websites and projects
click on tools --> Options --> Projects and Solutions --> Web Projects
Click on the check box to enable Use the 64 bit version of IIS Express for websites and projects

This is likely to do with the version of .NET that you are using and what the DLL was built in. Try adding the following to the configuration file (Web.Config):
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
Also, the "Managed Pipeline" should be set to Classic in IIS

I had this same problem with my MatLab to .NET code. Here are two things to look at:
In Visual Studio, under Project Properties --> Build, set the Platform Target to x64. This will get it to work for testing in IIS Express.
When you deploy, make sure your application pool is set to 64bit only by changing Enable 32-Bit Applications to False.
This worked for me when I had this problem.

Related

First time deploying ASP.NET web api, ran into '/' error

This is the first time i am deploying an ASP web api. The api runs smoothly in Debug/Release section but i got an error when first deployed it.
libzkfpcsharp is a dll that supports only x86. I changed The configuration properties to x86 to support the dll but i still get an error. Anyone knows how to deal with this?
Could not load file or assembly 'libzkfpcsharp' 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 'libzkfpcsharp' 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 'libzkfpcsharp' 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:
[BadImageFormatException: Could not load file or assembly 'libzkfpcsharp' 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.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +232
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +113
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +23
System.Reflection.Assembly.Load(String assemblyString) +35
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48
[ConfigurationErrorsException: Could not load file or assembly 'libzkfpcsharp' 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) +767
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +256
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +58
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +287
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +69
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +137
System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +854
[HttpException (0x80004005): Could not load file or assembly 'libzkfpcsharp' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +532
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +111
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +724
You also need to change you App.domain with in IIS to run in 32 bit mode

Error in Importing "Interop.zkemkeeper.dll" to WCF Service

I have "WCF Service Application" which is .net framework 4.6.1. I need to add "Interop.zkemkeeper.dll" as a reference. but when I added this as reference to the WCF service and when service stated it shows following error on the browser.
"Server Error in '/' Application.
Could not load file or assembly 'Interop.zkemkeeper' 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 'Interop.zkemkeeper' 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 'Interop.zkemkeeper' could not be loaded.
=== Pre-bind state information ===
LOG: DisplayName = Interop.zkemkeeper
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Interop.zkemkeeper | 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/Dushmantha/source/repos/VFTService/VFTService/
LOG: Initial PrivatePath = C:\Users\Dushmantha\source\repos\VFTService\VFTService\bin
Calling assembly : (Unknown).
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Dushmantha\source\repos\VFTService\VFTService\web.config
LOG: Using host configuration file: C:\Users\Dushmantha\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/Dushmantha/AppData/Local/Temp/Temporary ASP.NET Files/vs/224635a0/d24b75c0/Interop.zkemkeeper.DLL.
LOG: Attempting download of new URL file:///C:/Users/Dushmantha/AppData/Local/Temp/Temporary ASP.NET Files/vs/224635a0/d24b75c0/Interop.zkemkeeper/Interop.zkemkeeper.DLL.
LOG: Attempting download of new URL file:///C:/Users/Dushmantha/source/repos/VFTService/VFTService/bin/Interop.zkemkeeper.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'Interop.zkemkeeper' 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) +36
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) +21
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Could not load file or assembly 'Interop.zkemkeeper' 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) +738
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +92
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +290
System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +549
[HttpException (0x80004005): Could not load file or assembly 'Interop.zkemkeeper' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10075108
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254"
Could you try change Platform target to x86?
Click Build button on the toolbar
Click Configuration Manager
Then set Plataform target to x86

Getting an exception related to Elmah after removing it from project

I suppose I forgot something silly while removing Elmah because I'm getting a binding exception at run time...
System.IO.FileNotFoundException: Could not load file or assembly
'Elmah' or one of its dependencies. The system cannot find the file
specified.
A global solution search for the word Elmah (case insensitive) revealed nothing. I have cleaned the solution, emptied the bin folder, checked into IIS express settings. Not a single word about Elmah... I don't know where else to look.
Assembly Load Trace
=== Pre-bind state information ===
LOG: DisplayName = Elmah
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Elmah | 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:///W:/ImplementationSuiviProjet/Source/Portail/
LOG: Initial PrivatePath = W:\ImplementationSuiviProjet\Source\Portail\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: W:\ImplementationSuiviProjet\Source\Portail\web.config
LOG: Using host configuration file: C:\Users\Pier-Luc Michaud\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:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/portail/9481be8a/4a40a731/Elmah.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/portail/9481be8a/4a40a731/Elmah/Elmah.DLL.
LOG: Attempting download of new URL file:///W:/ImplementationSuiviProjet/Source/Portail/bin/Elmah.DLL.
LOG: Attempting download of new URL file:///W:/ImplementationSuiviProjet/Source/Portail/bin/Elmah/Elmah.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/portail/9481be8a/4a40a731/Elmah.EXE.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/portail/9481be8a/4a40a731/Elmah/Elmah.EXE.
LOG: Attempting download of new URL file:///W:/ImplementationSuiviProjet/Source/Portail/bin/Elmah.EXE.
LOG: Attempting download of new URL file:///W:/ImplementationSuiviProjet/Source/Portail/bin/Elmah/Elmah.EXE.
Stack Trace
[FileNotFoundException: Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.]
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +40
System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +37
System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +65
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +38
[ConfigurationErrorsException: Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.]
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +353
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, Boolean checkAptcaBit) +21
System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName, String propertyName, ConfigurationElement configElement) +39
System.Web.Configuration.Common.ModulesEntry..ctor(String name, String typeName, String propertyName, ConfigurationElement configElement) +42
System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +160
System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1068
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +82
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10037820
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Web.config
.csproj
Seems IIS configs were corrupted. I deleted the site and it works fine now. I'm really confused how the file got corrupted however. It was fine when I left the office yesterday.
It has to do with working between different branches of the same project but I can't really say exactly what caused it.

ASP.net Could not load file or assembly

I have tried looking at previous threads with none of them helping me. I am trying to get into web dev with C# asp.net (MVC5) but when trying to run the standard template website I get an error. In Chrome and IE, I have also tried creating new projects. Here are the errors I am recieving:
Could not load file or assembly 'System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
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.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
=== Pre-bind state information ===
LOG: DisplayName = System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///c:/users/chris/documents/visual studio 2013/Projects/WebApplication3/WebApplication3/
LOG: Initial PrivatePath = c:\users\chris\documents\visual studio 2013\Projects\WebApplication3\WebApplication3\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\users\chris\documents\visual studio 2013\Projects\WebApplication3\WebApplication3\web.config
LOG: Using host configuration file: C:\Users\Chris\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Users/Chris/AppData/Local/Temp/Temporary ASP.NET Files/root/710eb268/4f51e2d0/System.Web.WebPages.Deployment.DLL.
LOG: Attempting download of new URL file:///C:/Users/Chris/AppData/Local/Temp/Temporary ASP.NET Files/root/710eb268/4f51e2d0/System.Web.WebPages.Deployment/System.Web.WebPages.Deployment.DLL.
LOG: Attempting download of new URL file:///c:/users/chris/documents/visual studio 2013/Projects/WebApplication3/WebApplication3/bin/System.Web.WebPages.Deployment.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Stack Trace:
[FileLoadException: Could not load file or assembly 'System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 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 'System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 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.LoadAssembly(AssemblyInfo ai) +57
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +285
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
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.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 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) +9913572
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Re-installed and all is good now, 2 hours of my life wasted!

Could not load file or assembly Hunspellx64.dll while using NHUnspell NuGet package?

I have an ASP.NET/MVC Web Role that is using the NHUnspell NuGet package. When I try to run it I get the following error message:
Could not load file or assembly 'Hunspellx64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
This is strange because I as far as I know, my Web Role project should not be trying to load the unmanaged Hunspellx64.dll at all. That should be handled by the managed NHUnspell DLL. That DLL is copied over to the /bin directory of the Web Role as a build step.
UPDATE: Thanks to Thomas's comment about WebActivator being outdated I was able to fix the issue. I am duplicating my reply comment to his accepted answer to make sure others who have this problem see the fix:
I had NHUnspell working successfully before this error started
occurring. What broke things was installing AttributeRouting with
NuGet. AttributeRouting drags in an old version of WebActivator
(1.0.0.0). Unfortunately NuGet does not suggest an update to it when
you execute an Update operation. You have to manually do the update
via the Package Manager Console as per this web page's instructions:
http://www.nuget.org/packages/WebActivator
Here is the rest of the original post before the fix was received:
I have scoured my project for direct references/linkages to Hunspellx64.dll including my NuGet packages configuration, packages.config, web.config, my References list, the raw Project File, etc. I can't find any direct reference to that DLL. Where else can I look or what else can I try to stop my project from trying to load that unmanaged DLL directly? Here is the ASP.NET error dump:
[BadImageFormatException: Could not load file or assembly 'Hunspellx64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.]
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.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +102
System.Reflection.Assembly.LoadFrom(String assemblyFile) +34
WebActivator.PreApplicationStartCode.Start() in D:\Code\Bitbucket\WebActivator\WebActivator\PreApplicationStartCode.cs:11
[InvalidOperationException: The pre-application start initialization method Start on type WebActivator.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Hunspellx64.dll' or one of its dependencies. The module was expected to contain an assembly manifest..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
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): The pre-application start initialization method Start on type WebActivator.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Hunspellx64.dll' or one of its dependencies. The module was expected to contain an assembly manifest..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874568
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
The WebActivator Start method doesn't handle unmanaged DLLs in the bin folder.
As you see in the code file:
https://bitbucket.org/dfowler/webactivator/src/4c558d93cf3a/WebActivator/PreApplicationStartCode.cs
public static void Start() {
lock (initLock) {
if (!hasInited) {
// Go through all the bin assemblies
foreach (var assemblyFile in GetAssemblyFiles()) {
var assembly = Assembly.LoadFrom(assemblyFile);
// Go through all the PreApplicationStartMethodAttribute attributes
// Note that this is *our* attribute, not the System.Web namesake
foreach (PreApplicationStartMethodAttribute preStartAttrib in assembly.GetCustomAttributes(
typeof(PreApplicationStartMethodAttribute),
inherit: false)) {
// If it asks to be called after global.asax App_Start, keep track of the method. Otherwise call it now
if (preStartAttrib.CallAfterGlobalAppStart && HostingEnvironment.IsHosted) {
attribsToCallAfterStart.Add(preStartAttrib);
}
else {
// Invoke the method that the attribute points to
preStartAttrib.InvokeMethod();
}
}
}
The Start() method loads all DLLs as assemblies to probe for its PreApplicationStartMethodAttribute. That fails for an unmanaged DLL because there is no assembly manifest.
It looks you are using a branch (dfolwler?) or a outdated version of WebActivator because the current version can handle this by ignoring all exceptions on assembly load.
private static IEnumerable<Assembly> Assemblies
{
get
{
if (_assemblies == null)
{
// Cache the list of relevant assemblies, since we need it for both Pre and Post
_assemblies = new List<Assembly>();
foreach (var assemblyFile in GetAssemblyFiles())
{
try
{
// Ignore assemblies we can't load. They could be native, etc...
_assemblies.Add(Assembly.LoadFrom(assemblyFile));
}
catch
{
}
}
}
return _assemblies;
}
}
Update WebActivator to the most recent version.

Categories

Resources