Automation controls with C#

Can anybody telle me if there is at known problem with Navision and Microsoft .net controls written in C# with Visual Studio.Net ? I have written one control, and installer, and I created an Automation variable instance of one of the classes inside a Navision Form. But none of the class properties or methods are available. They are of course public. I will be happy to hear any suggestions. Thanks Carsten Nærvig Sørensen

Carsten : Only non visual COM components will work with in Navision.

Thanks, but the problem is more basic than that. I have no intentions of incorporating viasual components. Just do some sting work. But Navision seems unable to se any methods and properties af my C# classes. I can browse the classes from Navision but not the methods. My first guess would be that NF Automation is not compatible wit .NET managed code.

quote:


Originally posted by Tarek Demiati
Carsten : Only non visual COM components will work with in Navision.


Is there any work around on that subject ?

Carsten, Navision won’t display your properties or methods, but they should be available. Do a search on Word Automation in the forum and you’ll see many examples of ActiveX/COM objects being utilized. We haven’t switched to .Net yet, but plan too. We do, however, frequently use VB to create DLLs and implement via Navision. Please let us all know if you find that Navision has problems with .Net. Thanks, Bill

Hi Carsten, Under Project-Properties-“Configuration properties”-Build you find at property called “Register for COM Interop”. Is this property checked ? Have you created a GUID for the Interface ?

Thanks Bill and Claus. I have looked through these forums, and found a lot of help on Office Automation. That is however no use for me right now. I have already done Excel and Outlook integration with Navision Automation with great succes. That is relatively easy, and it works really fine. But I think that is because these Office dll’s are not made of .NET managed code. Actually I haven’t tried making an Automation Server using C++. Maybe you know a few tricks there? They might be helpful when working with .NET too. I looked at the c++ example from this forum, but I didn’t see anything unexpected. I know a GUID and project setting “Register for COM Interop” are required, because you can’t acces the Automation Server if you don’t have these. I used the Add-In Project Template from Visual Studio .NET. It is really nice. It creates a project with GUID and other things necessary. It also creates a setup project for easy registering and uninstall.

Carsten, I don’t know the answer to your problem. But I wonder why you write an OCX instead of a DLL. I have written DLL’s in Visual C++ .NET (ATL project) and this works fine. Maybe if you write a DLL it will work…?

I am writing a DLL. I Don’t want an ocx. I would prefer C#, but I am very interested in your C++.NET solution. I will try that if you say it works. Is there any chance, that you would post the skeleton of a C++ Automation DLL, that works?

I can give you a brief explanation (for ATL, don’t know if this procedure works for MFC… You could try). 1. Start new “ATL project” (use standard settings) 2. In the ‘Class view’ right click on your project (upmost item in tree) Select ‘add class’ 3. From the wizard i don’t know for sure wich class type i used but i think it was ‘ATL control’ but other may work as well. 4. If you also want to send events to navision go to ‘options’ and check ‘connection points’ 5. In the ‘class view’ you will find your class. You will also find your classname with a ‘I’ in front of it and if you have checked connection points you will also find your classname wiht ‘_I’ in front of it. The ‘I’ contains the property’s and method interface \ The ‘_I’ contains the Event inteface (shown as methods however, but are events) 6. Right click the ‘I’ item and select ‘Add’ → ‘Add Property’ or ‘Add Method’. 7. Apply some settings, click OK and the function will be created in the CPP file. Repear from step 5 until all propertys, methods and events ar defined. Remember, always use the ‘wizard’ to add propertys or methods. Because some modifications are required in the .H file and the ‘wizard’ takes care for that. Good luck…

That works. Thanks. This confirms my worries, that my problem comes from .NET. This is a Win32 dll. I doesn’t integrate with my .NET application. I will continue to look for a way to integrate .NET programs with Navision, and post my findings here.

Hi, i have an Example C# Project which includes a Method that returns a String to Attain. I using it in MBS 3.70 and it works fine. I open an empty Project an adding this Class. In the Project Properties i changed the Propertie Outputtyp to Classlibrary and Register for Com Interop to Yes. Maybe this C# Source Code helps: ------------------------------------------------------- using System.Runtime.InteropServices; namespace HelloAttain { public interface IInterop { string ShowText(); } [ClassInterface(ClassInterfaceType.None)] public class Interop : IInterop { public string ShowText() { return “HelloFromDotNet”; } } } -------------------------------------------------------------

Hi, I have a problem raising an event from an C# DLL. Nothing happens in Navision when i try to raise the event. Here is the C# source code: ----------------- using System.Runtime.InteropServices; using System; namespace myspace { public delegate void MyDelegate(); // delegate declaration [InterfaceType(ComInterfaceType.InterfaceIsDual)] public interface I { event MyDelegate MyEvent; void FireAway(); } [ComSourceInterfaces(typeof( I )), ClassInterface(ClassInterfaceType.None)] public class MyClass: I { public event MyDelegate MyEvent; public void FireAway() { if (MyEvent != null) MyEvent(); } } } ----------------- I will be happy to hear any suggestions. Thanks, Tommy Olesen

Thanks Bastian. The your code example works. Too bad I missed your reply in July. Now I can get on with writing somme very useful automation controls. - Carsten