Getting Error when start to Debug - c#

When I debug my ASP.NET Web Site I get the following error:
The files "/BookIt.Web/App_Code/VBCode/vCalendar.vb" and "/BookIt.Web/App_Code/CSCode/WebGrid/user/BenutzerCollection.cs" use different languages​​. This is not allowed, because they must be compiled together.
I don't know how to fix that.
Someone can help me?
Stacktrace:
[HttpException (0x80004005): Die Dateien "/BookIt.Web/App_Code/VBCode/QueryStringModule.vb" und "/BookIt.Web/App_Code/CSCode/Webgrid/Dienstleistung/Servicegruppe.cs" verwenden unterschiedliche Sprachen. Dies ist nicht zulässig, weil sie gemeinsam kompiliert werden müssen.]
System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() +452
System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +42
System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +640
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): Die Dateien "/BookIt.Web/App_Code/VBCode/QueryStringModule.vb" und "/BookIt.Web/App_Code/CSCode/Webgrid/Dienstleistung/Servicegruppe.cs" verwenden unterschiedliche Sprachen. Dies ist nicht zulässig, weil sie gemeinsam kompiliert werden müssen.]
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): Die Dateien "/BookIt.Web/App_Code/VBCode/QueryStringModule.vb" und "/BookIt.Web/App_Code/CSCode/Webgrid/Dienstleistung/Servicegruppe.cs" verwenden unterschiedliche Sprachen. Dies ist nicht zulässig, weil sie gemeinsam kompiliert werden müssen.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8921851
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +259

Simply put, you can't mix languages in the same project. You can have a VB.NET project and a C# project in the same solution, one referencing the other. You use one compiler to compile a single project.
You can have code from several languages in the same project if the other languages are included as Build Action: Content, not Build Action: Compile. Of course, you won't be able to use classes and logic from those files.
Code files in the App_Code folder will, however, be automatically compiled
http://msdn.microsoft.com/en-us/library/t990ks23(v=vs.80).aspx
Because the source code in the App_Code folder is compiled into a single assembly, all the files in the App_Code folder must be in the same programming language. For example, the App_Code folder cannot include source code in both Visual Basic and C#.
However, you can configure your Web application to treat subfolders of the App_Code folder as separate compilable units. Each folder can then contain source code in a different programming language. The configuration is specified by creating a codeSubDirectories element in the compilation element of the Web.config file and adding a reference to the subfolder. The following example illustrates how you would configure subfolders named VBCode and CSCode to compile into separate assemblies:
<compilation debug="false">
<codeSubDirectories>
<add directoryName="VBCode" />
<add directoryName="CSCode" />
</codeSubDirectories>
</compilation>

Related

IIS Express: System.ComponentModel.Win32Exception: Access is denied

I just upgraded from VS 2015 to VS 2019. I create a standard MVC project, execute and this error appears "System.ComponentModel.Win32Exception: Access is denied" in the standard 500 error page.
I didn't change anything in the default microsoft code of the standard project.
Tried to execute VS as administrator but nothing changes.
I know there are a lot of people with this problem but they are all talking about problems in production, this happens to me when I start the app in debug from Visual Studio.
The processes of VS and IIS Express are owned by my user with administrator privileges.
Thanks in advance for the help.
Full error: ("Accesso negato" is italian for "Access denied")
Server Error in '/' Application.
Accesso negato
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.ComponentModel.Win32Exception: Accesso negato
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.
Stack Trace:
[Win32Exception (0x80004005): Accesso negato]
[ExternalException (0x80004005): Cannot execute a program. The command being executed was "D:\Documenti\LavoriProgetti\MABE23\Grafoplast\Siglature\Siglature\bin\roslyn\csc.exe" /shared /keepalive:"900" /noconfig /fullpaths #"C:\Users\Discount Elettronica\AppData\Local\Temp\Temporary ASP.NET Files\vs\48e6051c\3d3b0e0b\xcsytsyz.cmdline".]
System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonated(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) +7083507
System.CodeDom.Compiler.Executor.ExecWaitWithCapture(SafeUserTokenHandle userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName, String trueCmdLine) +118
System.CodeDom.Compiler.Executor.ExecWaitWithCapture(IntPtr userToken, String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName) +85
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.Compile(CompilerParameters options, String compilerFullPath, String arguments, String& outputFile, Int32& nativeReturnValue) +274
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.FromFileBatch(CompilerParameters options, String[] fileNames) +682
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames) +186
System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile(CompilerParameters options, String[] fileNames) +25
System.Web.Compilation.AssemblyBuilder.Compile() +985
System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +10223794
System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +10113866
System.Web.Compilation.BuildManager.CompileGlobalAsax() +47
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +274
[HttpException (0x80004005): Cannot execute a program. The command being executed was "D:\Documenti\LavoriProgetti\MABE23\Grafoplast\Siglature\Siglature\bin\roslyn\csc.exe" /shared /keepalive:"900" /noconfig /fullpaths #"C:\Users\Discount Elettronica\AppData\Local\Temp\Temporary ASP.NET Files\vs\48e6051c\3d3b0e0b\xcsytsyz.cmdline".]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +65
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +458
System.Web.Compilation.BuildManager.CallAppInitializeMethod() +35
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +605
[HttpException (0x80004005): Cannot execute a program. The command being executed was "D:\Documenti\LavoriProgetti\MABE23\Grafoplast\Siglature\Siglature\bin\roslyn\csc.exe" /shared /keepalive:"900" /noconfig /fullpaths #"C:\Users\Discount Elettronica\AppData\Local\Temp\Temporary ASP.NET Files\vs\48e6051c\3d3b0e0b\xcsytsyz.cmdline".]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10080656
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +99
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +263

The pre-application start initialization method... Run WebActivatorEx.ActivationManager - Exception has been thrown by the target of an invocation

I keep getting this error, usually after changing the web.config on a running ASP.NET MVC azure web service app. It will run fine the first time but after it recompiles after changing the web.config this is usually appearing. I think it happens sometimes by just starting and stopping the web app. The only way I can make it go away is by publishing the app again from visual studio to azure.
Method not found: 'Microsoft.Practices.Unity.IUnityContainer MyProject.Core.ContainerManager.GetConfiguredContainer()'.
The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation
Source File: D:\MyProject-master\src\MyProject.Web\App_Start\UnityMvcActivator.cs Line: 73
StackTrace
MissingMethodException: Method not found:
'Microsoft.Practices.Unity.IUnityContainer
MyProject.Core.ContainerManager.GetConfiguredContainer()'.]
MyProject.Web.App_Start.UnityWebActivator.Start() in D:\MyProject-master\src\MyProject.Web\App_Start\UnityMvcActivator.cs:73
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +87
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +101
WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +73
WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +350
WebActivatorEx.ActivationManager.Run() +78
[InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +615
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
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): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10075124
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
This question seems very close to my issue but I haven't gotten this solution to work, there are two projects in my solution that use the RegisterTypes method:
interface and cannot be constructed on Unity config
These questions were related but not exactly this issue:
https://stackoverflow.com/questions/21078380/webactivatorex-dll-unity-bootstrap-is-firing-on-a-different-project
ActivationManager Exception during build process?
Unity Bootstrapper from NuGet is throwing error on App_Start
EDIT: If I merge the application into single assemblies during deployment the issue doesn't seem to happen anymore.
Install-Package Microsoft.AspNet.WebHelpers
For me, this turned out to be a problem where I was trying to inject something null into something that required a value -- didn't actually have anything to do with the error. For instance, I had a configuration setting that was missing, and it was trying to inject that missing setting somewhere. Once I realized which injection was going awry and fixed it, the error went away.

How can I catch exceptions generated in PreApplicationStartMethod?

I have an ASP MVC application that is hosted in a medium trust environment. This means that the only code that can execute is what is defined in the code permissions of the applications trust file. I am seeing that in the newer MVC applications a method ExecutePreAppStart() is called. This method then tries to execute LoadAllAssembliesFromAppDomainBinDirectory(). When this occurs a permissions error is generated
[PolicyException: Execution permission cannot be acquired.]
If the app has not been granted the explicit permission to execute that assembly. This is the expected outcome.
The issue here is that prior to PreApplicationStartMethod's implementation this error would bubble up to Application_Error in the global.asax. With PreApplicationStartMethod this is no longer the case. Since the PreApplicationStartMethod is not in code that I control, how can I trap for an error that may occur?
I have tried to create my own PreApplicationStartMethod to catch the exception but, it never reached the break point because the application is never fully loaded.
So, is there a way to catch errors for someone else's PreApplicationStartMethod? My end goal is to just be able to publish the exception.
Attempt at catching error:
[assembly: System.Web.PreApplicationStartMethod(typeof(mynamespace.Initializer), "Initialize")]
namespace mynamespace
{
public static class Initializer
{
public static void Initialize()
{
//Do something here to catch errors/bind event? but I never get this far at runtime
}
}
}
Stack Trace:
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
assemblyName, Boolean starDirective) +772
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
+259 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo
ai) +163
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection
compConfig) +230
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
+76 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String
preStartInitListPath, Boolean& isRefAssemblyLoaded) +343
System.Web.Compilation.BuildManager.ExecutePreAppStart() +176
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager
appManager, IApplicationHost appHost, IConfigMapPathFactory
configMapPathFactory, HostingEnvironmentParameters hostingParameters,
PolicyLevel policyLevel, Exception appDomainCreationException) +734
I am not sure why you need to run your application in a medium trust environment. The preapplicationstart method always worked for me and was able to catch exceptions when an error occurred. Usually, i would run an infinite while loop and execute operations every x amount of minutes. The only difference between your code and mine is that i usually define the Initializer class as public class without being static, i only set the initialize method as static.
This works for me even in azure web apps environment. So, make ways to elevate the trust level of your environment, but before test this on your development machine and make sure it works so you are sure that the error is thrown from server security policy.

C# .net web application with dll deployed from matlab

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.

Server Error in '/' Application. Unspecified error [ 5,sqlcese40.dll ]

Can somebody please help me?
After receiving an email from Google yesterday that advised a couple of links in my site (www.bigint.biz) were broken, I repaired them. Then I made a change to the sitemap.
Afterwards, when accessing the site I received the message: Server Error in '/' Application, Runtime Error, This tag should then have its "mode" attribute set to "Off".
So, I put the site exactly back how it was before the changes to the sitemap; but, I received
an internal server error 500 error message.
Then, I removed the whole site from the host provider and uploaded it again with the original version that worked fine with no joy.
Since, I have set the customErrors tag "mode" attribute to "Off" to get a more detailed error message - below:
Server Error in '/' Application.
Unspecified error [ 5,sqlcese40.dll ]
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.Data.SqlServerCe.SqlCeException: Unspecified error [ 5,sqlcese40.dll ]
Source Error: Line 2: #{ Line 3: Line 4: WebSecurity.InitializeDatabaseConnection("PhotoGallery", "UserProfile", "UserId", "Email", true);
Source File: \web-123win\winpackage22\XXX.COM\web\content_AppStart.cshtml Line: 4
Stack Trace:
[SqlCeException (0x80004005): Unspecified error [ 5,sqlcese40.dll ]]
System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent) +2182
System.Data.SqlServerCe.SqlCeConnection.Open() +47
WebMatrix.Data.Database.EnsureConnectionOpen() +44
WebMatrix.Data.<QueryInternal>d__0.MoveNext() +66
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +164
WebMatrix.Data.Database.QuerySingle(String commandText, Object[] args) +103
WebMatrix.WebData.DatabaseWrapper.QuerySingle(String commandText, Object[] parameters) +14
WebMatrix.WebData.SimpleMembershipProvider.CheckTableExists(IDatabase db, String tableName) +57
WebMatrix.WebData.SimpleMembershipProvider.CreateTablesIfNeeded() +49
WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider simpleMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables) +73
WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
ASP._Page__appstart_cshtml.Execute() in \\web-123win\winpackage22\bigint.biz\www.bigint.biz\web\content\_AppStart.cshtml:4
System.Web.WebPages.ApplicationStartPage.<ExecuteInternal>b__0() +65
System.Web.WebPages.ApplicationStartPage.<GetSafeExecuteStartPageThunk>b__3(Action action) +7
System.Web.WebPages.ApplicationStartPage.ExecuteInternal() +78
System.Web.WebPages.ApplicationStartPage.ExecuteStartPageInternal(HttpApplication application, Action`1 monitorFile, IVirtualPathFactory virtualPathFactory, IEnumerable`1 supportedExtensions) +184
System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application, Action`1 monitorFile, IVirtualPathFactory virtualPathFactory, IEnumerable`1 supportedExtensions) +30
[HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown.]
System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application, Action`1 monitorFile, IVirtualPathFactory virtualPathFactory, IEnumerable`1 supportedExtensions) +96
System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application) +170
System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application, Action`1 executeStartPage, EventHandler applicationStart) +126
System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application) +71
System.Web.WebPages.WebPageHttpModule.Init(HttpApplication application) +127
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
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): Exception of type 'System.Web.HttpException' was thrown.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874568
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
I noticed that when I was uploading the site again using FileZilla Client that 4 files failed to copy to the host; however, the same files are in the host bin directory as they did not originally delete for some reason - access rights I think. The files are:
web/content/bin/X86/sqlceer40ENN.dll
web/content/bin/X86/sqlceqp40.dll
web/content/bin/X86/sqlcese40.dll
web/content/bin/X86/sqlceme40.dll
Is this just coincidence, as the error message references one of these files?
Any help would be really appreciated.
Thank you.
EDIT - I have found a little more info here but I am struggling to understand how it can help me: http://www.blakepell.com/Blog/?p=227
I have got the site back up and running for the minute by removing: WebSecurity.InitializeDatabaseConnection("PhotoGallery", "UserProfile", "UserId", "Email", true);
But the issue still exists
I picked this problem up again today all this time later and found the solution with research. This is how I got there.
Replacing the dll files as recommended above didn't work before.
So, I started again by switching off my custom errors page which enabled me to get to get to the error code again.
I Googled the error and research pointed to a connection string issue or a folder permissions issue.
It's a good job I checked the permissions again because I previously set the folder permissions in the App_Data folder where the .sdf database was to enable read and write access using FileZilla but nothing actually changed. It seemed to work because changes appeared to cascade down through all the sub directories, but it didn't work.
The permissions were not actually changed using the FTP method although it looked like it had happened. I only found out because another post that I saw today suggested changing permissions through the control panel so I went back there to check them only to see a padlock by the folders.
So, I unlocked the folder permissions on App_Data correctly this time in the control panel file manager. I then un-commented the web security code below in the _AppStart page again and tried the site online and it worked.
Finally, I set custom errors back to on.
The moral is use the control panel and not FTP client to change folder permissions on hosted folders. I hope this helps someone else.

Categories

Resources