.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Interop: Get Seamless .NET Exception Logging From COM Clients Without Modifying Your Code

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

Using .NET objects from ASP can help you gain experience with the .NET Framework before migrating to ASP.NET. Your ASP pages will make use of the new .NET components through COM-callable wrappers (CCW). But how will you handle exceptions? This article fills you in.

Matt Adamson

MSDN Magazine January 2005

View Complete Post

More Related Resource Links

OutOfMemory Exception on 64 bit machines (Interop Problem)

Hello Our application needs to display the printer settings dialog. This works fine in 32bit windows systems, but results in a System.OutOfMemoryException at System.Runtime.InteropServices.Marshal.AllocHGlobal(IntPtr cb) when it is running under 64bit (Windows 2008 Server). The problem can easily be reproduced in a winform app. You need to set the platform target to x86 to experience the problem.Unfortuantely, our application needs to be built fox x86 for other reasons. Any ideas why this happens? Kind Regards Mat Source Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Printing; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication8 {     public partial class Form1 : Form     {         [DllImport("kernel32.dll")]         static extern IntPtr GlobalLock(IntPtr hMem);         [DllImport("kernel32.dll")]         [return: MarshalAs(UnmanagedType.Bool)]         static extern bool GlobalUnlock(IntPtr hMem);         [DllImport("kernel32.dll")]   &n

Release mode application throws Break instruction exception - code 80000003 when running in WinDbg


Here is the initial output of my program after running it from WinDbg:

CommandLine: "C:\Documents and Settings\Administrator\My Documents\Work\QMI_Test_Tool\QMI_UT_Source\Release\QMI Validation Tool.exe"
Symbol search path is: SRV*c:\symbols*http://msdl.microsoft.com/download/symbols
Executable search path is: 
ModLoad: 00400000 0048f000  QMI Validation Tool.exe
ModLoad: 7c900000 7c9b2000  ntdll.dll
ModLoad: 79000000 7904a000  C:\WINDOWS\system32\mscoree.dll
ModLoad: 7c800000 7c8f6000  C:\WINDOWS\system32\KERNEL32.dll
ModLoad: 77dd0000 77e6b000  C:\WINDOWS\system32\advapi32.dll
ModLoad: 77e70000 77f03000  C:\WINDOWS\system32\RPCRT4.dll
ModLoad: 77fe0000 77ff1000  C:\WINDOWS\system32\Secur32.dll
ModLoad: 7c420000 7c4a7000  C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_e6967989\MSVCP80.dll
ModLoad: 78130000 781cb000  C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_e6967989\MSVCR80.dll
ModLoad: 77c10000 77c68000  C:\WINDOWS\system32\msvcrt.dll
ModLoad: 7c9c0000 7d1d7000  C:\WINDOWS\system32\SHELL32.dll
ModLoad: 77f10000 77f59000  C:\WINDOWS\system32\GDI32.dll
ModLoad: 7e410000 7e4a1000  C:\WINDOWS\system32\USER32.dll
ModLoad: 77f60000 77fd6000  C:\WINDOWS\system32\SHLWAPI.dll
ModLoad: 7c4c0000 7c53d000  C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_e6967989\m

KERNELBASE.dll, version: 6.1.7600.16385, time stamp: 0x4a5bdbdf Exception code: 0xe0434f4d Fault off


Hi all just am getting this error with KernelBase.dll, what's happening at my application end is that I am using .NET Framework to determine if network connectivity is available, raise an event from underlying dll to inform application when network connectivity is established, or network connectivity is unavailable. Nothing really special here just using standard stuff out of .Net framework here.  Have seen similar incidents with KERNELBASE.dll reported, but no one is really giving out any info on what exception 0xe0434f4d is a code for.  Knowing what the execption would be, would allow me to find a quick workaround to the problem. BizTalk seems to have similar issue with KERNELBASE.dll. 


Additional info that may help is that I am running the .NET application on a Windows 7 machine with less than 100MB of storage space, well below the recommended minimum of 300mb, but am testing the .NET application through it's paces now. It should work if Windows 7 is working.

Below is the extract taken from the Windows application log:-


No return from unmanaged code, methods to catch exception?


I am developing a c# application that needs to calls functions from a c header file. I use

[System.Runtime.InteropServices.DllImport("xxx.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true,SetLastError=true)]
        public static extern Byte xxxx(IntPtr hResourceContext, ushort xxxx, ref structa aaa,ref Result_struct Result, Byte b);

to import the dll method. When I call this method in C#, the application simply exits without throwing an exception or error. I've used similar approach for other methods from the same dll which involves passing nested structs as parameter and they work fine. I would like to know how I can debug the code/ catch errors/exceptions from the unmanaged code.

I tried to include the SetLastError=true during DllImport but it does not help.


COM Interop exception in MSI package


I have migrated the VB code to VB.net and Kept the Interop dlls as it is. Withe that .Net code I have created the .msi Package and installed the application on my desktop. But when I tried to run the application it's throwing error as:

Error: An error occured in creating the form. See Exception.InnerException for details. The Error is: Could not load file or assembly 'AxInterop.ComctlLib, Version=, Culture=neutral, PublicKeyToken=null' or one of it's dependencies. The System cannot find the file specified.

Please help to run the application in a success way...




Annoying SQL exception, probably due to some OO/linq code done wrong


I started working on this "already started" project, and I'm having a really annoying error when trying to execute some interactions with SQL Server 2008:

The server failed to resume the transaction

One of these errors I get in this specific method call:

The aspx.cs Call:


busProcesso openProcess = new busProcesso(pProcessoId);
        if (openProcess.GetDocument() == null)
            //Irrelevant code.
    catch{ //... }

The Business class (relevant part):
public class busProcesso : IbusProcesso
        public Processo vProcesso { get; set; }

        RENDBDataContext db;

        public busProcesso()
            vProcesso = new Processo();

        public busProcesso(decimal pProcessoId)
            db = new RENDBDataContext();
                 vProcesso = db.Processos.SingleOrDefault(x => x.Id == pProcessoId);
            catch (Exception ex)
                throw new Exception(ex.Message, ex);

        public string GetDocument()

WCF Exception when 50 clients concurrently make a call. Bug?


We've ran into a rather strange issue in WCF, that has to do with concurrently making a call to a WCF service.    We first thought we were hitting a throttle limit, however we have all the throttles maxed.  Furthermore, when we run a verbose trace there isn't anything indicating an issue with a throttle, all we get is the rather unhelpful exception (which must be a bucket in WCF).


"The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.4383964'."


I have a reproducable app that can make this happen, is anyone at Microsoft interested?  If so, where should I send it.

Interop problem: VB6 COM code functions incorrectly when called from .net code.


I have found recently with some machines or some user accounts that calling some VB6 code from .Net fails to execute properly.
I have two examples:

  1. I have this simple VB6 dll, called by VB.Net code, that calls another simple VB6 dll using createobject.  The second object displays a form modally with progress bars, runs queries against a SQL server database to create and fill a table, and then closes (unload) that progress form and returns the table name.  The first object then takes this data to do additional processing on the SQL server and returns a SELECT statement to the object that called it. 
    For most people this works correctly, however for two users on a terminal server it fails to run correctly.  What it does is not close the form, however all of the updates to the database in both dlls are run according to SQL profiler.  The .Net process that called it never seems to get a return value from the COM dll for those 2 users only.  I even tried to recreate the user's profile, but it did not help.  Note that the .Net code calls the first VB6 dll using CreateObject as well.
    The strangest thing about this is what occurred when I added MsgBox calls to try to determine what was wrong with the progress form.  I added one immediately after the form's status bas was updated to "Finished

List Item Update Exception from HRESULT: 0x80040E2F Unexpected query execution failure, error code 3


A thread somewhat simliar to this has been posted before as well, but i just wanted to detail out the issue and circumstances

We have a list with 53 columns and 2600 items(and growing. I know its rubbish, but thats the way it is at the moment). The list was created using SharePoint GUI  on a test server, saved as a template with data, and was then imported to the production environment. I can post the list columns and type if it helps.

Every one in a while, on updating an item, SharePoint throws up the very not so helpful error page with "Exception from HRESULT: 0x80040E2F".

We looked into the logs and found that for each suc error, there was a Database level error logged as well.

The error starts with Unexpected query execution failure, error code 3621. Additional error information from SQL Server is included below. "The statement has been terminated." Query text (if available): "BEGIN TRAN;DECLARE... and runs for many lines so i wont post the entire blurb here.

Each time, the item update is successful, despite this error. The list also has an Item Updated event handler attached to it. Every time the update error occurs, the event handler does not seem to be firing.

Anybody can shed light on what is happening. We have tried exporting the list template to another site and everything seemed to work

Code 3005: An Unhandled Exception has Occurred (ASP.NET 2.0.50727.0)



I am receiving the following error on one of the web servers I support:

Event Type: Warning

Event Source: ASP.NET 2.0.50727.0

Event Category: Web Event

Event ID: 1309

Date: 11/3/2010

Time: 10:59:40 AM

User: N/A

Computer: <removed>


Event Code: 3005

Event Message: An unhandled exception has occurred.

Event time: 11/3/2010 10:59:40 AM

Event Time (UTC): 11/3/2010 10:59:40 AM

Event ID: 0c748a133ea846d99fa35a71b76623e6

Event sequence: 3

Event occurrence: 1

Event detail code: 0

Application Information:

Application domain: /LM/W3SVC/1/Root/<removed>

Trust Level: Full

Application Virtual Path: <removed>

Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust



I want to pass parameter to Silverlight Control deployed as a Webpart.For this i used WebpartStorageAttribute for getting the values while configuring the Webpart.

It deployed Successfully but when i try to add webpart its raising the following error

Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: Could not load type 'Microsoft.SharePoint.WebPartPages.WebPartStorageAttribute' from assembly 'Microsoft.SharePoint, Version=14.900.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.

Thanks in Advance

Exception with Microsoft.Office.Interop.Outlook method Members.Add



I am using Visual Studio 2.0 and Microsoft Outlook 11.0 Object Library in a windows application.

I am trying to create a distribution list of contacts in outlook and add members to it. Creating a contact or a distribution list works fine, but when I try to user Members.Add method I get the following exception: "An attempt was made to open an unsupported property."

I am using this post as example code :http://support.microsoft.com/kb/178787

This is the detailed exception:

System.Runtime.InteropServices.COMException was unhandled
  Message="An attempt was made to open an unsupported property."
  Source="Microsoft Office Outlook"
       at Microsoft.Office.Interop.Outlook.AddressEntries.Add(String Type, Object Name, Object Address)


I couldn't find any info about this on the web, I would be happy to get some support.



Logging Exception details using IErrorHandler



Along with exception I want to log extra details from reqest message (like request guiId, identifiying the request for which this exception belongs). but HandleError is called on  a separate Thread and I am not getting the reqest message from the OperationContext.current.

Can't I log extra details in IErroHandler? I think there should be  a way to do this, as it is a very basic requirement to log extra details in addition to Exception object (otherwise how will I track which exception belongs to which of the request).



issues with Microsoft.Office.Interop.Excel in asp.net throwing Exception from HRESULT: 0x800A03EC


i m using Microsoft.Office.Interop.Excel in asp.net for Excel file as anEmail attachment .

i get the data and write to Excel but when i try to save like:

oWB.SaveAs(strCurrentDir +strFile, Microsoft.Office.Interop.Excel.


XlFileFormat.xlWorkbookNormal, null,

D3DImage stops updating it's front buffer without exception or error code on XP

I encountered this very strange behaviour of D3DImage, which is only reproducible on XP. The following bug? doesn't seem to occur on any other OS.

The D3DImage has a correct backbuffer set up. I checked the bytes of the backbuffer, and they are updated. (Also updates are visible on other OS.) Still the following code doesn't appear to update the front buffer, without any warning whatsoever.

                    new Int32Rect(

Code Optimized Web Development Profile (VS 2010 and .NET 4.0 Series)

When you first run VS 2010 it prompts you to select an IDE profile to use. The profile you select will configure how tool windows are displayed/docked in the IDE by default and set the default keyboard shortcuts. You can then customize any of these settings by using the Tools->Options menu within the IDE and then override/change them. You can also later reset your profile and pick a different one by choosing the Tools->Import and Export Settings menu command.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend