Search code examples
c#.netdllregasm

Trying to Register package to COM


I'm using regasm to register my .dll (derived from .cs below) to Windows COM. It returns a Warning that states that there was No Type To Be Registered. I thought this was because not all of my dependencies had default constructors; but post-change I get the same problem. My question is do I need to define anything in my classes explicitly stating that it will be used as a COM object? If not, where am I going wrong?

Here is a minimal subset of one of the classes (the main one):

public class AlmREST
{
    //State:
    private String server;
    private String domain;
    private String project;
    private String username;
    private String password;
    //
    private String system;
    //
    private String assignedTo;
    private String responsible;
    private String phase;
    private String testEnv;
    //
    private String sID;

    //client/session state: 
    private HttpClient client;
    private CookieContainer cookieJar;
    private HttpRequestHeaders mainHeaders;
    //
    private Cookie LWSSOkey;
    private Cookie QCsession;
    private Cookie sessionKey;
    private Cookie XSRFtoken;
    private Cookie almUser;

    //DEFAULT\/
    public AlmREST()
    {
        sID = Environment.MachineName;
    }

    public AlmREST(String[] authent, String sys, String[] tester)
    {
        server = authent[0];
        domain = authent[1];
        project = authent[2];
        username = authent[3];
        password = authent[4];

        system = sys;

        assignedTo = tester[0];
        phase = tester[1];
        testEnv = tester[2];

        responsible = username;
        schrodID = Environment.MachineName;

        startUp();
    }

    //For COM/JNI
    public void setup(string s, string d, string pr, string u, string p)
    {
        server = s;
        domain = d;
        project = pr;
        username = u;
        password = p;
        startUp();
    }

    private void startUp()
    {
        //@TODO(later): find out how to derive SSL-cert for HTTPS
        //handler.Credentials = getSSLCert();
        cookieJar = new CookieContainer();

        HttpClientHandler handler = new HttpClientHandler();
        handler.CookieContainer = cookieJar;
        client = new HttpClient(handler);
        client.BaseAddress = new Uri(server);
        mainHeaders = client.DefaultRequestHeaders;
        //erase headers
        mainHeaders.Clear();
    }

    //Lots of methods (omitted)

    //Delegates\/ could they be a problem?
    internal delegate Entity Factory(String entitiesType, params KeyValuePair<String, object>[] definition);
    internal delegate Entities SubTypeQuery(String subTypes, params KeyValuePair<String, object>[] values);
    internal delegate Entity Extractor(String field, object value, Entities entities);
    internal delegate bool LockSelf(String id, String entitiesType);
    internal delegate bool UnlockSelf(String id, String entitiesType);
    internal delegate bool DeleteSelf(String id, String entitesType);
    internal delegate bool AmmendProperty(String id, String entitiesType, params KeyValuePair<String, object>[] ammendments);
    internal delegate List<Delegate> Inheritor();
}

Now, the methods call from an Object-Model I defined and ALL of those classes have default constructors too. Any more information you need please let me know, I left out the methods because there are over 20 of them. Thanks.


Solution

  • I think the problem is in you class. According to the Example COM Class from MSDN. Class must follow some rules to be COM visible:

    Exposing Visual C# objects to COM requires declaring a class interface, an events interface if it is required, and the class itself. Class members must follow these rules to be visible to COM: + The class must be public.

    • Properties, methods, and events must be public.
    • Properties and methods must be declared on the class interface.
    • Events must be declared in the event interface.

    Other public members in the class that are not declared in these interfaces will not be visible to COM, but they will be visible to other .NET Framework objects.

    https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/interop/example-com-class