How do I use C# to build COM addin?

Hi,

I would like to build COM component add-in using C# instead of VB.NET. Since QSRules.dll is not strong named, I cannot reference it directly in C# ..NET.

Here is what I did.

  1. Create C# Class library.
  2. sn -k AddInTest.snk
  3. Add this line [assembly: AssemblyKeyFile("AddInTest.snk")] in AssemblyInfo.cs
  4. Declare Entry Point. public bool Process(QSRules.SessionClass session) { MessageBox.Show(session.Cashier.Name.ToString()); return true; } Unfortunately, it cannot be compiled because QSRules is not strong named. So it give error message saying that "Assembly generation failed -- Referenced assembly 'Interop.QSRules' does not have a strong name ". As far as I know, RMS customized add-in component should be strong named to be installed in assembly cache.

So I tried to change the entry point code like VB.NET

public bool Process(object session) { MessageBox.Show(session.Cashier.Name.ToString()); return true; }

Obviously, this code only works for VB.NET because as far as I know, VB.NET is very generous lanague. Since C# is strong typed language, session object DOESNOT know what the Cashier is at compile time, so it generates error.

How do I write COM add-in component using C#?

Does anyone know to workaround for this?

Thank you in advance.

..............................................................TJ

Reply to
TJ
Loading thread data ...

I had the same issue before, because I am C# programmer. However, after trying to program COM add-in in C# without success, I gave up eventualy, and live with VB.NET. It is just a case that tests your adaptivity.

Reply to
lzcouponex

Did you try running QSRules through TLBIMP.exe utility and giving it your own strong key name to produce a new interop ?

Reply to
Ken B

HI,

Wow, great. Thank you very much for your suggestion. BTW, I got a this message when using TLBIMP.exe TlbImp warning: Type library importer has encountered an interface not derived from IUnknown: _HiddenInterface. It only happened at the first time. When I tried to covert using TLBIMP from second time, that message didn't come up. Can I safelfy ignore the warning message?

Thanks again.

.......................................................................TJ

"Ken B" wrote:

Reply to
TJ

I did some testing a while ago, and tried using a VB.Net component to 'catch the hook' from RMS, then call a c# component to do the work. I just raised a message box in my test, but was able to get c# code executing from within RMS. You still need to reference QSRules from within your c# project, but you don't have to register your project for COM Interop, so you avoid the strong name problem.

Basically I decided it wasn't worth the trouble, since you have to take an object as a parameter and cast it to a SessionClass before you can do anything with it. This isn't such a big deal, except that MS insists on breaking compatibility every time they release a hot fix, so you would need a version of your add-in for every hot-fix you install.

Reply to
Glenn Adams [MVP - Retail Mgmt]

BeanSmart website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.