How to write a .NET Control for Microsoft Navision

After my previous post about how to use a .NET control with Navision, I've received lots of email requests and comments on how to write a control with .NET that can work and talk with Navision.

Unfortunately I've discovered that there's not specific documentation about this on the net and so I hope that this post could be useful for everyone that works with Navision, but remember that the procedure is just like writing a .NET component and call it from a COM component.

.NET code is not directly accessible to COM clients and in order to use .NET code from a COM client, you need to create a proxy class, normally known as a COM Callable Wrapper. When you have to create a .NET class that will be used by COM clients, you have to keep in mind 2 prerequisites:

  1. You have to explicitly define an interface in your .NET code and have the class implement the interface
  2. Any class that must to be visible to COM clients must be declared public. The same rule applies to methods, properties, and events that will be used by COM clients.

After that, we can start building our control...

Open Visual Studio .NET and create a new project (Class Library or User Control as the Project Template).

After that, rename the Class1.vb file with the name of your project (for example NavControl.vb), select the code window and start by defining the interface that your component has to implement:

  1 Imports System.Runtime.InteropServices
  2 Imports System.Reflection
  3 
  4 <Assembly: AssemblyKeyFileAttribute("sgKey.snk")> 
  5 
  6 Public Interface INavControl
  7     Function SaySomething() As String
  8 End Interface

Here we have defined an interface named INavControl where a function called SaySomething() is defined. This function will be the method of our .NET Controls that works with Navision.

Now we have to define a public class that must implement this interface. The class will be defined as follow:

  1 <ClassInterface(ClassInterfaceType.AutoDual)> _
  2 Public Class NavisionControl
  3     Implements INavControl
  4 
  5     Public Function SaySomething() As String Implements INavControl.SaySomething
  6         Return "Hi, I'm the .NET Control and this comes from my function"
  7     End Function
  8 
  9 End Class

This class implements the function SaySomething that in this example is only a simple function that, when called, returns a string to the caller.

Now we have to register our .NET component in order to use it in Navision.

Before compilation, the assembly containing the class that will be used by Navision must be signed with a cryptographic key pair (strong name). Signing an assembly with a strong name helps .NET ensure that the code in the assembly has not been changed since the assembly was published.

To create a strong name you can use the sn.exe tool from the Visual Studio Command Window:

sn -k sgKey.snk

A file named sgKey.snk will be created and the line <Assembly: AssemblyKeyFileAttribute("sgKey.snk")> in our code wil use it to sign the Assembly.

Now you can compile the project and a file named NavisionControl.dll will be created. In order to register it and use the newly created component with Navision, you've to follow these 3 steps:

First, you must create a type library for the assembly (a type library is the COM equivalent of the metadata contained within a .NET assembly) and in order to do this, open the Command Window and type:

tlbexp NavisionControl.dll /out:NavisionControl.tlb

After that, you have to use the Assembly Registration Tool (regasm.exe) to both create the type library and register it in a single operation:

regasm /tlb:NavisionControl.tlb NavisionControl.dll

At the end, you must install the .NET assembly into the Global Assembly Cache (GAC) so that it will be available as a shared assembly. To install an assembly into the GAC, you've to use the gacutil.exe tool:

gacutil /i NavisionControl.dll

Now you're ready to use your component in Navision.

To test it, open the Navision Object Designer, create a new blank form and declare a global variable named MyCntr with DataType = Automation. Select the SubType by pressing the Assist Edit button and (on the list of controls that will appear to you) select NavControl.NavisionControl. Now your .NET control is declared in Navision.

We've also declared a string variable named CntString that will contained the string message returned to Navision from the .NET control.

In Navision, the form's C/AL Global section will appear as follow:

Now, in order to test the control, open the code window for this form and on the OnInit trigger of the form place the code to instantiate the control:

IF ISCLEAR(MyCntr) THEN
 CREATE(MyCntr);

On the OnOpenForm trigger we'll place the code below:

CntString:=MyCntr.SaySomething;
MESSAGE('The .NET control has returned this string: %1',CntString);

This code launch the SaySomething method of the .NET control and place the returned string into the CntString variable. Then it shows a message to the user with the returned string.
To complete the little project, on the OnCloseForm trigger we have to release all the resources used by the .NET control, so place the code below:

CLEARALL();

The example is finished... if you compile and run this newly created form this is the result:

When the form is executed, the control is instantiated and the .NET method is executed. Simple?

This is obviously only a simple example but it shows exactly all the steps that you have to do in order to create a .NET control that is able to work with Navision. The SaySomething methos here is really stupid (it returns only a string) but it could be really complex and it could perform database operations, connect to the web etc... The limit is only your fantasy!

I hope to have given a clear example on how to perform these tasks... Maybe I've opened a new window for all Navision's developers that reads my blog?

Print | posted on Monday, September 19, 2005 3:04 PM

Comments on this post

# How to write a .NET Control for Microsoft Navision (part. II)

Requesting Gravatar...
Left by STEFANO DEMILIANI WeBlog on Nov 17, 2005 6:01 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Thank you so much for this information. I have been looking for this everywhere. I have spent months looking on the internet for this stuff.
Thank you
Rich
Left by Rich on Jan 05, 2006 2:39 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Nice to see that it helps.
Check also the part II post here:
http://demiliani.com/blog/archive/2005/11/17/3205.aspx
Left by Stefano Demiliani on Jan 05, 2006 3:05 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Thanks a lot for the information. I have searched for 3 days on the internet and read a lot of pages. Nothing was working with Navision.
With your solution it works.

Thanks.
Left by Elwin from Holland on Mar 08, 2006 3:49 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Thanks Stefano,

Excellent. There is more value in this than anything else that I have seen in Mibuso.

Well done.
Left by Michael Morrissey on Mar 20, 2006 3:17 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
When I use the create funtion in Navision a message pops up saying:
'cannot create an instance of OLE control or Automation..... check if the control or Automation is proprely regitered'

PS- This is a translation of the message that apears to me in Portuguese

Please HELP
Left by Rui Caramalho on Mar 20, 2006 6:16 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I know how to develop a dll in vb.NET now and use it in Navision.
In the future I want to use my custom dll on other computers, so I must register it on all of them.
The first problem I found is that I must install Framework 2 on the other computers, otherwise I
can't use regasm.
After that the dll is shown in Navision but a error occures when running it (Could not create an instance of the OLE control or automation server .....). I think I missed a step.

It is not desirable to install Framework 2 on all other computers. With the standard installation of Navision Framework 1.1 is installed.

Is there a simple way to register a custom dll on other computers?

Thanks in advance.
Left by Elwin form Holland on Mar 27, 2006 10:18 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Elwin, you can build your DLL with .NET 1.1 (on my example, I've built it with the 1.1 version). .NET runtime is a prerequisite to run any .NET applications, so if you've built a .NET 2.0 application, you need the .NET 2.0 environment.
To deploy your .DLL on the target machines, I suggest to develop a custom setup package with Visual Studio (that permits you also to install .NET prerequisites if missing).
Left by Stefano Demiliani on Mar 27, 2006 10:25 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Thanks for your answer.
I thought myself it must be possible to use version 1.1 of Framework. Until now I couldn't found the place to adjust this. In the properties of the vb-project I found a tab references but I can't select version 1.1 there. Can you give me a hint?

I will study how to make a custom setup package.
Left by Elwin form Holland on Mar 27, 2006 10:48 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Are you using Visual Studio 2005? If yes, you're forced to use the .NET 2.0 Framework.
Have you a machine with Visual Studio .NET 2003 installed?
Left by Stefano Demiliani on Mar 27, 2006 10:50 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I'm using Visual Studio 2005. That means I have to install Framework 2.0 on the other system.
Thank for the answer.
Left by Elwin form Holland on Mar 27, 2006 10:58 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Yes, you're forced to install .NEt 2.0 also on the target machine (you can create a setup package that does the installation work automatically).
There's also a "pet project" called MSBee that permits you to build .NET 1.1 project with VS2005, but I've never tested it.
Left by Stefano Demiliani on Mar 27, 2006 11:01 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I am new to Navision, but it seems greate. I want to use .NET into Navision. This post is very useful. I have created a .NET control as mentioned but when declaraing global variables when I click on subtype it doesn't show me any thing in the list of controls and I don't know which Automation server to select. Please guide.
Left by Prashant Waykar on Jun 16, 2006 12:21 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Prashant, your global variable must be af type "Automation", then you can select what type of automation control you want (here you've to choose the control that you've previously added to the GAC as described on my post.
Then, on C/AL code you can call every PUBLIC function you've declared in your control.
Left by Stefano Demiliani on Jun 16, 2006 12:25 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Thank you for your instant reply. As you mention I have already set the variable type as Automation and verified that control is in GAC. But when I click on Assist Edit button in SubType. I get the Automation object list empty. I doesn't see any control in the list. Should I select server from Automation Server list? which? Please guide.
Left by Prashant Waykar on Jun 16, 2006 1:19 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Yes, you've to click the Automation Server field, than on the list that appears you you've to choose your .NET control (in my example it's called NavControl). After chosing the control, the name of the class appears you (in my example it's called NavisionControl, check my picture).
Left by Stefano Demiliani on Jun 16, 2006 1:24 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Thank you again for your response. I also looked at your Part II post. I am missing server in my Automation Server list. Is it to do something with Demo version?
Left by Prashant Waykar on Jun 16, 2006 1:51 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
You don't have the Automation Server list? Check my part II post, here there's the image that explains what's the window. Any problems?
Left by Stefano Demiliani on Jun 16, 2006 1:55 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I do have the Automation Server list but it misses .NET control (in my example it is also NavControl). What could be the reasons? Is it to do something with Demo version or somtthing else?
Left by Prashant Waykar on Jun 16, 2006 2:04 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I think that the problem is that your control is not correctly registered into the GAC.
Left by Stefano Demiliani on Jun 16, 2006 2:10 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I can see my dll server in the automation server list but when I select it, it doesn't show me any interfaces and classes in that. What could be the reason? Needs a help.
Left by Prashant Waykar on Jun 20, 2006 10:17 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Is your class or methods declared as public? Have you followed all my indications? Check your .NET code.
Left by Stefano Demiliani on Jun 20, 2006 11:05 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
yes definitely I have followed your indications only. I am using Visual Studio 2005
Left by Prashant Waykar on Jun 20, 2006 11:36 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I can't understand why your control doesn't expose nothing. If your methods are public, you've to see them.
Try to send me your code.
Left by Stefano Demiliani on Jun 20, 2006 12:07 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Thanks a lot for all this stuff and your quick responses. Finally it is working. I build it using Visual Studio 2003 and it works fine. Thank you again.
Left by Prashant Waykar on Jun 20, 2006 12:32 PM

# Connecting Microsoft CRM to Dynamics NAV

Requesting Gravatar...
Connecting Microsoft CRM to Dynamics NAV
Left by STEFANO DEMILIANI on Nov 20, 2006 12:42 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Good, very clear! I am trying!
Left by zzheng on Dec 06, 2006 12:58 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I have the same problem with Prashant.I can see my dll server in the automation server list but when I select it, it doesn't show me any interfaces and classes in that. What could be the reason? I also use VS2005. Is it the reason?
Left by zzheng on Dec 06, 2006 2:26 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
With a .NET control developer with .NET 1.1 my sample works good, but I think it should work also with VS2005. Are the exposed methid declared as public?
Left by Stefano Demiliani on Dec 06, 2006 5:23 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Thank you for your response.
When I change the VS2005 to VS003, It is ok now. I want to ask you if I can use this DLL to post a Web Form to the Webserver? (2) Is this way can be used to connect the Navision to the Webservice. Because Webservice also can be compile into a DLL. When I was trying to do that, I failed because of the Strong name. It always could not Readding the key.
Left by zzheng on Dec 07, 2006 12:48 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Yes, you can use a control like the one described on my post, and on your public method (such as the SaySomething above) you can call an external webservice.
Left by Stefano Demiliani on Dec 07, 2006 5:43 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I get a error that the automation was not reg correct...WHY?
Look at this link
http://www.mibuso.com/forum/viewtopic.php?p=80636#80636

CREATE(autEnc);
Left by Magnus on Apr 10, 2007 11:24 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Have you correctly installed your .NET control into the GAC? Have you signed your assembly with a strong name? My post shows the steps you need...
Left by Stefano Demiliani on Apr 10, 2007 11:28 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Stefana, I have the problem with a downloaded component from this
http://www.mibuso.com/forum/viewtopic.php?p=80636#80636

Do you have any suggestions??
Left by on Apr 12, 2007 10:55 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Can you explain me what type of problem do you have? Maybe I could help you.
Left by Stefano Demiliani on Apr 12, 2007 11:12 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
In the link I refered to I described the problem.

I have done these steps
tlbexp NavisionControl.dll /out:NavisionControl.tlb

regasm /tlb:NavisionControl.tlb NavisionControl.dll

When I tried to run gacutil it says you have to make a strongnamne.. When I try to do this I dont understand how when I have just these files
COMEncodingConverter.dll
COMEncodingConverter.pdb
COMEncodingConverter.tlb
Left by Magnus on Apr 13, 2007 5:38 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Are you sure that you've correctly made the strong name?
Check my code... the first line of your control (after the Import section) must be something like this:
<Assembly: AssemblyKeyFileAttribute("sgKey.snk")>.
after that, the first compilatino step that you've to do is to create the strong name.
To create a strong name you can use the sn.exe tool from the Visual Studio Command Window, like this:
sn -k sgKey.snk
A file named sgKey.snk will be created and the line <Assembly: AssemblyKeyFileAttribute("sgKey.snk")> in our code wil use it to sign the Assembly.
After these steps, you've to execute the next steps (tlbexp and regasm).
Left by Stefano Demiliani on Apr 14, 2007 10:31 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
do I need the hole project or is this 3 files enough?
Left by Magnus on Apr 23, 2007 5:29 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hello,

I followed the example above and I got the following message:
NavControlTest.NavControlTest2 is neither recognized as a GUID nor as the name of an Automation server. Check to see if the entry is misspelled.

I get this in Navision when I go to declare a variable of Automation Type and Subtype NavControlTest.NavControlTest2. Looking at the example above I noticed the single quotes around the first word before the period. So I tried it like this 'NavControlTest'.NavControlTest2 and got this message:

Could not find the specified interface in the type library.

Anybody else run into this issue?
Left by Ahmad Latif on May 18, 2007 10:15 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Update to my question:

I was using Visual Studio 2005 SP1 .Net Framework 2.0.
Left by Ahmad Latif on May 22, 2007 5:48 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hello,

I'm working a while with .NET Controls in Microsoft Navision with your solution.
Now I have added a form in VB which I can call from Navision. This is working fine.

The only minor problem is, when I declare a automation variable in Navision I see 3 subtype: a interfase, a class and the form.

I can only run the form through a function from the class and not directly.
Now I want to hide the form so it does not appear with the subtypes.

Is this possible?

I hope you can help me.
Thanks in advance.
Left by Elwin on Jun 27, 2007 11:05 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Elwis, have you checked my second post here:
http://demiliani.com/blog/archive/2005/11/17/3205.aspx
maybe it could help you...
Left by Stefano Demiliani on Jun 27, 2007 2:11 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I have checked your second post. I couldn't find a solution for my problem.

I will try to explain my problem.
The class1.vb consist of several functions. I have added a standard windows form (about box) added to my VB-project. The class1.vb has a function which will show this about box. This function can be used in Navision and it works.
The about box form itself is shown in Navision when declaring a automation variable.
This I want to change so the about box form is not shown.

I tried to use the code from your example but I'm doing something wrong.
I have opened AboutBox.designer.vb and changed the code:

<Global.Microsoft.VisualBasic.CompilerServices.
CompilerServices.DesignerGenerated()>
Partial Class AboutBox

to

<ClassInterface(ClassInterfaceType.None)>
<Global.Microsoft.VisualBasic.CompilerServices.
CompilerServices.DesignerGenerated()>
Partial Class AboutBox

I hope you can give me a clue.
Thanks in advance.
Left by Elwin on Jun 29, 2007 1:30 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I found the answer myself.

I have defined a form in a VB-project and I don't want to see it in the subtype when defining the automation-variable in Navision.
Go to the code of the VB-form and change the property COM-Visible to FALSE.

It is so easy when you know it.
Left by Elwin on Jul 02, 2007 2:02 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Really good :)
Left by Stefano Demiliani on Jul 02, 2007 2:10 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Thank so much! Your page was critically important to writing my first functional DLL file. Your screenshots informed me that I could use multiple imports.
Left by fgw on Sep 18, 2007 10:28 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hi am Anil Prasad
I like to export my navision report in excell format but the alignment gets disturb.help me
Left by Anil Prasad on Sep 25, 2007 1:10 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Unfortunately this examle doesn't work for VS2005. Is some solution for this problem?
Left by Vyacheslav Valma on Jan 17, 2008 5:48 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hi!!! I've found solution.Need to Change attribute [assembly: ComVisible(false)] in AssemblyInfo on [assembly: ComVisible(true)]. Thank you for example!!! It very helpes me.
Left by Vyacheslav Valma on Jan 18, 2008 1:08 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
ertqeahg
Left by lokesh varma on Mar 13, 2008 11:28 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
i am varma
Left by lokesh varma on Mar 13, 2008 11:28 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I copied the example and it works fine. But now I want (and many others with me) to create a custom control for Navision. I added a custom control to my class lib, also a form. But nothing is shown in Navision. Please can you help me further?
Left by Marco on Jul 02, 2008 11:53 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hi,
I have created a .dll file using VS2003 in 1.1 Framework. It is working fine as required in my own system where i have created the dll and also i am able to use the class and methods defined within the dll from MS Navision.But the problem is that when i am trying to register the same dll file in some other system then i am not able to use it from Navision it is showing error as "Couldn't create Instance of the OLE control" sort of..

Please Help.
Left by Mahendra Jain on Sep 18, 2008 8:22 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Is the .NET dll correctly registered to the new system? Try to copy the assembly to c:\windows\assembly folder and check if NAV can see the control.
Left by Stefano Demiliani on Sep 18, 2008 8:56 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
NAV can see the control.. but when i instantiate the variable it says an error..'cannot create an instance of OLE control or Automation..... check if the control or Automation is proprely regitered'
the control is working fine on my system where i created the control
Left by Mahendra Jain on Sep 18, 2008 11:27 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Seems that the control is not correctly registered on the GAC. Can you see it on the assembly folder? You can try to write a simple winform application that instantiate the control and run it on the client that has the problem.
Left by Stefano Demiliani on Sep 18, 2008 11:35 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I am able to see the assembly in the assembly folder also.. and also i have written a simple application using VS2003.. which is able to use the dll and perforrm the desired task. but still i am not able to use it in the navision..
please help..
Left by Mahendra Jain on Sep 22, 2008 7:54 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hi Thanks a lot..

Finally i have overcome with the problem..
for solution,
I have manually removed the dll once from the assembly folder and then repeat the whole process again. I don't know why.. but it worked for me.
Left by Mahendra Jain on Sep 24, 2008 8:11 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hi,

I have a problem. I see my ddl in Nav, but when I click subtype I have blank list. Any ideas on what im doing wrong?
Here are my code:

interface INavisionTools
{
string DoSomehing(string foo);
}

[ClassInterface(ClassInterfaceType.AutoDual)]
public class Barcode : INavisionTools
{
public string DoSomething(string foo)
{
//implementation
}
}

I have used: [assembly: ComVisible(true)]
Left by NavNoob on Nov 26, 2008 7:57 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Have you executed the steps above? Seems there are problems on DLL registration...
Left by Stefano Demiliani on Nov 27, 2008 2:15 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Yes I had, as I mentioned the ddl is on the list, bo has no objects and methods. I was trying a lot of weird stuff and still no solution. It must be silly mistake.
Left by NavNoob on Nov 27, 2008 9:24 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Stefano,

Thanks for these articles on Automation servers in Nav. With your help, I finally managed to create one. To help others out, I posted a full sample solution (with FOB/TXT files) with some other thoughts on my blog at adventuresindotnet.blogspot.com/.../...object.html, if anyone is interested.

Tim Larson
Left by Tim Larson on Dec 04, 2008 6:21 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Tim, great idea. Thanks...
Left by Stefano Demiliani on Dec 04, 2008 9:13 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hello Stefano,
I have question about registering dll coming with Navision and regarding automation. The point is how we can deploy this issue without full instaltion proces of Navision. I have found some directions at this site http://dynamicsuser.net/forums/t/5995.aspx but it is valid till version 2. Let know how we can come up with it.

Regards
Left by NSPK on Dec 10, 2008 2:04 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hi NPSK,
if you correctly install on the GAC a .NET control, you can see it also without a full installation process of the NAV client. When I wrote this post, the NAV client was installed on my machine only with a folder Copy...
Left by Stefano Demiliani on Dec 10, 2008 2:09 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Methods are visible, but ole automation cannot create instance of object.
Left by NSPK on Dec 10, 2008 3:56 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
when I call the class generated in c# 2005 from navision I can't see the method, if I created a interface, I see the method but navision give me this error "could not create an instance of the OLE control or Automation server identified by GUID?" I don't what can I do, because I follow your step, thank
Left by Veronica on Dec 23, 2008 3:30 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
It's always the same registration problem Veronica... check also this link
adventuresindotnet.blogspot.com/.../...object.html
it could be helpful...
Left by Stefano Demiliani on Dec 24, 2008 10:34 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hello Stefano Demiliani,

I have a problem in Navision. I write a *.dll in Vb.Net 2005 Express Version. Everthing work like you show it in this post. But only in form and I want to trigger the events in a codeunit. I have 2 events but both are not visible when i want to create eventtriggers in navision and change the setting of the automation property in WithEvents "True"?!? The events have the body like: Public Sub cmd_DataArrival(ByVal bytesTotal As Integer) Handles winsock.DataArrival

I don't know if I must implement a interface for the events too like the functions?

Can you help me?
thx t2
Left by tropic2 on Feb 11, 2009 1:58 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
With the Automation in my sample you launch a .NET code you've written (a function for example). Yes, you can also execute this code on a trigger or on a Codeunit. I've not understood what do you want to do however... On my sample, you launch from NAV (C/AL) a .NET code that is executed. You can't handle external events that comes from the outside (what is Winsock.DataArrival??).
Left by Stefano Demiliani on Feb 11, 2009 2:42 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
When you open a new codeunit you see only Documentation and OnRun... My Boss told me that when you apply a new variable with the datatype automation and the *.dll in Subtype and then you go to the properties of the automation variable and then you can see, when you change the setting of the automation property in WithEvents "True", all your events in the codeunit...

Winsock.DataArrival is a event from the Interop.MSWinsockLib. You know client-server modell? The server sends the client or the client sends information to the server, when data are available in the stream, the event dataarrived will trigger this event.

so the event dataarrived should be in the codeunit... that is the plan. but i don't know if this is possible!
Left by tropic2 on Feb 11, 2009 3:42 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Check this code I have: this is a sample assembly which can be used as an automation object from within Navision.
The code looks like this:

using System;
using System.Runtime.InteropServices;

namespace raiseevent
{
[ComVisible(false)]
public delegate void PulseDelegate();

[GuidAttribute("9CC9CCAE-B300-4794-B3A8-9960D43A57D5")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
public interface ButtonEvents
{
[DispIdAttribute(1)]
void Pulse();
}

[GuidAttribute("C0BEE88F-01EC-4755-8B0A-A20E0563428A")]
public interface iButton
{
[DispIdAttribute(2)]
void CausePulse();
}


[GuidAttribute("38345F3F-ADDE-4089-B868-551EA7937528")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(ButtonEvents))]
public class Button : iButton
{
public Button()
{
}

public void CausePulse()
{
Pulse();
}

public event PulseDelegate Pulse;

}
}


Create a codeunit.

The automation object is named "raiseevent". Choose the class called Button. Assign withevents property in Navision and put some code in this property i.e. message('hello world')

On the OnRun trigger of your codeunit place this code:

CREATE(raiseevent);
raiseevent.CausePulse();
Left by Stefano Demiliani on Feb 11, 2009 4:01 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
ok, sorry for my english but i think you don't understand me :(
i give you a short sample...
when you have a new blank codeunit. go into the designer and then to the C/AL clobals. new automation variable. subtype -> F6 then automation server -> F6 ... search in the list "Navision Timer 1.0". ender ... enter ... then go into the properties of the variable. (Shift + F4) The Proberty from WithEvent must be changed from No to Yes. and then you see unter OnRun for example("Variable" :: Timer(Milliseconds : Integer). and this is what i want with my events from the dll?
Left by tropic2 on Feb 11, 2009 4:10 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Ok sorry, now I've understood the problem...
Have you checked this link on MSDN?
msdn.microsoft.com/en-us/library/aa973247.aspx
The second part shows how to make .NET events visible to Navision.
Left by Stefano Demiliani on Feb 11, 2009 4:23 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
thx, you are my hero :)
Left by tropic2 on Feb 11, 2009 6:35 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Sorry Demiliani, but i must disturb you another time. everything works withe the events like msdn.microsoft.com/en-us/library/aa973247.aspx But why i see all the eventhandler in the Automation Object List? Is it possible to inhibit the eventhandler in the Object List but display them in the C/AL Editor as Event?

thanks :)
Left by tropic2 on Feb 20, 2009 2:29 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hi to all, for the ones how still have a problem with VS2005 and when compiling and running have the problem:

'...cannot create an instance of OLE control or Automation..... check if the control or Automation is properly registered...'

I have solved this by:
1- Removing the line: [assembly: AssemblyKeyFile("sgKey.snk")] from the code

2- them go to the project properties (where you find the properties of Application; build; build events; debug;....) and in the "Sinning" separator select "Sign the Assembly" and choose your file (the previously created one)

3- I have putted the code find in: adventuresindotnet.blogspot.com/.../...object.html in the build events

This worked for me... good luck :)
Left by Manuel Baião on Sep 25, 2009 10:42 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Hi Stefan,

Thanks for your wonderful work. actually i hv written a wrapper class in C# which actually has a console DLL ( more like a credit card processing DLL) embedded in it. after a much battle i got it registered and i could see the methods in navision. but when i execute the wrapper class or functionality the system prompts the following error 'Could not create the OLE or automation...' and this is happening at the creation or instantiation of the wrappers class i.e CREATE (wrapperclass.dll). so wanted to check with you if u hv encountered this kinda error or any suggestions from u would be great help.

i have followed you r steps as is. i am not sure if this is due to GUID creation?
Left by Kumar on Oct 05, 2009 6:00 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Good clear article. Thank you. We have a credit card authorisation COM component written in VB in VS2008 live and working in Nav 5. Our problem has been creating a setup that registers the component correctly. I can set it up manually no problem.

