creating COM objects in C#

D

Dan Holmes

I think i have the basics. I am creating a COM wrapper for my VB6 code
to call an existing assembly. Below is the wrapper. Do COM object
created in C3 need to be in a strongly named assembly? If so what if
the assembly that i am wrapping also depends on an interop layer that
isn't strong named? You can only strong name something that also has
dependencies of strong named assemblies.

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace AcmeUnitLabelingComInterop
{
[Guid("5F05CEC4-8979-4aea-86E5-868EBBFF3138")]
public interface IAcmeUnitLabelingCOM
{
[DispId(1)]
bool Printlabel(string LabelXml);
}

[Guid("A5AD09C9-B786-434d-978C-5B5C7CE563B0")
, ClassInterface(ClassInterfaceType.None)]
public class AcmeUnitLabelingComInterop : IAcmeUnitLabelingCOM
{
public AcmeUnitLabelingComInterop() { }


#region IAcmeUnitLabeling Members

bool IAcmeUnitLabelingCOM.Printlabel(string LabelXml)
{
IVSLabeling.UnitLabeling ul = new IVSLabeling.UnitLabeling();
return ul.PrintLabel(LabelXml);
}

#endregion
}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Dan,

COM interop doesn't require strong naming. However, it is usually a
good idea to place COM object implementations in .NET into the GAC, to make
finding the assembly easy (remember, since it is registered as a COM object,
the whole machine has access to it). Placing assemblies in the GAC requires
strong naming.

If your assembly is referencing assemblies that don't have strong names,
then you can't strong name your assembly. Every assembly you reference must
be strong named in order to strong name yours.

If you are referencing interop assemblies in the assembly you want to
strong name, then you can use TLBIMP utility to generate the Runtime
Callable Wrappers (RCWs) that you access, passing the /keyfile or
/keycontainer switches to strong name the interop assembly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top