1

I am writing an application to interface with COM components and I have run into a problem when working with the Excel.Application component while running my application in the Visual Studio 10 IDE. I am getting a fatal Out of Memory error. Everything runs fine if I just run the EXE, but this severely limits my debugging capabilities. All other COM components I have accessed this way work fine, including both home-grown and commercially available components.

Here is a console app that demonstrates this crash. I have removed all error handling for simplicity's sake. Putting a try/catch block around the offending code does not help. This project requires a reference to the CustomMarshalers.dll.

    class Program
    {
        static void Main(string[] args)
        {
            InstantiateCOMComponent("Excel.Application");
        }

        private static void InstantiateCOMComponent(string name)
        {
        Type typeInfo = Type.GetTypeFromProgID(name);
        object instance = Activator.CreateInstance(typeInfo);
        IDispatch dispatch = instance as IDispatch;

        // NOTE: THIS CALL FAILS WITH Excel.Application in the IDE
        // but succeeds at run-time!! (Out of Memory fatal error)
        Type comTypeInfo;
        dispatch.GetTypeInfo(0, 0, out comTypeInfo);
        }
    }

 [ComImport, 
  Guid("00020400-0000-0000-C000-000000000046"),
  InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDispatch
{
    void Reserved();
    [PreserveSig]
    int GetTypeInfo(uint nInfo, int lcid,
       [MarshalAs(
          UnmanagedType.CustomMarshaler,
          MarshalTypeRef = typeof(TypeToTypeInfoMarshaler))]
       out System.Type typeInfo);
}

I am thinking the problem is simply due to Excel's size.

acordner
  • 197
  • 1
  • 3
  • 8
  • My project has some similar goals on codeplex (ActiveXObject added to .NET JS compiler). Some of it is already in Codeplex (but doesn't have a complete tool set for reflecting COM types [yet]). If that sounds interesting, you can try copying what it does from here: http://jurascript.codeplex.com/SourceControl/changeset/view/14725#284671 My IDispatch interface declaration is here: http://jurascript.codeplex.com/SourceControl/changeset/view/14725#284670 If it works for you perhaps I can make it in answer format. It's very much WIP and I have more to offer on my machine at home. – aikeru Jun 18 '12 at 16:14
  • There's also a blog site where I got a lot of my info, but I can't think of it and have it bookmarked back home ... – aikeru Jun 18 '12 at 16:16

0 Answers0