Question

I currently have a helper class that I am using to obfuscate a static class that keeps track of high scores in a game I am working on. I am using Eazfuscator on my release and found that when my scores were being serialized, this exception was thrown:

ArgumentException Identifier ' ' is not CLS-compliant

Is there a way I can store my list of high scores in my helper class and still be able to serialize it after obfuscation?

try
{
  GameHighScore highScoreHelper = new GameHighScore();
  highScoreHelper.CreateGameHighScore(highScore);

  XmlSerializer serializer = new XmlSerializer(typeof(GameHighScore));
  serializer.Serialize(stream, highScoreHelper);
}
catch(Exception e)
{
  Logger.LogError("Score.Save", e);
}

My helper class:

  public class GameHighScore
  {
    
    public List<HighScoreStruct<string, int>> highScoreList;

    private HighScoreStruct<string, int> scoreListHelper;

    [XmlType(TypeName = "HighScore")]
    public struct HighScoreStruct<K, V>
    {
      public K Initials
      { get; set; }

      public V Score
      { get; set; }

      public HighScoreStruct(K initials, V score) : this() 
      {
        Initials = initials;
        Score = score;
      }
    }

    public GameHighScore()
    {
      highScoreList = new List<HighScoreStruct<string, int>>();
      scoreListHelper = new HighScoreStruct<string, int>();
    }

    public void CreateGameHighScore(List<KeyValuePair<string, int>> scoreList)
    {

      for (int i = 0; i < scoreList.Count; i++)
      {
        scoreListHelper = new HighScoreStruct<string, int>(scoreList[i].Key, scoreList[i].Value);
        highScoreList.Add(scoreListHelper);
      }
    }
  }
Was it helpful?

Solution

Best solution would be not to obfuscate classes needed for any kind of serialization. You'll gain 2 benefits of doing so:

  • no strange names will be used for classes
  • re-running obfuscation will not produce new names for the same classes/fields.

Most obfuscators allow to specify attributes that keep particular classes/methods non-obfuscated.

Otherwise - write your own serialization.

OTHER TIPS

Try using the XmlElement attribute on your properties.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top