question

Matt avatar image
Matt asked

SimpleJson throws an Exception serializing

Hey folks,

I've got an issue I can't pinpoint. I'm getting an exception thrown trying to serialize a class I have, but it isn't consistent. If I comment everything out, it's fine...if I let most back in, it may throw the exception, but if I comment one out and another back in, it might still throw that exception. It's not a specific variable it's trying to serialize, but maybe it's a max variable type thing?

The thrown exception is:

Number of parameters specified does not match the expected number.

The code trigger the exception is the line trying to serialize:

string serialized = null;
try
{
	serialized = PlayFabSimpleJson.SerializeObject( m_TitleGameplay );
}
catch( Exception e )
{
	DebugManager.Log( e.Message, true );
}
finally
{
	DebugManager.Log( ( serialized != null ) ? "Success!" : "Failure" );
}

Finally, the class that's being serialized:

public class TitleGameplay
{
	public int version = 0;
	public Difficulty[] difficulties;
	public Perk[] perks;
	public Town[] towns;
	public VendorEvent[] vendorEvents;
	public TravelEvent[] travelEvents;
	public Ailment[] ailments;
	public ReputationData reputationData = new ReputationData();
	public ShopBundle[] shopBundles;
	public Component[][] resourcePack;
	public int adTravelTime = 5000;
	public int chauffeurTravelTime = 5000;
	public float banditGoldPercent = 0.2f;
	public int banditGoldThreshold = 1000;
	public int horsePurchaseCost = 850;
	public float vendorMinDensity = 0.2f;
	public float vendorMaxDensity = 0.4f;
	public float vendorMinImpact = 0.2f;
	public float vendorMaxImpact = 0.8f;
	public int travelMinFrequency = 30;
	public int travelMaxFrequency = 8;
	public float travelMinImpact = 0.2f;
	public float travelMaxImpact = 0.8f;
	public int maxRepBonusStorage = 10;
	public int normalVoucherCost = 75;
	public int premiumVoucherCost = 150;
	public float duplicateRefundPercent = 0.25f;
}

So to be clear, one example was having most things active but a few commented out, it would serialize fine. Then I might uncomment a line (perks was one example, towns was another), making it active again, and it'd failed.

Those classes themselves just have primitive types (or arrays of them).

I appreciate the info, I'm struggling with fixing this problem and it's pretty important right now to get working.

Thanks,

Matt

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt avatar image Matt commented ·

After further examination, it looks like there are specifically 3 variables causing issues (perks, towns, and ailments), and those 3 variables are the only ones with "complex" non-serialized variables.

To be clear, those 3 have either a Color or Sprite variable as follows:

public class Perk
{
	public string id;
	public bool active;
	public int client;
	public int name;
	public int desc;
	public string source;
	public int value;
	public string format;
	public int cost;


	[NonSerialized] public bool live = false;
	[NonSerialized] public Sprite sprite = null;
}

I don't want these sprites serialized, they are *only* for direct, easy access on the client to images or colors associated with these items.

Does anyone understand exactly why a line, like the above, would throw an exception when trying to serialize a class?

0 Likes 0 ·

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

Playfab SimpleJson doesn’t support [NonSerialized] attribute for now. You can posta feature request for it.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.