Do you have an example?
Left by Skye Quin on Oct 30, 2009 5:23 PM

# replica jewelry

Requesting Gravatar...
Good clear article. Thank you. We have a credit card authorisation COM component written in VB in VS2008 live and working in Nav 5. Our problem has been creating a setup that registers the component correctly. I can set
Left by replica jewelry on Apr 29, 2010 5:47 AM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
Having done this a few times for a client, I feel compelled to mention that in addition to checking "Register for COM interop" under the Build section of the project properties, you also need to go into the Application section of the project properties, hit the Advanced button, and check the "Make assembly COM-Visible" box.
Left by Thomas Hunt on Jul 27, 2010 12:22 AM

# shoes

Requesting Gravatar...
Insured in order to reduce the out-patient treatment of patients with chronic severe cost burden and effectively protect the insured medical treatment from next month onwards directly under the Medicare outpatient treatment of chronic uggs outlet

diseases in the original grant will be based on the kinds of chronic diseases additional kinds of chronic diseases At the same time will enhance the existing species in a chronic out-patient treatment ugg boots outlet

of chronic diseases grant limit It is understood that included in the basic medical insurance benefits outpatient treatment of chronic diseases range of new diseases were chronic obstructive pulmonary disease ankylosing spondylitis endometriosis ugg boots sale


myeloproliferative disease ulcerative colitis Who suffer directly under the insured in these chronic diseases and patients who do need long-term outpatient treatment may be according to prescribed procedures to the city health insurance Christian louboutin
agency the Committee of Experts Luan review confirmed that health insurance and receive a Certificate treatment of chronic diseases calendar the patient you can enjoy the subsidy cost of outpatient treatment for chronic disease treatment
Left by shoes on Dec 15, 2010 4:19 AM

# re: How to write a .NET Control for Microsoft Navision

Left by ssss on Jan 04, 2011 2:00 AM

# clothing manufacturer

Requesting Gravatar...
A more simple approach even for Windows SharePoint Services: The SharePoint Business Data List Connector (BDLC) provides the complete
Left by clothing manufacturer on Mar 06, 2011 3:38 PM

# re: How to write a .NET Control for Microsoft Navision

Requesting Gravatar...
I've got problem wiht Saysomething function.
My code is:
<ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class NavisionControl
Implements INavControl

Public Function SaySomething() As String Implements INavControl.SaySomething
Return "Hi, I'm Alex"


End Class

What is wrong?
Left by Rolladen on Jun 08, 2011 11:58 AM

Your comment:

 (will show your gravatar)
 
Please add 5 and 8 and type the answer here: