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

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

Ignore exception made by COM object?

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :.NET Framework
Hi, I have third party COM object that I reference into my project. My project was simple console application which source code similar like code below: static void Main(string[] args) { try{ object _comObject = new ComObject(); // do some stuff with _comObject. while (Marshal.ReleaseComObject(_comObject) > 0) { } _comObject = null; } catch { } } I have put try..catch wrap around my Main function and also release COM resources that lock by object. But still COM throw an exception of Invalid Window Handle and made my application to stuck until user click the OK button on error message. Now the problem was why the try..catch not function, if there any exception throw by COM object it should catch by try..catch block. So this point the COM error raised after the try..catch block which mean the exception raised after my application send closed signal to OS. And the bad news is the COM exception is under my application and it made my application stuck (not closed) until the error dialog is closed. I don't want the exception to show up (made my application stuck), that's why I wrap my Main function with try..catch. I just need my application closed. Is there any way to unload the referenced COM library just before application closed (like DllUnload on Native programming), so I can wrap it with try..catch to ignore exception message that made by COM objec

View Complete Post

More Related Resource Links

Exception when login with sa in Object Explorer within MSSM Studio

Has anyone got an idea what might have caused the following. I have been able to login using SQL Server Authentication using the sa account with no problems within the object explorer. Not sure why I get an error (see below) when I try and login today. I can use the sa account via VS2010 IDE to connect to SQL Server, I can use sa account going via Database Engine Query within MSSM Studio, which uses the same SQL Server Authentication dialog. But when trying to connect via Object Explorer I get the following error. TITLE: Connect to Server ------------------------------ Cannot connect to --------- ------------------------------ ADDITIONAL INFORMATION: An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) ------------------------------ A severe error occurred on the current command.  The results, if any, should be discarded. A severe error occurred on the current command.  The results, if any, should be discarded. (Microsoft SQL Server, Error: 0) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=0&LinkId=20476 ------------------------------ BUTTONS: OK ------------------------------ The Event Log gives an error of: A user request from the session with SPID 51 generated a fatal exception. SQL Server is terminating this session. Contact Produc

Null Reference Exception was not handled by user Object Reference not set to instance of an object

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Security.Principal;using System.Data;using System.Data.SqlClient;using System.Windows;using System.Collections; public partial class Default2 : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {     }    private bool tableCopied = false;    private DataTable originalDataTable;     protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)    {         if (e.Row.RowType == DataControlRowType.DataRow)        {            //string sValue = e.Row.Cells[3].Text;             if (!tableCopied)            {                originalDataTable = ((System.Data.DataRowView)e.Row.DataItem).Row.Table.Copy();                ViewState["originalDataTable"] = originalDataTable;      &nbs

SharePoint 2010 : Creating SPSite object throws exception FileNotFoundException

We are in a process of upgrading from SharePoint 2007 to SharePoint 2010. I had written a Service which runs under default web site on the SharePoint web server. This service's app pool account uses the farm admin account. The service was working with no issue on SharePoint 2007 x64bit server. When I installed and run the same service on SharePoint 2010 x64bit box. I get the FileNotFoundException on SPSite site = new SPSite(http://myserver/sites/projects/project01); I have given the pool account running this server following rights: The Farm Admin The Site Collection Admin The Database Sys Admin The Local Admin No Luck. Thank you in advance for your help.

Exception when access to sharepoint by Client Object Model


Hello ,

  - I have a windows Application .

  - In the  Form  load , I write the following code to aceess sharepoint site :

      ClientContext clientContext = new ClientContext("URL");

     Web site = clientContext.Web;



    MessageBox.Show("Title: {0}", site.Title);

  The following exception happened when execute query :

         "The re

Exception Details: System.NullReferenceException: Object reference not set to an instance of an obje


Hi, i have a Problem, i made a ASP.NET Page with VS2010 and now i want to run it on a iis6 (windows server 2003) and i get the message:

Object reference not set to an instance of an object.

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.NullReferenceException: Object reference not set to an instance of an object.


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:


[NullReferenceException: Object reference not set to an instance of an object.]

   Bestellung.Bestellung.ImageButton1_Click(Object sender, ImageClickEventArgs e) in D:\foo.aspx.cs:71

   System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115

   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +120

   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10

   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13


BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception

BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)]

I have this error when I try to run a .net 2.0 web application. please help

CreateDocument method in CMIS Object Service raising the Constraint Violation Exception


HI All,

Below are the code snippet for rasing the above exception like  "The operation violates a Repository- or Object-level constraint defined in the CMIS domain model. "


ObjectServicePortClient objectService = new TestCMISWinApp.ObjectService.ObjectServicePortClient("BasicHttpBinding_IObjectServicePort");

objectService.ClientCredentials.Windows.AllowNtlm =



Programmatically Ignore Inherited Properties while iterating through object properties


Hi All,

I'm currently running a loop to iterate through an object properties:

Public Class Notification
    Inherits CommonProp
    Public Property NotificationID As Integer
    Public Property Message As String
    Public Property ReceivedDateTime As DateTime
End Class

However, when iterating through these properties, I do not want to iterate through the inherited CommonProp properties.

Is there anyway of ignoring the CommonProp properties?

Please kindly assist.

Thank you in advance.

Warmest Regards,


Unable to cast COM Object - Exception


Hi everyone,

Ive been trying to develop a COM Client application, but without success. My goal is to create an application that can open reports in Cognos Impromptu. Ive got Cognos Impromptu installed on this machine and im using Visual Studio 2008 to develop the client.

I created my project as a consoleapplication in Visual Studio. Next, I added the Impromptu Client Reference via Project > Add Reference > COM. All works fine till now, Visual Studio creates my COM Wrapper dll and adds it to the bin/debug folder.

But when I trry to run my program, it gives me the following Exception:

Unable to cast COM object of type 'ImpromptuClient.ImpromptuApplicationClass' to
 interface type 'ImpromptuClient.IAppAuto'. This operation failed because the Qu
eryInterface call on the COM component for the interface with IID '{2F835754-FB4
F-11CF-8E5F-00401C60350D}' failed due to the following error: No such interface
supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Press any key to continue . . .

The code I use is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.

Passing an exception object to a WCF service


I'm pretty new to WCF , as an experiment I was trying to create a WCF service wrapper over an exception handler class which is using the enterprise library underneath.

I created a simple class with one exception variable, which gets exposed as the data contract

when I try to pass the exception to the WCF service I get the following serialzation error

There was an error while trying to serialize parameter http://tempuri.org/:ex. The InnerException message was 'Type 'System.Collections.ListDictionaryInternal' with data contract name 'ArrayOfKeyValueOfanyTypeanyType:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.

I configured the app.config for the calling application by adding Syste.Exception as known type in the DataContractSerializer

        <add type="System.Exception, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <knownType type="System.Exception, mscorlib, Version=, Cult

Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.


Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

C# Object Oriented Programming

So far in C# Essentials we have looked at the basics of programming in C# such as variable types and flow control. Although it would be possible to write a functional program using these techniques, there is much more to becoming a proficient C# programmer. C# is, above all, an object oriented programming language and as such any C# programmer will be expected to create object-oriented applications using this language.

Object Oriented Programming

Four core concept of OOP Object Oriented Programming. 1.Inheritance, 2.Polymorphism, 3.Abstraction and 4.Encapsulation

Object-Oriented Programming Concepts

This is the first in a series of articles describing the use of object-oriented programming techniques as implemented by the C# programming language. This series follows the C# Fundamentals tutorial that beginners are advised to read first.

Ready made List Types provided by SharePoint

SharePoint provides some out of the box List Types. Some of the most used ready made list types that SharePoint provides currently are listed below:
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