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
Here you can see a screen of our code with the jsonParser instantiated

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?
Thanks for posting; I believe the issue is caused by this:
https://github.com/protocolbuffers/protobuf/issues/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.
I downgrading the version of Google.Protobuf to 3.8.0 and it fix the problem!
Thanks!
Most helpful comment
I downgrading the version of Google.Protobuf to 3.8.0 and it fix the problem!
Thanks!