Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException with request parameters #126

Closed
NickDarvey opened this issue Oct 28, 2019 · 2 comments
Closed

NullReferenceException with request parameters #126

NickDarvey opened this issue Oct 28, 2019 · 2 comments
Milestone

Comments

@NickDarvey
Copy link
Contributor

Description

I'm getting a NullReferenceException while constructing a request to the Slack API using their Swagger definition.

I'm unfamiliar with Type Providers so I'm not sure how to approach debugging it. Right now I'm poking through decompiled IL (see below).

Repro steps

See this test.

Expected behavior

Constructs a request and sends it (at which point it should get a authorization error).

Actual behavior

[21:02:51 ERR] All/TP Slack Tests/call provided methods errored in 00:00:00.0360000 <Expecto>
System.NullReferenceException: Object reference not set to an instance of an object.
   at Swagger.Slack.Tests.Slack.Client.ChatPostEphemeral(Nullable`1 threadTs, String blocks, String attachments, Nullable`1 asUser, String parse, String token, String text, String user, Nullable`1 linkNames, String channel)
   at Swagger.Slack.Tests.slackTests@16.Invoke(Unit unitVar)

Known workarounds

None.

Related information

  • Branch: dev

Decompiled IL of ChatPostEphemeral method

public FSharpAsync ChatPostEphemeral([DefaultParameterValue(null)] [Optional] FSharpOption threadTs = default(FSharpOption), [DefaultParameterValue(null)] [Optional] string blocks = null, [DefaultParameterValue(null)] [Optional] string attachments = null, [DefaultParameterValue(null)] [Optional] FSharpOption asUser = default(FSharpOption), [DefaultParameterValue(null)] [Optional] string parse = null, [DefaultParameterValue(null)] [Optional] string token = null, [DefaultParameterValue(null)] [Optional] string text = null, [DefaultParameterValue(null)] [Optional] string user = null, [DefaultParameterValue(null)] [Optional] FSharpOption linkNames = default(FSharpOption), [DefaultParameterValue(null)] [Optional] string channel = null)
{
    //IL_0014: Unknown result type (might be due to invalid IL or missing references)
    //IL_001b: Unknown result type (might be due to invalid IL or missing references)
    //IL_001c: Unknown result type (might be due to invalid IL or missing references)
    //IL_0026: Unknown result type (might be due to invalid IL or missing references)
    //IL_0027: Expected O, but got Unknown
    //IL_0036: Unknown result type (might be due to invalid IL or missing references)
    //IL_003b: Unknown result type (might be due to invalid IL or missing references)
    //IL_0040: Expected O, but got Unknown
    //IL_005f: Unknown result type (might be due to invalid IL or missing references)
    //IL_0064: Unknown result type (might be due to invalid IL or missing references)
    //IL_0069: Expected O, but got Unknown
    //IL_0088: Unknown result type (might be due to invalid IL or missing references)
    //IL_008d: Unknown result type (might be due to invalid IL or missing references)
    //IL_0092: Expected O, but got Unknown
    //IL_00a1: Unknown result type (might be due to invalid IL or missing references)
    //IL_00a3: Expected O, but got Unknown
    //IL_00b2: Unknown result type (might be due to invalid IL or missing references)
    //IL_00b7: Unknown result type (might be due to invalid IL or missing references)
    //IL_00bc: Expected O, but got Unknown
    //IL_00dc: Unknown result type (might be due to invalid IL or missing references)
    //IL_00e1: Unknown result type (might be due to invalid IL or missing references)
    //IL_00e6: Expected O, but got Unknown
    //IL_0106: Unknown result type (might be due to invalid IL or missing references)
    //IL_010b: Unknown result type (might be due to invalid IL or missing references)
    //IL_0110: Expected O, but got Unknown
    //IL_0130: Unknown result type (might be due to invalid IL or missing references)
    //IL_0135: Unknown result type (might be due to invalid IL or missing references)
    //IL_013a: Expected O, but got Unknown
    //IL_0149: Unknown result type (might be due to invalid IL or missing references)
    //IL_014b: Expected O, but got Unknown
    //IL_015a: Unknown result type (might be due to invalid IL or missing references)
    //IL_015f: Unknown result type (might be due to invalid IL or missing references)
    //IL_0164: Expected O, but got Unknown
    //IL_0184: Unknown result type (might be due to invalid IL or missing references)
    //IL_0189: Unknown result type (might be due to invalid IL or missing references)
    //IL_018e: Expected O, but got Unknown
    //IL_01cc: Unknown result type (might be due to invalid IL or missing references)
    //IL_01d4: Unknown result type (might be due to invalid IL or missing references)
    //IL_01d6: Unknown result type (might be due to invalid IL or missing references)
    //IL_01db: Unknown result type (might be due to invalid IL or missing references)
    //IL_01e0: Expected O, but got Unknown
    //IL_02d5: Unknown result type (might be due to invalid IL or missing references)
    //IL_02db: Unknown result type (might be due to invalid IL or missing references)
    //IL_02e0: Unknown result type (might be due to invalid IL or missing references)
    //IL_02ee: Unknown result type (might be due to invalid IL or missing references)
    //IL_02ef: Unknown result type (might be due to invalid IL or missing references)
    //IL_02f4: Unknown result type (might be due to invalid IL or missing references)
    //IL_02f9: Expected O, but got Unknown
    //IL_0303: Unknown result type (might be due to invalid IL or missing references)
    Type obj = typeof(FSharpMap);
    FSharpFunc mapping = new Lambda40e03960-767e-479d-9bc5-59dcf2b14dc6();
    IEnumerable<KeyValuePair<string, string>> nameValueCollection = (IEnumerable<KeyValuePair<string, string>>)new Lambda133ea8de-40e5-49fe-a698-cd8882350d21
    {
        mapping = mapping
    }.Invoke((!0)SeqModule.Append<Tuple<string, string>>(SeqModule.Append<Tuple<string, string>>(SeqModule.Append<Tuple<string, string>>(SeqModule.Append<Tuple<string, string>>(SeqModule.Append<Tuple<string, string>>(SeqModule.Append<Tuple<string, string>>(SeqModule.Append<Tuple<string, string>>(SeqModule.Append<Tuple<string, string>>(Operators.CreateSequence<Tuple<string, string>>((IEnumerable<Tuple<string, string>>)FSharpList.Cons((!0)new Tuple<string, string>("thread_ts", ((object)threadTs).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons((!0)new Tuple<string, string>("blocks", ((object)blocks).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons((!0)new Tuple<string, string>("attachments", ((object)attachments).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons((!0)new Tuple<string, string>("as_user", ((object)asUser).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons((!0)new Tuple<string, string>("parse", ((object)parse).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons((!0)new Tuple<string, string>("text", ((object)text).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons((!0)new Tuple<string, string>("user", ((object)user).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons((!0)new Tuple<string, string>("link_names", ((object)linkNames).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons((!0)new Tuple<string, string>("channel", ((object)channel).ToString()), FSharpList.get_Empty())));
    string uri = RuntimeHelpers.combineUrl("http://fake-host/", RuntimeHelpers.combineUrl("/api", "/chat.postEphemeral"));
    UriBuilder uriBuilder = new UriBuilder(uri);
    Lambda8df8c1b2-2dcc-4850-88fd-5bd49e0efc14 lambda8df8c1b2-2dcc-4850-88fd-5bd49e0efc = new Lambda8df8c1b2-2dcc-4850-88fd-5bd49e0efc14();
    FSharpFunc mapping2 = new Lambda1713dcb0-a6d1-4fe4-8f00-9b1312711f3a();
    string text2 = (string)lambda8df8c1b2-2dcc-4850-88fd-5bd49e0efc.Invoke((!0)new Lambdaa3d9630b-db31-40c0-99c7-d96b0dd770fb
    {
        mapping = mapping2
    }.Invoke((!0)FSharpList.get_Empty()));
    if (string.IsNullOrEmpty(uriBuilder.Query))
    {
        uriBuilder.Query = text2;
    }
    else
    {
        uriBuilder.Query = string.Format("{0}&{1}", (object)uriBuilder.Query, (object)text2);
    }
    string uriString = uriBuilder.Uri.ToString().Substring("http://fake-host/".Length);
    HttpMethod method = new HttpMethod("POST");
    HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, new Uri(uriString, UriKind.Relative))
    {
        Content = (HttpContent)new FormUrlEncodedContent(nameValueCollection)
    };
    RuntimeHelpers.fillHeaders(httpRequestMessage, (IEnumerable<Tuple<string, string>>)ArrayModule.Append<Tuple<string, string>>((1 == 0) ? new Tuple<string, string>[0] : new Tuple<string, string>[1]
    {
        new Tuple<string, string>("Content-Type", "application/json")
    }, new Tuple<string, string>[1]
    {
        new Tuple<string, string>("token", ((object)token).ToString())
    }));
    FSharpAsync x = this.CallAsync(httpRequestMessage);
    return RuntimeHelpers.asyncCast(obj, new Lambda2812a87e-1602-4572-8f53-405ee1f7458c
    {
        @this = this,
        x = x
    }.Invoke((!0)ExtraTopLevelOperators.get_DefaultAsyncBuilder()));
}

Though I'm not sure how useful this is as even though I've added the DLLs to ILSpy I'm getting...

// SwaggerProvider.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
	// Assembly reference loading information:
	// There were some problems during assembly reference load, see below for more information!
	// Error: Could not find reference: SwaggerProvider.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
	// Info: Success - Found in Assembly List
sergey-tihon added a commit that referenced this issue Oct 29, 2019
@sergey-tihon
Copy link
Member

I think that I know what is wrong here... 😢

you call it with null in runtime

          slack.ChatPostEphemeral(
            threadTs = None, //  <--- here is null in runtime
            blocks = "",
            attachments = "",
            asUser = None, //  <--- here is null in runtime
            parse = "",
            token = "",
            text = "Hello",
            user = "UNL9PF6P6",
            linkNames = None, //  <--- here is null in runtime
            channel = "CPDMKJR34") |> Async.Ignore

but when I transform it to FormUrlEncodedContent payload I assume it is not null and call .ToString() on all objects

        (!0)new Tuple<string, string>("thread_ts", ((object)threadTs).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons(
        (!0)new Tuple<string, string>("blocks", ((object)blocks).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons(
        (!0)new Tuple<string, string>("attachments", ((object)attachments).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons(
        (!0)new Tuple<string, string>("as_user", ((object)asUser).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons(
        (!0)new Tuple<string, string>("parse", ((object)parse).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons(
        (!0)new Tuple<string, string>("text", ((object)text).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons((
        !0)new Tuple<string, string>("user", ((object)user).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons(
        (!0)new Tuple<string, string>("link_names", ((object)linkNames).ToString()), FSharpList.get_Empty())), (IEnumerable<Tuple<string, string>>)FSharpList.Cons(
        (!0)new Tuple<string, string>("channel", ((object)channel).ToString()), FSharpList.get_Empty())));

there is no workaround rather than provide Some
I will try to fix this in the next versions

sergey-tihon added a commit that referenced this issue Oct 30, 2019
@NickDarvey
Copy link
Contributor Author

Ohh that'd be it. Thank you so much!

@sergey-tihon sergey-tihon added this to the v0.10.0 milestone Nov 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants