尝试将包注册到COM

时间:2017-07-28 10:59:38

标签: c# .net dll regasm

我使用regasm将我的.dll(从.cs派生)注册到Windows COM。它返回一个警告,指出没有要注册的类型。我认为这是因为并非所有的依赖都有默认的构造函数;但是改变后我得到了同样的问题。 我的问题是我是否需要在我的类中定义任何明确声明它将用作COM对象的东西?如果没有,我哪里错了?

这是其中一个类(主要类)的最小子集:

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();
}

现在,方法从我定义的Object-Model调用,所有这些类也都有默认的构造函数。 您需要的任何更多信息请告诉我,我遗漏了方法,因为有超过20个。感谢。

1 个答案:

答案 0 :(得分:1)

我认为问题出在你的课堂上。根据MSDN的示例COM类。 类必须遵循一些规则才能看到COM:

  

将Visual C#对象暴露给COM需要声明一个类接口,如果需要则声明一个事件接口,以及类本身。类成员必须遵循这些规则才能对COM可见:+   该课程必须公开。

     
      
  • 属性,方法和事件必须公开。
  •   
  • 必须在类接口上声明属性和方法。
  •   
  • 事件必须在事件界面中声明。
  •   
     

类中未在这些接口中声明的其他公共成员对COM不可见,但对其他.NET Framework对象可见。

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