-1

have this C# code

string[] statuses = { "created", "paid", "pending", "authorized", "shipping", "completed", "canceled", "expired" };
string status = "pending";
if (Array.Exists(statuses, element => element == status.Trim())){
    context.Response.Write("match!");
}

it is inside *.ashx file. Tested on two IIS servers, on the first one it works fine, but on the second - have this error

Compiler Error Message: CS1525: Invalid expression term '>'

I am newbie in .net, but looks like compiler there think that > is the part of lambda expression, while expression should only start after =>, can somebody explain to me, please, why this happens and where I am wrong? Thanks.

crang crang
  • 77
  • 1
  • 7
  • You have dynamic compilation set up, where you only provide the source of the HTTP handler? Do you use same compiler version on both servers? – GSerg Dec 06 '19 at 10:39
  • @GSerg unfortunately I have no access to those servers, just made ashx file and gave it to the owner, he gave me two links, one working and another - not – crang crang Dec 06 '19 at 10:42
  • One solution is to precompile and give the dll with the ashx file. Another is to put something like [this](https://stackoverflow.com/a/40360029/11683) in the web.config that is alongside the ashx. – GSerg Dec 06 '19 at 11:09
  • May I know whether you are deploying the handler on a legacy web server which only support c# 2.0? – Jokies Ding Dec 09 '19 at 05:46

1 Answers1

1

In order to avoid using lambda you could use this:

if (statuses.Contains(status.Trim()))
    context.Response.Write("match!");
Gleb
  • 1,723
  • 1
  • 11
  • 24
  • ``statuses`` is array, so I need to do it in the loop, but idea was clear, thank you – crang crang Dec 06 '19 at 10:58
  • @crangcrang array is IEnumerable. [Nothing stops you from using it with Linq .Contains](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/linq-to-objects) – Gleb Dec 06 '19 at 11:05