Dynamics NAV 2009 R2: DotNet System.String

21 Sep

If you are having the need to use DotNet in an older client such as Dynamics NAV 2009 R2 you will problably run into troubles which they have fixed for later versions of Dynamics NAV.  I had the problem that I tried to downgrade code using the DotNet type System.String. I didn’t get very far until the compiler started to complain…

I can’t assign any values to my variable. Instead I get “Assignment is not allowed for this variable“. Hmmm.. But then I tried to use another methods to add values to my System.String variable.

I looked at the System.String on msdn and found the method Insert. So how about Variable.Insert(0, <MyString>) ?
Unfortunately that didn’t work either. The error I received was “The DotNet variable has not been instantiated“.

Okay, how about using the constructors? Well that didn’t work either. The solution became to use StringBuilder instead (System.Text.StringBuilder). I could use that as a string container and it also had the method that I was looking for in the first place, Replace.

So I replaced my Original code:

DotNetSystemString := DotNetSystemIOFile.ReadAllText(FileName);
DotNetSystemString := DotNetSystemString.Replace('OldText','NewText');

DotNetSystemTextStringBuilder := DotNetSystemTextStringBuilder.StringBuilder(DotNetSystemIOFile.ReadAllText(FileName));

I hope that helps you.

Leave a comment

Posted by on 2015-09-21 in Okategoriserade


Tags: , , , ,

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 )

Facebook photo

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

Connecting to %s

The BC Docs Librarian

Tips and news for AL programmers

Stefan Maroń

Dynamics 365 Business Central

James Pearson

Thoughts about Dynamics 365 Business Central, Git, Azure DevOps, PowerShell, Automated Testing, Visual Studio Code...and maybe some other stuff

Roberto Stefanetti BLOG

MVP & MCT Microsoft Dynamics 365 Business Central, Powershell, Azure, SQL Server


DevOps starts with culture!

Comments for DevOps ABCs Blog

Reflections from the ERP field

DevOps ABCs Blog

Reflections from the ERP field

Dynamics 365 Business Central for Partners

Reflections from the ERP field

Freddys blog

Learn something new... - then Teach someone!

Stefano Demiliani Technical Blog

Reflections from the ERP field

David Worthington's NAV Performance Blog

Micosoft Dynamics NAV Performance Testing & Optimization

Freddys Blog

Reflections from the ERP field

Marije Brummel Blog | Business Central, Azure and more...

Design Patterns, Performance, Clean Code

Ideas in the cloud

Goprowe AB

Reflections from the ERP field


Reflections from the ERP field

The NAV Viking´s Blog

- Sharing my experience in the Dynamics NAV world

Comments for

Reflections from the ERP field

Nav Can Be Fun

Its Really Fun to Work with Microsoft Dynamics Nav / D365 Business Central

%d bloggers like this: