.NET     Console.WriteLine( "All Things .NET" );
.NET Nerd Blog Home
6.20.2002

 

COM+ Serviced Components



First try creating a .NET COM+ object. A few things I've learned along the way.

Assembly that has class derived from ServicedComponet must have a strong-name, and application (COM+ package) name.
using System.Reflection;
[assembly: ApplicationName("MyComponent")]
[assembly: AssemblyKeyFile("MyComponent.snk")]
(Remove the AssemblyKeyFile attribute from the AssemblyInfo.cs if you do this from the code)
(Can put these in AssemblyInfo.cs too. Need "using System.EnterpriseServices;" if move the ApplicationName attribute in there.)

Generate keypair with sn –k MyComponent.snk. For C#, put this snk file in the obj directory where assembly DLL is being built. For VB, put it in the solution directory. So after a successful build, the assembly should have a publickey entry in the assembly manifest (use ILDASM to view).

If you just run now without pre-registration, the runtime will register the package and assembly in COM+ "on the fly" (pretty cool, but takes a while to do this).

Pre-register using regsvcs tool.
regsvcs /fc MyAssembly.dll

Server Activation - help file says server activated assemblies need to be in the GAC to be called from DLLHOST, otherwise caller will get exception. This does not seem to be the case (check GAC after auto-registration and the assembly is not there.)

Other attributes to be aware of (what level to declare them), and their default values if you don't declare the attribute:

  • ApplicationActivation - library (activated in caller's process)
  • ApplicationName - <assembly name>
  • ApplicationID - <generated guid> (used instead of ApplicationName when caller instantiates object)
  • AutoComplete (method) - false (won't automatically commit transaction upon successful method exit)
  • Transaction (class) - false




Comments: Post a Comment

Powered by Blogger