尝试将包注册到 COM
Trying to Register package to COM
我正在使用 regasm
将我的 .dll
(派生自下面的 .cs
)注册到 Windows COM。它 returns 一个警告,指出没有要注册的类型。我认为这是因为并非我所有的依赖项都有默认构造函数;但是 post-change 我遇到了同样的问题。
我的问题是我是否需要在 类 中定义任何内容,明确说明它将用作 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();
}
现在,从我定义的对象模型调用的方法和所有这些 类 也有默认构造函数。
如果您需要任何更多信息,请告诉我,我省略了这些方法,因为它们有 20 多种。谢谢
我觉得是你的问题class。根据 MSDN 中的示例 COM Class。
Class 必须遵循一些规则才能使 COM 可见:
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://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/interop/example-com-class
我正在使用 regasm
将我的 .dll
(派生自下面的 .cs
)注册到 Windows COM。它 returns 一个警告,指出没有要注册的类型。我认为这是因为并非我所有的依赖项都有默认构造函数;但是 post-change 我遇到了同样的问题。
我的问题是我是否需要在 类 中定义任何内容,明确说明它将用作 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();
}
现在,从我定义的对象模型调用的方法和所有这些 类 也有默认构造函数。 如果您需要任何更多信息,请告诉我,我省略了这些方法,因为它们有 20 多种。谢谢
我觉得是你的问题class。根据 MSDN 中的示例 COM Class。 Class 必须遵循一些规则才能使 COM 可见:
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://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/interop/example-com-class