InvalidOperationException in SerializationHelper.cs when deserializing items

Mar 9, 2011 at 9:24 PM

Hello everybody,

I use Sterling in my project. It's gorgeous but right now I have problems with it inside my Windows Phone 7 project.
When loading lots of database items, the program throws InvalidOperationException in SerializationHelper.cs. Revision 73744 but happened before as well.

Traceback:

System.InvalidOperationException was unhandled
  Message=NotSupportedException
  StackTrace:
       at System.RuntimeType.get_GUID()
       at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
       at System.Collections.Generic.List`1.Enumerator.MoveNext()
       at Wintellect.Sterling.Serialization.SerializationHelper.Load(Type type, Object key, BinaryReader br, CycleCache cache)
       at Wintellect.Sterling.Database.BaseDatabaseInstance.Load(Type type, Object key, CycleCache cache)
       at Wintellect.Sterling.Database.BaseDatabaseInstance.Load(Type type, Object key)
       at Wintellect.Sterling.Database.BaseDatabaseInstance.Load[T](Object key)
       at I_RSS.UI.Models.MainViewModel.GetNewArticlesAsync(Object o)
       at System.Threading.ThreadPool.WorkItem.doWork(Object o)
       at System.Threading.Timer.ring()

The exception happens in SerializationHelper.cs, line 362.

// now iterate
foreach (var p in _propertyCache[type])
{
    p.SetMethod(instance, _Deserialize(br, cache));
}

In most cases it happens when waking up the application from hibernation, precisely after navigation back to the main page where it starts loading and displaying items. The job is being done from another thread (using ThreadPool.QueueUserWorkItem()). It's possible that more than one thing is being loaded at one time (there are more functions like this) - but there wasn't any problem before. Let me show you some code I use.

ThreadPool.QueueUserWorkItem(GetNewArticlesAsync, new object[] { onlyUnread, callback });
...
void GetNewArticlesAsync(object o)
        {
            var returnedObject = o as Object[];
            bool onlyUnread = (bool)returnedObject[0];
            var callback = returnedObject[1] as CompletedCallback;

                var query = from Article in App.Database.Query<Article, bool, DateTime, Guid>(FeedsDatabase.ARTICLE_NEW)
                            where Article.Index.Item1 == true
                            orderby Article.Index.Item2 descending
                            group Article by Article.Index.Item2.Date into g
                            select new { Key = g.Key, Items = g };

                foreach (var group in query)
                {
                    if (GlobalThings.ApplicationClosing)
                        return;

                    var newGroup = new Group<Article>(group.Key);
                    Threads.SafeDispatch(() =>
                    {
                        NewArticles.Add(newGroup);
                    });
                    foreach (var article in group.Items)
                    {
                        //var currentArticle = App.Database.Load<Article>(article.Key);
                        var currentArticle = article.LazyValue.Value;
                        if (onlyUnread)
                        {
                            if (currentArticle.IsUnread)
                            {
                                Threads.SafeDispatch(() =>
                                {
                                    newGroup.Add(currentArticle);
                                });
                            }
                        }
                        else
                        {
                            Threads.SafeDispatch(() =>
                            {
                                newGroup.Add(currentArticle);
                            });
                        }
                    }
                    if (group.Items.Count() < 1)
                    {
                        Threads.SafeDispatch(() =>
                        {
                            NewArticles.Remove(newGroup);
                        });
                    }
                }        
        }

If you can find out where is the problem, I will be very pleased.

Thank you very much for your time. Otherwise, Sterling seems to be almost perfect for my needs. It is really useful.

Paul

 


Mar 9, 2011 at 9:45 PM
Edited Mar 9, 2011 at 9:46 PM

Ensure that you have the latest version of Sterling.

This looks like an error I had months ago and was fixed.

http://sterling.codeplex.com/discussions/233327

Mar 10, 2011 at 11:50 AM

I have the latest version. I've tried to remove Sterling and then include it again to the project but unfortunately nothing changed. The error happens mainly when loading from a large database (500+ articles).

Coordinator
Mar 10, 2011 at 11:58 AM

It's tough to try to analyze it with so little information. I'd need to see the definitions of the tables/keys/indexes, understand what the data in the database looked like and see the full scenario. There shouldn't be an issue with multiple loads because Sterling locks the path it writes to but there may be some interesting scenarios going on we just haven't run into and had to address yet. If there is any way you can duplicate it in a smaller test case or use the contact form to send me some code to replicate the scenario, I can dig into it deeper.

It looks like it is choking on the iterator as it walks the object so I'm wondering if perhaps you changed the properties on the type and this is what is causing issues? If you clear isolated storage and run it again does the issue still happen? Have you profile memory to see if maybe that is an issue?

Mar 10, 2011 at 3:20 PM

Jeremy, I've send a message with a piece of my project to you through the contact form. Hoping it will help you somehow to find the cause of the problem.