cs-script
cs-script copied to clipboard
Looks like the csscript doesn't like LINQ or LINQtoXML -> 3.50.5.1 CS-Script.bin
Hi,
currently playing with .Net-Framework 4.7.2
encountered some issues with the csscript. most of them are solved, like the "auto-discards" in 623-625 and "checkForNull" in 896 just by writing it the long way :-)
But unfortunately I cannot solve the LINQtoXML-Part to easy 457-463
I've got the 3.50.5.1 (Nuget) installed, because I'm using .Net-Framework.
Would be great to hear back. Best Regards
` using System; using System.Text; using System.ComponentModel; using System.IO; using System.Linq; using System.Xml.Linq;
457 var infoTags = from info in xDocument.Descendants("info") 458 let description = info.Element("description")?.Value 459 select new 460 { 461 Name = info.Element("name")?.Value, 462 Description = description, 463 Type = GetDescriptionType(description) 463 };
c:...\bin\Release\data.tmp(458,61): error CS1525: Invalid expression term '.' c:...\bin\Release\data.tmp(458,62): error CS1003: Syntax error, ':' expected c:...\bin\Release\data.tmp(459,22): error CS1002: ; expected c:...\bin\Release\data.tmp(461,45): error CS1525: Invalid expression term '.' c:...\bin\Release\data.tmp(461,46): error CS1003: Syntax error, ':' expected
621 static Type GetDescriptionType(string description) 622 { 623 if (bool.TryParse(description, out _)) return typeof(bool); 624 if (int.TryParse(description, out _)) return typeof(int); 625 if (float.TryParse(description, out _)) return typeof(float); 626 return typeof(string); 627 }
c:...\bin\Release\data.tmp(623,40): error CS0103: The name '_' does not exist in the current context c:...\bin\Release\data.tmp(623,9): error CS1502: The best overloaded method match for 'bool.TryParse(string, out bool)' has some invalid arguments c:...\bin\Release\data.tmp(623,40): error CS1503: Argument 2: cannot convert from 'out ' to 'out bool' c:...\bin\Release\data.tmp(624,39): error CS0103: The name '' does not exist in the current context c:...\bin\Release\data.tmp(624,9): error CS1502: The best overloaded method match for 'int.TryParse(string, out int)' has some invalid arguments c:...\bin\Release\data.tmp(624,39): error CS1503: Argument 2: cannot convert from 'out ' to 'out int' c:...\bin\Release\data.tmp(625,41): error CS0103: The name '' does not exist in the current context c:...\bin\Release\data.tmp(625,9): error CS1502: The best overloaded method match for 'float.TryParse(string, out float)' has some invalid arguments c:...\bin\Release\data.tmp(625,41): error CS1503: Argument 2: cannot convert from 'out _' to 'out float'
896 Write?.Invoke("Could not ClearProcessData on OPC" + e.Message); c:...\bin\Release\data.tmp(896,13): error CS1525: Invalid expression term '.' c:...\bin\Release\data.tmp(896,14): error CS1003: Syntax error, ':' expected `
The problem is caused by the fact that you are using the null-conditional operator ?.
, which is not supported by .NET Framework compilers out of the box but by Roslyn only.
You have a few options here:
- Drop the operator and use more verbose syntax
let description = info.Element("description") == null ? null : info.Element("description").Value
- Use Roslyn-based CodeProvider. You will need to configure your cscs.exe to use the
CSSRoslynProvider.dll
compiler. Or just placeCSSRoslynProvider.dll
file in the same folder withcscs.exe
. Though it may also be too old to support this syntax. - Switch to the latest CS-Script version that is .NET Core-based. It supports the latest C# syntax right away.