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

Bug in the sample code of OnCloudHelloWorld #194

Open
joonjoonjoon opened this issue Sep 8, 2021 · 0 comments
Open

Bug in the sample code of OnCloudHelloWorld #194

joonjoonjoon opened this issue Sep 8, 2021 · 0 comments
Assignees
Labels
Health Triaged Triaged within product health

Comments

@joonjoonjoon
Copy link

The example has the following code, but it throws an InvalidCastException

private static void OnCloudHelloWorld(ExecuteCloudScriptResult result) {
    // CloudScript returns arbitrary results, so you have to evaluate them one step and one parameter at a time
    Debug.Log(JsonWrapper.SerializeObject(result.FunctionResult));
    JsonObject jsonResult = (JsonObject)result.FunctionResult;
    object messageValue;
    jsonResult.TryGetValue("messageValue", out messageValue); // note how "messageValue" directly corresponds to the JSON values set in CloudScript
    Debug.Log((string)messageValue);
}

I fixed it in my project by using the following:

private static void OnCloudHelloWorld(ExecuteCloudScriptResult result) {
    // CloudScript returns arbitrary results, so you have to evaluate them one step and one parameter at a time
    Debug.Log(JsonWrapper.SerializeObject(result.FunctionResult));
    JsonObject jsonResult = (JsonObject)JsonWrapper.DeserializeObject(result.FunctionResult.ToString());
    object messageValue;
    jsonResult.TryGetValue("messageValue", out messageValue); // note how "messageValue" directly corresponds to the JSON values set in CloudScript
    Debug.Log((string)messageValue);
}

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@thomasgu thomasgu added this to the Product Health Q1 milestone Aug 4, 2023
@thomasgu thomasgu added the Health Triaged Triaged within product health label Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Health Triaged Triaged within product health
Projects
None yet
Development

No branches or pull requests

4 participants