Options

How to use System.String?

yukonyukon Member Posts: 361
edited 2015-09-21 in NAV Three Tier
Hi Team,

I'm trying to use System.String in NAV2009-R2. I can't assign value to System.String variable. I refered the function "IsValidFileName" of NAV 2013 CU-419(File Management). But 2013 can assign the value. Why can't use in NAV2009-R2? Is it something wrong in my code?
Name	   DataType	Subtype	Length
String	   DotNet	'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.String

String := 'balabala';	
---------------------------
Microsoft Dynamics NAV Classic
---------------------------
Assignment is not allowed for this variable.

Best Regards,
Yukon
Make Simple & Easy

Answers

  • Options
    SigGunnSigGunn Member Posts: 18
    Try adding this code:
    IF ISSERVICETIER THEN
      string := 'balabala'  // should work if running on the application tier, untested
    ELSE
      MESSAGE('Classic client does not support dotnet, use RTC');
    
  • Options
    kinekine Member Posts: 12,562
    Have you tried to use Constructor first to create the string object?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    yukonyukon Member Posts: 361
    kine wrote:
    Have you tried to use Constructor first to create the string object?

    Yes I did. Can't compile object.


    Regards,
    Yukon
    Make Simple & Easy
  • Options
    kinekine Member Posts: 12,562
    Hmmm... yes, the problem with abiquity in different forms of the constructor...

    There are changes in the dotnet interop in NAV 2013 and it looks like they solved some basic problems of the DotNet from 2009. Looks like you hit one...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    yukonyukon Member Posts: 361
    Hi Kine,

    I think some .net variable cannot use directly in NAV. I found at this blog http://navigateintosuccess.com/blog/generics-in-net-interop-for-nav-2013.

    Best Regards,
    Yukon
    Make Simple & Easy
  • Options
    CaponeCapone Member Posts: 125
    I had the same scenario that I needed System.String and the method replace.

    But I managed to find a workaround by using stringbuilder instead :D


    StringBuilder := StringBuilder.StringBuilder(String);
    StringBuilder.Replace('MyOldValue', 'MyNewValue');
    F.WriteAllText(FileName, Stringbuilder.ToString);
    Hello IT, have you tried to turn it off and on?
    Have you checked the cables?
    Have you released the filters?

    http://www.navfreak.com
Sign In or Register to comment.