C# com interopt failure on american machines

0

I've been working on a simple dll library that is com-accessible so that other softwares can use our library (from any managed or unmanaged language).

Creating a com-accessible dll is fairy easy:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace MyNamespace
{
    //This interface defines purely the events. DotNetEventSender should implement this interface with the ComSourceInterfaces() attribute
    //to become an Event Source.
    [ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface COMEventsInterface
    {
        //[DispId(1)]
        // we don't have any events, but if needed, include them here

    }

    [ComVisible(true)]
    public interface ICOM
    {
        //Methods
        int Sum(int[] intsToSum)
    }

//Identifies this interfaces that are exposed as COM event sources for the attributed class.
    [ComSourceInterfaces(typeof(COMEventsInterface))]
    //Tells the compiler not to generate an interface automatically and that we are implementing our own interface (IDotNetEventSender)
    [ClassInterface(ClassInterfaceType.None)]
    [ComVisible(true)]
    public class COM : ICOM
    {

        // Methods
        public int Sum(int[] intsToSum)
        {
            int sum = 0;
            foreach ( int i in intsToSum )
            {
                sum += i;
            }
            return sum;
        }
    }
}

In debug mode in would now mark this project to register for com-interop via Project>Properties>Build>Register for com interop.

In release mode I have an installer which marks the primary output from my project as "vsdrpCOM".

And this works great, in most cases. But somehow on some machines (all American) this won't work. The com class gets registered but I constantly get the error: HRESULT 0x80131534, which is actually already descibed here on SO: Error when instantiating .NET/COM interop class via classic ASP

But realy, I don't see any solution here. I've checked for user rights, domain rights, ...

EDIT: The constructor of my real class does this one thing: (I've added the try catch because I found on SO that this is an error in the constructor...)

// Constructor
    public COM()
    {
        try
        {
            // register itself with the application
            MyApplication.COMObject = this;
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

It just registers itself to a static class' property COMObject:

private static COM _comObject;
public static COM COMObject
        {
            get
            {
                return _comObject;
            }
            set
            {
                _comObject = value;
            }
        }

Although, the COM class doesn't really need to register itself, i've done this for future use if I would like to trigger Events

c#
dll
com
asked on Stack Overflow Aug 19, 2013 by KenGey • edited May 23, 2017 by Community

1 Answer

0

Well, I happens to be that i have faulty declared a DateTime in one of my declarations of a static class... private DateTime myDateTime = Convert.ToDateTime("15/09/2013 12:00:00");

And ofcourse, on a EU system, this will work, but on an American (or even others) this gives an error because there is no 15th month...

This gets triggered even before the constructor of my com-accessible class and that's why the error couldn't be handled.

Dumb mistake, but proves that sometimes errors look very complex while they are very simple.

answered on Stack Overflow Aug 23, 2013 by KenGey

User contributions licensed under CC BY-SA 3.0