Skip to content

Specified method is not supported - Operators.op_Subtraction[T1,T2,T3](T1 x, T2 y) #206

@sergey-tihon

Description

@sergey-tihon

Description

for loop used in quotation compiles but fails at runtime with exception

System.NotSupportedException: Specified method is not supported.
at Microsoft.FSharp.Core.Operators.op_Subtraction[T1,T2,T3](T1 x, T2 y)
at Lambda30cb63ff-f943-4fb8-8bb4-125c35c8a163.Invoke(Unit )
at Microsoft.FSharp.Control.AsyncBuilderImpl.callA@522.Invoke(AsyncParams`1 args)

the quotation is

<@
       ...
       for (name, value) in %heads do msg.Headers.Add(name, value)
       msg 
@>

Actual behavior

Error message on Mono is even less readable

System.NotSupportedException: Specified method is not supported.
  at Lambdaae052712-1c22-4799-9b8d-5860aa66eb67.Invoke (Microsoft.FSharp.Core.Unit ) [0x00175] in <5a91431651cfe594a74503831643915a>:0 
  at Microsoft.FSharp.Control.AsyncBuilderImpl+callA@522[b,a].Invoke (Microsoft.FSharp.Control.AsyncParams`1[T] args) [0x00051] in <5a7d678a904cf4daa74503838a677d5a>:0 

Known workarounds

Rewrite loop using Seq.iter. Following code works

<@
     %heads
     |> Seq.iter (fun (name, value) ->
          msg.Headers.Add(name, value)
      )
     msg 
@>

Related information

More details are here -fsprojects/SwaggerProvider#105 (comment)

Generated code decompiled to C#

Tuple<string, string>[] array = (!Operators.Not(flag) || 1 == 0) ? ((ProvidedSwaggerBaseType)client).Headers : ArrayModule.Append(new Tuple<string, string>[1]
		{
			new Tuple<string, string>("Content-Type", "application/json")
		}, ((ProvidedSwaggerBaseType)client).Headers);
int num = 0;
while (true)
{
    if (num > ArrayModule.Length(array) - 1)
    {
        break;
    }
    Tuple<string, string> array2 = LanguagePrimitives.IntrinsicFunctions.GetArray(array, num);
    string item = array2.Item2;
    string item2 = array2.Item1;
    httpRequestMessage.Headers.Add(item2, item);
    num++;
}

IL code of the loop

IL_0167: stloc.s 12
IL_0169: ldc.i4.0
IL_016a: stloc.s 15
// loop start (head: IL_016c)
    IL_016c: ldloc.s 15
    IL_016e: ldloc.s 12
    IL_0170: call int32 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Length<class [mscorlib]System.Tuple`2<string, string>>(!!0[])
    IL_0175: ldc.i4.1
    IL_0176: call !!2 [FSharp.Core]Microsoft.FSharp.Core.Operators::op_Subtraction<int32, int32, int32>(!!0, !!1)
    IL_017b: bgt.s IL_01b2

    IL_017d: ldloc.s 12
    IL_017f: ldloc.s 15
    IL_0181: call !!0 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::GetArray<class [mscorlib]System.Tuple`2<string, string>>(!!0[], int32)
    IL_0186: stloc.s 16
    IL_0188: ldloc.s 16
    IL_018a: call instance !1 class [mscorlib]System.Tuple`2<string, string>::get_Item2()
    IL_018f: stloc.s 17
    IL_0191: ldloc.s 16
    IL_0193: call instance !0 class [mscorlib]System.Tuple`2<string, string>::get_Item1()
    IL_0198: stloc.s 18
    IL_019a: ldloc.s 11
    IL_019c: call instance class [System.Net.Http]System.Net.Http.Headers.HttpRequestHeaders [System.Net.Http]System.Net.Http.HttpRequestMessage::get_Headers()
    IL_01a1: ldloc.s 18
    IL_01a3: ldloc.s 17
    IL_01a5: call instance void [System.Net.Http]System.Net.Http.Headers.HttpHeaders::Add(string, string)
    IL_01aa: ldloc.s 15
    IL_01ac: ldc.i4.1
    IL_01ad: add
    IL_01ae: stloc.s 15
    IL_01b0: br.s IL_016c
// end loop

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions