Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • Bugs /
avatar image
Question by Mehdi Boumendjel · Jan 06, 2020 at 03:01 AM · CloudScriptunity3d

InvalidCastException: Specified cast is not valid.

Hi folks,

I've been following a tutorial on implementing PlayFab in Unity, and until now I really love it.

I'm having an issue for cloud functions

Console logs an error :

InvalidCastException: Specified cast is not valid.


PlayFabController.OnCloudUpdateStats (PlayFab.ClientModels.ExecuteCloudScriptResult result) (at Assets/Scripts/PlayFabController.cs:175)
PlayFab.Internal.PlayFabHttp+<>c__DisplayClass23_0`1[TResult].<_MakeApiCall>b__1 () (at Assets/PlayFabSdk/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:217)
PlayFab.Internal.PlayFabUnityHttp.OnResponse (System.String response, PlayFab.Internal.CallRequestContainer reqContainer) (at Assets/PlayFabSdk/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:245)
UnityEngine.Debug:LogException(Exception)
PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer) (at Assets/PlayFabSdk/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:249)
PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/PlayFabSdk/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:196)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

The error brings me to my OnCloudUpdateStats()

private static void OnCloudUpdatePlayerStats(ExecuteCloudScriptResult result)
    {
        // Cloud Script 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 Cloud Script
        Debug.Log((string)messageValue);
    }

From the Documentation : https://api.playfab.com/docs/tutorials/landing-automation/writing-custom-cloud-script

It seems that the Documentation uses the deprecated JsonWrapper and also doesn't seem to mention the need of:

using PlayFab.Json;

EDIT - SOLVE :

I had to replace that line :

Debug.Log(JsonWrapper.SerializeObject(result.FunctionResult));

with

Debug.Log(PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer));
Comment

People who like this

0 Show 1
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sarah Zhang · Jan 06, 2020 at 07:37 AM 0
Share

Congratulations, we will accept your solution as the answer.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Jeremy Rose · Jan 20, 2020 at 01:36 AM

This isn't correct either. It should actually be

Debug.Log(PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(result));

To actually serialize the result.

But you can also use this which does the same thing.

Debug.Log(result.ToJson());
,

That isn't really correct either It should be

Debug.Log(PlayFab.PluginManager.GetPlugin<ISerializerPlugin>PluginContract.PlayFab_Serializer).SerializeObject(result));

To actually serialize the result.

But there is also this method which does the same thing.

Debug.Log(result.ToJson());
Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    My Cloud Scripts for iOS builds suddenly stop working mid game. 3 Answers

    CloudScript execution API requests issued (triggered action)), bug or how does it works? 1 Answer

    title_player_account PlayFabId does not work with cloud script 1 Answer

    CloudScript executed from Player dashboard returns unreadable response 1 Answer

    Underscore char being used as separator when parsing event data. 0 Answers

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges