Heap corruption in MVC application using IIS8 - asp.net-mvc-4

I have a MVC4 application, which loads some DLLs. Basically, the architecture of the MVC application is this: the app receives some jobs from the user, it calls the processing functions from dlls and in the end, emails the results to the user.
All dlls are compiled on 64bits, I use IIS8 on 64 bits, on Windows Server 2012R2 and VS2013.
When I run/deploy the application, its behaviour is:
Scenario1: Run from Visual Studio 2013 in VS2013 included web server (IIS Express) in Debug/Release Mode => works fine
Scenario2: Run from Visual Studio 2013 deployed in local full IIS8 in Release Mode => works fine
Scenario3: Deployed in Release Mode in local full IIS8 and run directly from browser, without having open VS2013 => IIS crashes with An unhandled win32 exception occurred in w3wp.exe.The Just-ln-Time debugger was launched without necessary security permissions. To debug this process, the Just-ln-Time debugger must be run as an Administrator. When I open the debugger, the error is: A heap has been corrupted.
In event viewer, the logs are:
Faulting application name: w3wp.exe, version: 8.5.9600.16384, time stamp: 0x5215df96
Faulting module name: ntdll.dll, version: 6.3.9600.18821, time stamp: 0x59ba86db
Exception code: 0xc0000374
I know that exception code 0xc0000374 comes from Heap corruption.
I debugged IIS using DebugDiag and Application Verifier, with Full PageHeap flags activated.
The relevant part of the stack for the crashing thread is:
.NET Call Stack
mscorlib_ni!DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr)+68
[[InlinedCallFrame] (Microsoft.Win32.Win32Native.LocalFree)] Microsoft.Win32.Win32Native.LocalFree(IntPtr)
mscorlib_ni!System.Runtime.InteropServices.Marshal.FreeHGlobal(IntPtr)+2d
Species_DLL.Class1.Species_MetaModel()+b955
rIAMTestMVC4.Impressions.SpeciesUtil.use_Species_Integrated(Int32)+1efd
Full Call Stack
vrfcore!VerifierStopMessageEx+6f4
vrfcore!VfCoreRedirectedStopMessage+90
verifier!VerifierStopMessage+a0
verifier!AVrfpDphReportCorruptedBlock+2a7
verifier!AVrfpDphCheckNormalHeapBlock+c8
verifier!AVrfpDphNormalHeapFree+27
verifier!AVrfDebugPageHeapFree+af
ntdll!RtlDebugFreeHeap+47
ntdll!RtlpFreeHeap+74c85
ntdll!RtlFreeHeap+368
vrfcore!VfCoreRtlFreeHeap+1e
KERNELBASE!LocalFree+2e
mscorlib_ni!DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr)+68
[[InlinedCallFrame] (Microsoft.Win32.Win32Native.LocalFree)] Microsoft.Win32.Win32Native.LocalFree(IntPtr)
mscorlib_ni!System.Runtime.InteropServices.Marshal.FreeHGlobal(IntPtr)+2d
Species_DLL.Class1.Species_MetaModel()+b955
rIAMTestMVC4.Impressions.SpeciesUtil.use_Species_Integrated(Int32)+1efd
Are there any differences between Scenario2 and Scenario3? Is there any heap protection that is done by VS?
I also run the same scenarios on Windows7 with IIS7 and works fine on all three.
I don't have access to DLL code, but as I mentioned, the same code runs perfectly on IIS7/Windows7 and on IIS8 from Visual Studio.
LE: There are two functions shown in call stack:
rIAMTestMVC4.Impressions.SpeciesUtil.use_Species_Integrated => This function is from MVC controller, which calls one dll
Species_DLL.Class1.Species_MetaModel => This function is from dll, called by previous function.
How can I resolve the problem of scenario3? What are the differences between these scenarios?
Thank you,

I had similar issues but i resolved mine by changing the project build to x86 to compensate for 32 bits.

Did you run VS2013 as an administrator? if so, then this is what prevented the error from happening with VS, and happens with IIS only.
It looks like the IIS application pool is having a problem reaching those DLLs, and this problem didn't occur with VS2013.
Update: Just add the permission to the pool itself to access the folder:
Select the folder that has your DLLs Right click and select
"Properties"
Select the "Security" tab Click the "Edit" and then
"Add" button
Click the "Locations" button and make sure you select the local
machine. (Not the Windows domain if the server belongs to one.)
Enter IIS AppPool\DefaultAppPool in the "Enter the object
names to select:" text box. (Don't forget to change "DefaultAppPool"
here to whatever you named your application pool.)
note: steps are copied with some changes from here.
To know or change the application pool that runs your application: when you open IIS manager and select your application from the tree on the left, find it in Advanced Settings down the Actions Pane on your right.
To change the identity of the pool , you'll find them under the machine in the tree on your left.
Check this article on how to specify the identity of the application pool.

