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

WebhookReflection Error when parsing webhook request in ASP.NET WebApi #3445

Closed
Smokechickensss opened this issue Sep 16, 2019 · 2 comments
Closed
Assignees
Labels
status: blocked Resolving the issue is dependent on other work. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@Smokechickensss
Copy link

Hello,
we are testing the Dialogflow Standard edition in order to make a simple chatbot that will communicate with a webhook in a ASP.NET website.
The chatbot is working but we have a problem with the c# code to parse the webhook request.

We have built the webhook following the specification and the c# library but we still getting an error when trying to parse the request body into a WebhookRequest object from Google.Cloud.Dialogflow.V2 library.

The problem is when we try to parse the json using the Google.Protobuf. JsonParser object instantiated like this example here: https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Dialogflow.V2/index.html#web-hook-template-code-for-aspnet-classic-web-api

The request sent by Dialogflow is the following:


{
  "responseId": "cabd446a-02f8-4cbf-88e7-332a18a34069-ad9426ce",
  "queryResult": {
    "queryText": "test",
    "action": "action_name",
    "parameters": {
    },
    "allRequiredParamsPresent": true,
    "fulfillmentText": "fallback text message",
    "fulfillmentMessages": [{
      "text": {
        "text": ["fallback text message"]
      }
    }],
    "intent": {
      "name": "projects/pard-1547211051241/agent/intents/d349eaa4-adc7-441a-9b6d-d250462a7e29",
      "displayName": "test"
    },
    "intentDetectionConfidence": 1.0,
    "languageCode": "en"
  },
  "originalDetectIntentRequest": {
    "payload": {
      "userId": "21fb1710-04a4-4c7a-9bf2-771af3c6e36e"
    }
  },
  "session": "projects/pard-1547211051241/agent/sessions/123456789"
}

We have tryied many times with different solution (also with Newtonsoft Json).
In our code we are getting this error:

The type initializer for 'Google.Cloud.Dialogflow.V2.WebhookReflection' threw an exception.

At this line of code: var request = jsonParser.Parse(json);

Here you can see a screen of our code with the jsonParser instantiated
code

All the packages and dependencies were downloaded by NuGet package manager like the suggest in the guide here: https://cloud.google.com/dialogflow/docs/quick/setup#lib

Here you can see all the packages versions:


<packages>
  <package id="Google.Api.CommonProtos" version="1.7.0" targetFramework="net472" />
  <package id="Google.Api.Gax" version="2.9.0" targetFramework="net472" />
  <package id="Google.Api.Gax.Grpc" version="2.9.0" targetFramework="net472" />
  <package id="Google.Apis" version="1.40.2" targetFramework="net472" />
  <package id="Google.Apis.Auth" version="1.40.2" targetFramework="net472" />
  <package id="Google.Apis.Core" version="1.40.2" targetFramework="net472" />
  <package id="Google.Cloud.Dialogflow.V2" version="1.0.0" targetFramework="net472" />
  <package id="Google.LongRunning" version="1.1.0" targetFramework="net472" />
  <package id="Google.Protobuf" version="3.9.1" targetFramework="net472" />
  <package id="Grpc" version="2.24.0-pre1" targetFramework="net472" />
  <package id="Grpc.Auth" version="1.22.0" targetFramework="net472" />
  <package id="Grpc.Core" version="2.24.0-pre1" targetFramework="net472" />
  <package id="Grpc.Core.Api" version="2.24.0-pre1" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net472" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net472" />
  <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net472" />
  <package id="System.Buffers" version="4.4.0" targetFramework="net472" />
  <package id="System.Interactive.Async" version="3.2.0" targetFramework="net472" />
  <package id="System.Memory" version="4.5.3" targetFramework="net472" />
  <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
</packages>

Here you can also find the complete stacktrace of the error.
error.txt

Seems that the error occur when the parser is trying to parse the WebhookRequest message descriptor and somewhere it fails with an System.IndexOutOfRangeException

Can you please help us to find and fix the problems? Is this error related to a specific release of the Google.Cloud.Dialogflow.V2 or Protobuf libraries?

@Smokechickensss Smokechickensss changed the title WebhookReflection Error when parsing webhook request WebhookReflection Error when parsing webhook request in ASP.NET WebApi Sep 16, 2019
@jskeet
Copy link
Collaborator

jskeet commented Sep 16, 2019

Thanks for posting; I believe the issue is caused by this:
protocolbuffers/protobuf#6509

Please could you try downgrading your version of Google.Protobuf to 3.8.0? I believe that will fix the problem. Unfortunately I think it will be a little while before this is released in a later version of Google.Protobuf - looking at the issue and PRs, I suspect it will only be fixed in 3.11.0, as the branch for 3.10.0 has already been cut.

@jskeet jskeet self-assigned this Sep 16, 2019
@jskeet jskeet added status: blocked Resolving the issue is dependent on other work. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 16, 2019
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Sep 17, 2019
@Smokechickensss
Copy link
Author

Smokechickensss commented Sep 17, 2019

I downgrading the version of Google.Protobuf to 3.8.0 and it fix the problem!
Thanks!

@jskeet jskeet closed this as completed Sep 17, 2019
@jskeet jskeet removed the triage me I really want to be triaged. label Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: blocked Resolving the issue is dependent on other work. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants