Creating an Instance of a COM object

I am modifying an ASP.NET application that uses a COM reference. The code creates an instance of the object the following way:

public static object COMCreateObject (string sProgID)
{
    try
    {
        Type oType = Type.GetTypeFromProgID(sProgID);
        if (oType != null)
        {
            return Activator.CreateInstance(oType);
        }
        else
        {
            throw new ApplicationException(
                 "Could not resolve ProgID for " + sProgID + 
                 " (Ensure the component is registered properly)");
        }
    }
    catch (Exception oExc)
    {
        PageInclude.ermHandleError(
                 "An error occured whilst creating " + sProgID +
                  " - " + oExc.ToString());
        throw oExc;
    }
}

The GetTypeFromProgId returns a valid Type of System._COMObject, however three of the properties (DeclaringMethod, GenericParameterAttributes and GenericParameterPosition) are returned with an InvalidOperationException ("Method may only be called on a Type for which Type.IsGenericParameter is true.").

So then calling the Activator.CreateInstance(oType) also fails (Creating an instance of the COM component with CLSID {508B4562-C89D-4DE9-4523-E6D507B3E3F2} from the IClassFactory failed due to the following error: 800aeb29.)

I'm unsure if the exceptions on the COM component are to blame (it's not a .NET component, so these fields may be missing?).

Any Ideas?

Answers


Need Your Help

How to Add/Remove views efficiently?

android view add removechild

I have an application which shows a list of items with details. When the user selects the item, the app shows the extra detail. I created two Views which extend RelativeLayout, one for listView and...

How to add data-attribute to the form tag in simple_form?

ruby-on-rails simple-form custom-data-attribute

I'm using garlic.js to validate my forms. Garlic.js recommends adding a data-attribute on the form tag.