[C# COM development] output by Regasm
Hello everyone,
I am debugging and learning MSDN C# COM server sample.
http://msdn2.microsoft.com/en-us/library/aa645738(vs.71).aspx
I am using Regasm to generate Windows Registry scripts, here it is,
I can understand that for C# COM Server, since it is managed code, it will use mscoree.dll as the entry point. But I can not see anything related to the real codebase dll (CSharpServer.dll), which contains the real implementation of coclass and interface definition.
I am wondering how mscoree.dll find and invoke real implementation in CSharpServer.dll?
REGEDIT4
[HKEY_CLASSES_ROOT\CSharpServer.InterfaceImplementation]
@="CSharpServer.InterfaceImplementation"
[HKEY_CLASSES_ROOT\CSharpServer.InterfaceImplementation\CLSID]
@="{C6659361-1625-4746-931C-36014B146679}"
[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}]
@="CSharpServer.InterfaceImplementation"
[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="CSharpServer.InterfaceImplementation"
"Assembly"="CSharpServer, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\InprocServer32\0.0.0.0]
"Class"="CSharpServer.InterfaceImplementation"
"Assembly"="CSharpServer, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v2.0.50727"
[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\ProgId]
@="CSharpServer.InterfaceImplementation"
[HKEY_CLASSES_ROOT\CLSID\{C6659361-1625-4746-931C-36014B146679}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]
thanks in advance,
George
[1842 byte] By [
George2] at [2007-11-20 9:24:40]

# 1 Re: [C# COM development] output by Regasm
In COM, you are registering a class name in the registry. Then, you can create an instance of that class in your code.
The CLR will not know where to load the class if it isn't registered. But, since you probably registered the (COM) class, the CLR will know where to find it (most probably in the GAC).
# 2 Re: [C# COM development] output by Regasm
Thanks Tischnoetentoet,
In COM, you are registering a class name in the registry. Then, you can create an instance of that class in your code.
The CLR will not know where to load the class if it isn't registered. But, since you probably registered the (COM) class, the CLR will know where to find it (most probably in the GAC).
If you look through the output by regasm I posted in the question, you will find that there is no actual codebase dll (which contains the implementation of coclass), only mscoree.dll.
So, I am thinking how CLR will find the actual codebase dll when client invokes CoCreateInstance?
I have re-thought the process of how a COM client CoCreateInstance for managed code. I think the process should be,
1. the CLSID information input from client to mscoree.dll (in Windows Registry, there is no information of the actual codebase dll, only mscoree.dll will be used);
2. mscoree.dll will look through GAC (I am not sure whether mscoree.dll will do this or some other components will do this) to find the actual codebase (dll) which contains the CLSID information.
Do you agree with me or disagree? :-)
Any comments?
regards,
George
# 3 Re: [C# COM development] output by Regasm
I am not very sure about this, but as far as I know, each assembly contains some kind of codebase description.
So, the CLR knows which assembly to use. Then, it will ask the assembly where to find that specific class.
# 4 Re: [C# COM development] output by Regasm
Thanks Tischnoetentoet,
I am not very sure about this, but as far as I know, each assembly contains some kind of codebase description.
So, the CLR knows which assembly to use. Then, it will ask the assembly where to find that specific class.
Since in Windows registry, there is no real codebase (assembly dll) information, how do you think CLR will find the right assembly?
I think it should not be through Windows Registry CLR will find the right assembly -- since Windows registry has no real codebase information. So, how do you think CLR will find?
regards,
George
# 5 Re: [C# COM development] output by Regasm
Because the assembly is registered in the GAC. When you install a (shared) assembly in the GAC, how do you think the CLR will find it?
First, it will search the GAC, then it will search the app directory. I think this works the same for COM objects.
# 6 Re: [C# COM development] output by Regasm
I've registered a C# COM DLL which is NOT in the GAC and the registry DOES constain an entry (called CodeBase) for the full path of the DLL.
# 7 Re: [C# COM development] output by Regasm
Thanks Tischnoetentoet,
Because the assembly is registered in the GAC. When you install a (shared) assembly in the GAC, how do you think the CLR will find it?
First, it will search the GAC, then it will search the app directory. I think this works the same for COM objects.
I think CLR needs to find the binding between coclass/interface and codebase dll in order to support COM client. I can understand searching GAC is ok, since in GAC there is meta data which contains coclass/interface (correct me if I am wrong).
But I do not understand you point that searching app directory is also ok. Supposing in current directory, there are multiple dlls, and how could CLR know which one needs to be invoked? And how CLR knows in which dll, which coclass is implemented and exported as public class which is visible?
regards,
George
# 8 Re: [C# COM development] output by Regasm
Thanks Zaccheus, you do not delegate your dll to mscoree.dll? I think C# COM is managed code and the entry point for each actual codebase dll is mscoree.dll.
Anyway, could you post your registry content please for the specific item?
I've registered a C# COM DLL which is NOT in the GAC and the registry DOES constain an entry (called CodeBase) for the full path of the DLL.
regards,
George
# 9 Re: [C# COM development] output by Regasm
Thanks Zaccheus, you do not delegate your dll to mscoree.dll? I think C# COM is managed code and the entry point for each actual codebase dll is mscoree.dll.
Yes, I do, or rather regasm does. Like you say, COM must go through mscoree.dll.
But there is an additional entry (called CodeBase) which tells mscoree.dll where my C# COM DLL is.
Anyway, could you post your registry content please for the specific item?
No, sorry, it's work related so I can't post it.
Just search HKEY_CLASSES_ROOT\CLSID\ for Values called CodeBase and you'll quickly see what I mean.
# 10 Re: [C# COM development] output by Regasm
Hmm, this is strange, I used regasm to make a .reg file and the CodeBase value is missing!
So it looks as if regasm only adds the CodeBase value while actually registering an assembly, not while creating a .reg file.
Perhaps that is because the install location of the assembly is unknown when the .reg file is created.
# 11 Re: [C# COM development] output by Regasm
Hi Zaccheus,
Hmm, this is strange, I used regasm to make a .reg file and the CodeBase value is missing!
So it looks as if regasm only adds the CodeBase value while actually registering an assembly, not while creating a .reg file.
Perhaps that is because the install location of the assembly is unknown when the .reg file is created.
I have found some samples of CodeBase from registry. Thanks.
But, how do you think regasm will register the actual dll (other than mscoree.dll) into registry? I have searched registry by the actual codebase name, but can not find from registry -- only mscoree.dll is recorded with the CLSID.
I am wondering whether in your environment, it is different? (both mscoree.dll and the actual dll are in Windows registry by regasm)
regards,
George
# 12 Re: [C# COM development] output by Regasm
I have found some samples of CodeBase from registry. Thanks.
Cool.
:)
But, how do you think regasm will register the actual dll (other than mscoree.dll) into registry? I have searched registry by the actual codebase name, but can not find from registry -- only mscoree.dll is recorded with the CLSID.
I am wondering whether in your environment, it is different? (both mscoree.dll and the actual dll are in Windows registry by regasm)
Sorry, I don't understand your question.
When you use RegAsm to register a specific C# COM DLL in a specific location, then RegAsm creates all the required entries (including CodeBase) in that machine's registry.
# 13 Re: [C# COM development] output by Regasm
Hi Zaccheus,
Cool.
:)
Sorry, I don't understand your question.
When you use RegAsm to register a specific C# COM DLL in a specific location, then RegAsm creates all the required entries (including CodeBase) in that machine's registry.
If you specify /regfile option, codebase information of assembly will not be registered -- it is very strange.
I have tested that using /tlb option will enable the registration of codebase of assembly.
regards,
George