DotNet Quick Tip: Accessing members with invalid names

  • Post comments:5 Comments
  • Reading time:3 mins read

A friend asked my by e-mail today about a problem he encountered with DotNet interop: how to access a property of an object, if the property name matches a reserved word in NAV. A simplest example is from the Microsoft.Dynamics.Nav.SMTP.SmtpMessage class that comes bundled with NAV 2013.

Consider this piece of code:

Mail := Mail.SmtpMessage;
Mail.To := 'john.doe@noname.no';

If you try to compile this, it will fail. It’s simple: the To property name is invalid in the C/AL context, because it is a reserved word.

So, how do you fix it?

(more…)

Continue ReadingDotNet Quick Tip: Accessing members with invalid names

Some tips and hints about temporary tables

  • Post comments:9 Comments
  • Reading time:10 mins read

MP900433071[1]Temporary tables in NAV are a great thing, and are frequently used, but there are some misconceptions about them. I see developers do the same mistakes time after time and again. In this post I’ll address some common misconceptions and give some tips and hints that you can use in practice.

There may be a lot of basics for you here, in which case just skip to the end: there I give you a nice tip about how to prevent accidental changes to physical tables when you expect that a table is temporary, and in fact it is not.

(more…)

Continue ReadingSome tips and hints about temporary tables

Generics in .NET Interop for NAV 2013

  • Post comments:25 Comments
  • Reading time:8 mins read

image.NET Framework is full of programming conceptual gems, that are now at the fingertips of us poor C/AL folks. One of those is generics. However, the C/AL support for generics at the first glance seems rather limited, and the help file says that you can’t specify data types, and that all generics will be instantiated with System.Object as their type. However, with Microsoft Dynamics NAV 2013, there is a very simple way which allows you to use generics with other data types, as well. So, if .NET Framework Interoperability interests you a slightest bit, here’s a solution. The example below will be for the System.Collections.Generic.Dictionary<,>, and I will show how to use instances of the Dictionary<,> object with any desired data type, without having to pull in any external assemblies. (more…)

Continue ReadingGenerics in .NET Interop for NAV 2013

Passing strongly-typed data to Web services

  • Post comments:4 Comments
  • Reading time:6 mins read

imagePassing strongly-typed data to NAV Web services can be trickier than it seems. If you are lucky, you can make your method accept strongly-typed parameters, and you are good to go. However, if you just can’t avoid sending text data, your text must be encoded in EN-US format, otherwise it will cause problems (see this).

What the heck, just encode the data as EN-US, right? Not quite. There are a myriad of reasons why data can come in non-EN-US encoding, one of which is this: it’s the Web services, for Pete’s sake – anyone or anything can call them.

(more…)

Continue ReadingPassing strongly-typed data to Web services

The Beauty and The Beast: NAV and .NET

  • Post comments:19 Comments
  • Reading time:23 mins read

imageIf there wasn’t one already, someone should have invented Belgium. There are two things in this world that I love, and probably shouldn’t (and an oversized red speaker’s shirt I got from Luc today did a darned god job at concealing the unlucky consequences of overly indulging in both of them): beer and chocolate. Boy, do Belgians know their beer and chocolate!

But they know their NAV, too, and after NAV TechDays 2011, which have just ended in Antwerp, and two days of top NAV content, I can only say – great job, Luc and the team, and please make it a tradition.

If you attended my presentation about .NET interoperability, then there are a couple of demos I couldn’t deliver due to time constraints, and I promised to blog it. So, here we go.

It’s about streams. You already know that in NAV there are two data types, InStream and OutStream, that allow you to stream data in and out of generic sources or destinations. They are a fantastic tool, because they require you to know nothing about the type of source or destination, and you can store and retrieve data without having to care if the data comes from Internet, or a BLOB field, or is it written to a file, or transported over an XMLport. Stream makes it abstract and allows you to simply handle the data, and make the object itself care about the specifics.

(more…)

Continue ReadingThe Beauty and The Beast: NAV and .NET