1

I'm using protobuf-net in WP7 to serialize my data.

I initialize my custom types at launch of app, but I have a big problem:

If I launch my app in the background (tombstoning) for a few minutes, when the app then becomes active an exception is thrown as I haven't initialised the types.

Does anyone have a solution to this problem? Thank you!

SOLUTION:

I resolved the problem like this:

    private void Application_Activated(object sender, ActivatedEventArgs e)
    {
        if (!e.IsApplicationInstancePreserved)
        {
          // add types

          // RuntimeTypeModel.Default.Add(......);
        }
    }
Anton Sizikov
  • 9,105
  • 1
  • 28
  • 39
Stefano
  • 43
  • 5
  • 1
    "it throws exceptions as I don't have initialize the types" can you be more specific about the exceptions you are seeing? full error messages would be ideal – Marc Gravell Oct 23 '12 at 14:37
  • One reason for this can be that wp7 "hibernate" of your app after some inactivity, maybe? If so try to attach to some "restore" (i did not know exact name of such event) event and re-run initialization of your custom types. – psulek Oct 23 '12 at 14:40
  • Put the "solution" in an answer below instead of as an edit. It's good info for others, and this way the question can get marked as "answered" – ctacke Oct 23 '12 at 18:39
  • Post your solution as an answer. – Anton Sizikov Oct 24 '12 at 11:56

1 Answers1

2

I resolved the problem like this:

    private void Application_Activated(object sender, ActivatedEventArgs e)
    {
        if (!e.IsApplicationInstancePreserved)
        {
           // add types
           RuntimeTypeModel.Default.Add(...);
        }
    }
Stefano
  • 43
  • 5
  • 1
    You shouldn't need to do this; if you are using the `Serializer.*` methods, then it will automatically add things as needed. However! I should also emphasize that this will be sub-optimal, as it suggests you are using the "full" engine. To get the best performance on WP7, it is recommended to use "precompiler" and the "core" engine. See "What Files Do I Need.txt" – Marc Gravell Oct 25 '12 at 08:23