Skip to content

Clean workaround for wrong special characters in BigText variables

December 22, 2011

In a previous blogpost about webservices i wrote about saving the result of a xmlport to a bigtext variable and the problems with charsets and special characters like ä,ö,ü etc.

Originaly i did a conversion of the whole output from ansi2ascii which worked but was not very performant…

Now with .net Interop we have a very clean an nice way of doing this. Here is the code for it:




StreamReader := StreamReader.StreamReader(XMLInStream, TRUE);

StreamReader is a dotnet variable:

Name DataType Subtype Length
StreamReader DotNet ‘mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’.System.IO.StreamReader

As a result you have the bigtext variable with the correct content, in the correct encoding as you would expect it.


From → Dynamics NAV

  1. Hello,

    when i use this code i get an error on the streamreader line.
    Any idea’s how to fix this?


    Tom Van Mierlo

    • the error is:
      Unknown Type ”.

      • Well can you post the whole code? or better the object you used the code in.
        This should work withotu problems. Does the error occur on compile time or on run time?

      • Costa permalink

        Declare another dotNet variable stream ‘mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089′.System.IO.Stream

        and assign the instream to it.

        stream := XMLInstream;

        and after that instantiate the streamreader with the above variable

        StreamReader := StreamReader.StreamReader(stream, TRUE);

        This worked for me.

    • andy permalink

      hi ! i am same issues on it. your problem is solved already ?

      • Which build are you using? Have you tried my suggestions for Tom Van Mierlo, about trying the latest build, and wrapping -” around the variables? Have you identified the line of code that gives you the problem? Where stands the cursor after the compile error?

      • Tom Van Mierlo permalink

        No, i haven’t found a solution. “Solved” it by not sending any “special characters” to the other side. In my situation, this prevents it of getting them back.

  2. The error occurs on compile.

    My code is:

    PROCEDURE fctConvertBigTextStream@1100084006(VAR pbtxXMLFileIn@1100084000 : BigText;VAR pbtxXMLFileOut@1100084001 : BigText);
    lrecTempBlob@1100084004 : Record 50025;
    linsInStream@1100084003 : InStream;
    lousOutStream@1100084002 : OutStream;
    StreamReader@1100084010 : DotNet “‘mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’.System.IO.StreamReader”;



    StreamReader := StreamReader.StreamReader(linsInStream, TRUE);

  3. Is there any chance you named another variable, function, or anything else “StreamReader”? Otherwise i would try a higher build of NAV 2009 R2 and see if the problem is solved. I know there were problems with the initial realease of 2009 R2 and the dot net interop feature.

    In your code i don’t see any errors i used this multiple times and it always worked.

    But errors like the one you have are usually syntax check errors of the compiler, so there needs to be something wrong with that. Sometimes it helps when you add quotes to your variables like this: “StreamReader”.ReadToEnd()

Trackbacks & Pingbacks

  1. Display Text from a Blob Field in RDLC Report « – man vs. code
  2. Clean workaround for wrong special characters in BigText variables |

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s