string vs text issues

I am doing more WE (Web Edition) work right now and running into various “issues”. I am trying to use nothing but the new framework where I can. So I am using text wherever I can over using strings. the WebRequest has several items that are strings. When I try to pass those items to various methods or properties that are text, I add the .ToText to the end of them to convert them to text. the IDE compiles the code with zero issues nor any warnings.

Now when I run the app on a Linux host (Ubuntu 16.04 - 64bit Virtual Machine) I get an unhandled exception (I catch it in App.UnhandledException that does a System.Debug of the information). The application is compiled for 64-bit. I get the error message of “String must have a known encoding” and it is coming from the "String.$ToText%y%s” and “String_ToText”. This is true even is I do a .DefineEncoding( Endcodings.UTF-8 ) to the string before trying to convert it to a text. I.e. stringURL.DefineEncoding( Encodings.UTF-8 ).ToText.

so I am just running down some rabbit hole right now trying to use the new framework (since it has too many issues with converting string to text & vice versa)? or I am just doing something stupid and doing this drama to myself? Are others having trouble using the new framework with the WebRequest objects?

thanks
—sb

PS> I am using Xojo2017R2

[quote=357470:@scott boss]…
This is true even is I do a .DefineEncoding( Endcodings.UTF-8 ) to the string before trying to convert it to a text. I.e. stringURL.DefineEncoding( Encodings.UTF-8 ).ToText.[/quote]

and if you break this into 2 lines (yeah I know this sounds odd but …)

stringURL.DefineEncoding( Encodings.UTF-8 )
dim stringUrlAsText as Text = strinUrl.ToText

Wondering if this is a case of https://blog.xojo.com/2016/07/15/untie-these-chains-a-riddle/

I have this method

Public Function ToUTF8Text(Extends s As String) as Text Return DefineEncoding(s, Encodings.UTF8).ToText End Function

in a module. I then would use stringURL.toutf8text. Saves a lot of typing (even with autocomplete).

[quote=357477:@Wayne Golding]I have this method

Public Function ToUTF8Text(Extends s As String) as Text Return DefineEncoding(s, Encodings.UTF8).ToText End Function

in a module. I then would use stringURL.toutf8text. Saves a lot of typing (even with autocomplete).[/quote]

Wayne that is a great idea. I wished I thought of that sooner. I will see if that gets me around the string to text issue I am having.

—sb

Have you checked that your string contains valid UTF8? I recently had 2 nice bugs because I had invalid characters. The string module from Kem Tekinay has a function to make valid UTF8 and - of course - the MBS plugin has a function, too, but I don’t remember the name.

[quote=357477:@Wayne Golding]I have this method

Public Function ToUTF8Text(Extends s As String) as Text Return DefineEncoding(s, Encodings.UTF8).ToText End Function

in a module. I then would use stringURL.toutf8text. Saves a lot of typing (even with autocomplete).[/quote]
You ought to add some code to:
0. If s.Encoding = Nil, call DefineEncoding,
0. If s.Encoding <> Encodings.UTF8, call ConvertEncoding
0. Return s.ToText

This will also handle the situation of the encoding already being set and just call ToText on that string.