0
votes

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

1
What happens if you use it from managed code directly on those machines?SLaks
Is this really really your code? No strings, no DateTime that go around...xanatos
More likely, it is TypeInitializationException: TypeInitializationException uses the HRESULT COR_E_TYPEINITIALIZATION, that has the value 0x80131534 - ops, sorry, hadn't followed the link you posted, which has that infonoseratio
In general, COR_E_TYPEINITIALIZATION has an associated inner exception that really tells you what's going on. Have you tried to get that inner exception?Simon Mourier
You have a static constructor in your code that fails. It isn't visible in your snippet so we can't guess why it would fail. You cannot diagnose this error from unmanaged code, the InnerException is lost. Getting a repro so you can use a managed debugger is important. Check out the DebugDiag tool to get this remotely.Hans Passant

1 Answers

0
votes

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.