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

After my previous post on how to write a .NET control (.NET DLL) to extend Microsoft Navision's functionality, I've received some feedbacks that signalled me a little strange behaviour: when you import your new .NET DLL for using it in Navision, on the C/AL Symbol menu (when you reference the control) you can see all the default COM methods and properties (Equals, GetHashCode,GetType,ToString etc.). This is not so good, I know...

How to solve this?

The key for not exposing all the standard COM methods and properties is to use the DispIdAttribute class, that permits to specify the COM dispatch identifier (DISPID) of a method, field, or property.

You have to modify the source code in my previous post as follow:

  1 Imports System.Runtime.InteropServices
  2 Imports System.Reflection
  3 
  4 <Assembly: AssemblyKeyFileAttribute("sgKey.snk")> 
  5 
  6 Public Interface INavControl
  7     <DispId(1)> _
  8     Function SaySomething() As String
  9 End Interface
 10 
 11 <ClassInterface(ClassInterfaceType.None)> _
 12 Public Class NavisionControl
 13     Implements INavControl
 14     Public Function SaySomething() As String Implements INavControl.SaySomething
 15         Return "Hi, I'm the .NET Control and this comes from my function"
 16     End Function
 17 End Class

and then rebuild the project and register again the control:

After the registration, open your Navision form previously created (exactly like explained on my previous post) and place a reference to the newly created control:

Now, check the exposed methods of this new control:

As you can see, the .NET control expose only the declared method (SaySomething).

More elegant now...

Print | posted on Thursday, November 17, 2005 2:55 PM

Comments on this post

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

Requesting Gravatar...
Are you able to embed .Net controls in Navision so that instead of calling a function in the control we actually display a simple multiline text form?
Left by Ryan on Dec 23, 2005 3:02 PM

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

Requesting Gravatar...
Do you mean a visual control embedded into Navision? Mmmm never tryed it but sounds interesting to try (altough, if I remember correctly, the Navision manual says that you cannot add Visual COM controls into a Navision form). I have to try...
Left by Stefano Demiliani on Dec 23, 2005 4:12 PM

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

Requesting Gravatar...
Left by STEFANO DEMILIANI WeBlog on Jan 05, 2006 9:05 AM

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

Requesting Gravatar...
Thanks for the excellent demonstration.
Is it possible to add an event to the class alongside the already existing method "Saysomething".
Left by Frank Mortensen on Jan 24, 2006 6:32 PM

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

Requesting Gravatar...
Yes,your class can raise events:
Public Class MyClass
Public Event MyEvent()
Public Sub SaySomething()
.....
RaiseEvent MyEvent()
.....
Application.DoEvents()
....
End Sub
End Class
Left by Stefano Demiliani on Jan 25, 2006 12:03 PM

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

Requesting Gravatar...
Thank for the demo.
When defining the automation control, 2 classes will be shown (INavControl and NavisionControl).
Only the NavisionControl-class is working.
Is it possible only to show this class and hide the class INavControl?
Left by Elwin from Holland on Mar 17, 2006 1:04 PM

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

Requesting Gravatar...
No it's not possible because it's the public interface exposed by the control:
Public Interface INavControl
Left by Stefano Demiliani on Mar 17, 2006 1:07 PM

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

Requesting Gravatar...
Can I use Flash objects in the Navision?
Left by Prashant Waykar on Jun 19, 2006 9:44 AM

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

Requesting Gravatar...
I don't think you can use them directly, but you can call a Flash object (stored outside) from Navision.
Left by Stefano Demiliani on Jun 19, 2006 11:09 AM

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

Requesting Gravatar...
is it possible to pass outstream from Navision to .Net?
Left by Luis on Jul 20, 2006 5:23 PM

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

Requesting Gravatar...
Hey,

I created a test.dll and try to use it in navision but, i get an Error in Part 2 (RegAsm)
it say's "RegAsm-Error because is not a valid .NET assembly" can you help me pls?

Regards Schmidt!
Left by Schmidt on Dec 16, 2007 11:20 AM

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

Requesting Gravatar...
Schmidt, are you sure that you're using the correct regSam version?
Sometimes this error occours when the regasm being used was the one from the .NET 1.1 Framework and you're trying to use it with a .NET 2.0 assembly.
You can avoid the problem by simply running the VS 2005 Command Prompt and re-running regasm again.
Left by Stefano Demiliani on Dec 16, 2007 1:55 PM

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

Requesting Gravatar...
Hi, How can we create control that can raise some action on event such as record insert or record delete from Navision?
Left by Stephen on Apr 23, 2008 10:42 AM

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

Requesting Gravatar...
Stephen, you can call a .NET assembly from the OnInsert or OnDelete triggers inside NAV, exactly like my sample.
Left by Stefano Demiliani on Apr 23, 2008 3:18 PM

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

Requesting Gravatar...
Hi, Thanks for the reply.
Is it possible to create control that can "monitor" the data insertion on many/all table? or we must call the .net function on every table's onInsert that we wanted to raise the action?
Left by Stephen on Apr 27, 2008 1:25 AM

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

Requesting Gravatar...
A .NET control that monitor data insertion on every table? This seems to be a feature that must be triggered out of NAV. Maybe you can use SQL Server triggers.
As you may know, triggers are executed as the result of a user action against a table, such as an INSERT, UPDATE or DELETE statement.
To create a trigger using .NET, you need to go through the following steps:
1) Create a .NET class and implement the functionality of the extended trigger within that class.
2) Compile that class to produce a .NET assembly.
3) Register that assembly in SQL Server using the Create Assembly statement.
4) Create trigger definitions.
Here's an article with a sample:
http://www.15seconds.com/issue/041006.htm
Left by Stefano Demiliani on Apr 27, 2008 2:17 PM

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

Requesting Gravatar...
I have a problem! When i compile the project there's an error: Failed to create the assembly manifest: Error reading file key 'sgKey.snk'-The system can not find the specified file! But the file is in the project's folder! And one more thing: there's no AssemblyKeyFileAttribute in my .net threre is only AssemblyKeyFile
Left by johnny on Apr 29, 2008 12:09 PM

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

Requesting Gravatar...
Johnny, try this:
use <Assembly: AssemblyKeyFile("..\..\TestClassLibrary.SNK")>
Left by Stefano Demiliani on Apr 29, 2008 2:25 PM

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

Requesting Gravatar...
Thanks Stefano it's working perfectly! One more thing: i'm using itextsharp.dll and i want to make a control for navision to fill .pdf. I tried your method but when i'm using the methods in navision i get the next error message: "Has not been able to create an instance of the control of OLE or servidor of Automation identified by GUID={memory address}:'ClassLibrary2'.InavControl. That the control OLE or the servidor Automation this properly installed and registered "
Left by Johnny on Apr 30, 2008 12:36 PM

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

Requesting Gravatar...
Seems that the control is not correctly installed on the GAC...
Left by Stefano Demiliani on Apr 30, 2008 4:27 PM

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

Requesting Gravatar...
I've tried the the same thing in 3 different pc's and the same result! There's not another way to instal the control?
Left by johnny on May 05, 2008 11:54 AM

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

Requesting Gravatar...
Is it possible for me to pass the form object in to the .net and so that we can change or modify the form. In other words, we pass in a form name into the .net function, and .net function will do something such as hiding some controls, resizing control of the form.

Thanks and regards,
Stephensaw
Left by Stephensaw on Jun 16, 2008 5:11 PM

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

Requesting Gravatar...
Hi and thanks for a great tutorial. I'm pretty new to the .NET world so I hope this isn't a stupid question...Is is possible to package all of the deployment steps into an installer file so that the control can easily be installed on multiple computers?
Left by Robert on Mar 11, 2009 2:04 PM

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

Requesting Gravatar...
Robert, you can create an MSI package directly with Visual Studio and use it to deploy the control.
Left by Stefano Demiliani on Mar 11, 2009 2:12 PM

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

Requesting Gravatar...
Hi Stefano,
Thanks for your post ! It will be very usefull. B
But I still have a problem. I create the .dll as you tell on you previous post (using VS2008), when I create global variable in Navision with automation, I see the 2 classes INavControl and NavControl.

But when I want to use method, no method are disponible for NavControl Class ? And they are Public defined.

If I Use INavControl, methods will be disponible but when I try to use them I receive the error bellow "Could not create an instance of The OLE control or Automation server identified by GUID={....}1.0:{....}:'NavControl'.INavControl. Check that the OLE control or Automation server is correctly installed and registered."

I don't know what I'm doing wrong ? did you have any ideas ?

Thanks for your help !
Left by Ludovic B on Apr 23, 2009 10:01 AM

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

Requesting Gravatar...
Okay ! I found the problem. Now it works !

In My .dll, when I create project, I linked it to dotnet framework 2.0 ! And dotnet framework 3.5 was installed and running on my Machine.

I only change dotnet framework 2.0 to 3.5 in my project, re-build all and register again .dll and now it works fine !

Thanks for your nice blog Stefano !
Left by Ludovic B on Apr 23, 2009 10:37 AM

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

Requesting Gravatar...
Hi stefano, how can the above example be implemented in VB2005 or VB2008. i have an third party dll that i need to use in NAV. I used the following
Public Declare Function loadEasyclaim Lib "C:\Program Files\bin\MakingClaims" () As Long

but the declare ..lib statement is not valid in an interface class. any suggestions.
Left by joe maz on Sep 21, 2009 6:03 AM

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

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:44 AM

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

Requesting Gravatar...
Hello,


i want to write a *.dll file where navison can talk with my methods en functions.

this is my code.

Imports System.Runtime.InteropServices
Imports System.Reflection
Imports System


<Assembly: AssemblyKeyFileAttribute("sgKey.snk")>


Namespace TestNavision

<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface GeefWoordWeer
<DispId(10001)> Function GeefWoord() As String
End Interface


<Guid("5E0FA85F-8286-485c-9B50-67C5AC155291"), _
ComSourceInterfacesAttribute("TNM.GeefWoordWeer"), _
ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class tnm
Implements GeefWoordWeer


Public Function GeefWoord() As String Implements GeefWoordWeer.GeefWoord
Return "Test functie GeefWoord weer"
End Function

End Class
End Namespace


the
sn -k sgKey.snk => Works and done
tlbexp ... => Works and done
regasm ... => Works and done
gacutil /i => Works and done


When i look into navision (automation object list) i can see the dll but i don't see the
procedures. Can u help me please ??

What's wrong with my code. or what am i doing wrong.

Left by Steven on Oct 22, 2009 5:21 PM

# replica jewelry

Requesting Gravatar...
rocedures. Can u help me please ??

What's wrong with my code. or what am i doing wrong.
Left by replica jewelry on Apr 29, 2010 5:26 AM

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

Requesting Gravatar...
Hi is it possible to create a vb.Net form into Navision?
How can it be done?
Please let me know..
Left by Meera on Jun 29, 2010 12:50 PM

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

Requesting Gravatar...
Hi Stefano,

Thank for this post wihch is very clear and usefull to extend classic NAV client capabilities. I wrote a dll based on your examples, which can show a pdf document (almost) directly in NAV by using a vb form and web browser. The only problem I have is that this vb form is always on top of my NAV form and is not 'linked' to it as I resize or move the NAV form. I really don't know much about vb .net programming, I'm just c/al. Do you have any tips that could help me in my dev ?
Just let me Know and thanks for your nice blog

Left by Gerald on Feb 16, 2011 4:19 PM

# オンラインカジノ

Requesting Gravatar...
I have just visited your site and the info you have covered has been of great interest to me. Now and then I'll stumble across a post like this and I'll recall that there really are still interesting pages on the web.
Left by オンラインカジノ on Apr 05, 2011 7:40 AM

Your comment:

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