I'm attempting to expose our library via COM but seem to be fighting the tools more than the actual problem. Regardless of how I write my COM exposed class I get the warning: "XXX.dll does not contain any types that can be registered for COM interop" (marked project as Register for COM interop in the project properties). Even the simple class below (as the only class in an assembly that is signed and marked with ComVisible(false)) still warning persists:
[Guid("77699130-7D58-4d29-BE18-385871B000D1")]
[ComVisible(true)]
public interface IExample
{
string GetText();
void SetText(string text);
}
[Guid("F91E5EE1-D220-43b5-90D1-A48E81C478B7")]
[ComVisible(true)]
public class Example : IExample
{
private string m_text = "default text";
public string GetText()
{
return m_text;
}
public void SetText(string text)
{
m_text = text;
}
}
I've tried to run regasm from the command line on the output which gladly states "Types registered successfully". However, running with the /verbose switch no extra information is displayed (I seem to recall that it lists the name or perhaps just the number of registered types). Also tried running regasm with the /regfile switch to generate a regfile which generates this:
[HKEY_CLASSES_ROOT\ComExample.Example]
@="ComExample.Example"
[HKEY_CLASSES_ROOT\ComExample.Example\CLSID]
@="{F91E5EE1-D220-43B5-90D1-A48E81C478B7}"
[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}]
@="ComExample.Example"
[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="ComExample.Example"
"Assembly"="COMInteropTesting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8568e57f6b170d6c"
"RuntimeVersion"="v2.0.50727"
[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}\InprocServer32\1.0.0.0]
"Class"="ComExample.Example"
"Assembly"="COMInteropTesting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8568e57f6b170d6c"
"RuntimeVersion"="v2.0.50727"
[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}\ProgId]
@="ComExample.Example"
[HKEY_CLASSES_ROOT\CLSID\{F91E5EE1-D220-43B5-90D1-A48E81C478B7}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]
I'm no COM wizard of any measure but the registration looks valid to me. However, nothing seems to appear in the registry when running regasm on the assembly.
So my question is whether I'm missing something in my simple example to have the registration work, am I seeing false indications and is the registration actually correct and how can I better determine if the COM registration actually works
EDIT: Using the alterations suggested by Kev I could not avoid the warnings from VS2008 but I could actually get something registered in the registry using regasm directly (nothing in the registry from just the VS2008 integration).
I then tried to remove the simple class so I had an empty assembly. Running regasm on this did not report any sort of warnings, only "Types registered successfully". I see warnings like "RegAsm : warning RA0000 : No types were registered" when running RegAsm on some of my other assemblies which may be incorrectly exposed to COM. What is going on here, can I trust anything except the registry and what about the on/off warnings from regasm?