Related

Disable Webview in Console Application

I'm building a NET6 local multiplatform console application as shown:
But even with a single "Hello World" and without any reference or package being called, everytime I debug-execute the code a lot of "Webview2" is loaded on the Windows processes.
Worst: even stoping the debug session, these modules remains active and they seems to close only if i manually finalize them in Task Manager
Since the application is not an ASP.NET nor a Winform application, why Visual Studio 2022 loads Webview2?
Can I disable it?

Attaching to process over SSH with VS2019 and ASP.NET core not working

I am running an asp.net docker container remotely. I have enabled SSH, mapped the port and also installed VSDBG in the container.
In visual studio I am able to attach to process over SSH. I choose my project dll file. There are no error alerts and it appears to be debugging but on every breakpoint there is this message:
The breakpoint will not currently be hit. The breakpoint is pending and will be resolved when debugging starts.
Also if I open modules window there is no entries.
What is going on? Why is remoe debugging not working?
There are usually two reasons:
1. project publication made with release instead of debug configuration
2. the projects are not consistent. There is a difference between the project on the local machine and the server.

WCF Common Language Runtime detected an invalid program on windows XP

I have a windows forms application running on .NET 4 that communicates with a WCF web service. The application is compiled to run with X86 as the platform target. The application was deployed on a network of hundreds of computers, and there are only a couple, that happen to have a windows XP version installed (Microsoft Windows Embedded POSReady 2009, service pack 3 to be more precise) that launch the error "Common Language Runtime detected an invalid program" upon calling the constructor of the WCF proxy class object. In order to isolate the problem, I created a small console application that the only thing it does is to call the constructor of the web service proxy class, like:
ItesWebServiceClient m_webService = new ItesWebServiceClient("BasicHttpBinding_IItesWebService");
And the exception is then thrown:
stacktrace output
The same console app runs on all other computers, even the ones with the same windows version.
We've already tried repairing and re-installing .Net framework on the failing computers but so far nothing fixes it. I also used the PEVerify tool to validate MSIL and ran the code in debug mode (no optimizations) as suggested on other posts.
Is there something I'm missing? could there be a key .Net framework component or hot fix that needs to be installed?
Thanks
Ok it turns out that the person who was re-installing the .Net framework on the machines was always installing the .net client profile version. Uninstalling that version and installing the full .net 4 version solved it.

32 bit WCF on Azure - enable32BitAppOnWin64 not working

I am trying to get a 32 bit WCF library to run on Azure. I've read several posts, like this: 32-bit legacy COM DLLs on Windows Azure, saying that they successfully force IIS to load a 32 bit application.
I added the startup batch file, which also registers a COM, and I see that it is run successfully. The COM is registered and the setting is set to true in IIS manager.
Yet the role keeps recycling and in the Event Viewer I see:
WaIISHost
Role entrypoint could not be created: System.BadImageFormatException: Could not load file or assembly 'file:///E:\approot\bin\wcfAzureWrapperStoryMapping.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///E:\approot\bin\wcfAzureWrapperStoryMapping.dll'
I tried changing the OS from Windows 2008 to Windows 2012, no effect. What is going on?
And the funny part, the base folder contains two folders, x64 and x86. So it's like there is a provision for 32 bit. How do I force these guys to cooperate? I was thinking to rename the folders from the batch file but it's probably not going to work...
UPDATE: funny enough, Task Manager shows IISConfigurator as 32 bit! What's going on, I wonder?

Dll not registering for all users

Hopefully this is placed in the right area, but I seem to be having an issue with a registered dll.
Our main application is written with Power Builder Version 11, and through various objects, we are able to call registered C# .dll's
The C# .dll is created in Visual Studio 2008 and is installed via an installer that someone else in the building made. When a user runs the installer, they are given the option to register it for everyone or 'Just Me'
The .dll is installed successfully and the user that did the install is able to run the Power Builder application and call the functions inside the .dll.
The issue that arises is that any other user that runs the Power Builder application is greeted with a message box that says: Unable to connect to: [my dll].
I tried to re-register the .dll (using Regasm) but that doesn't work. I have confirmed that the folder is in the PATH System Variable.
The only solution I found was to uninstall the .dll from the Control Panel and re-install it from scratch. But, the same issue arise after the install.
What could the issue be? I'm starting to think that it has to be a rights issue but I can't be 100% positive.