The following code has only thrown a NullReferenceException a few times in the last few months, but I'm not quite sure why. The code is not mine, but it looks pretty straight to me.
Type pageType = page.GetType(); if (_pages.TryGetValue(pageType, out value)) return value;
[NullReferenceException: object reference not set to instance object.] System.Collections.Generic.Dictionary 2.Insert(TKey key, TValue value, Boolean add) +210 System.Collections.Generic.Dictionary 2.set_Item (TKey key, TValue value) +11
The only thing I can think of is that pageType is null when it is used as a dictionary key, but it seems impossible .
The code that calls it is simple:
protected override void OnLoad(EventArgs e) { base.OnLoad(e); _mypage = GetPage(); }
I also thought that the error could be with _section.Pages , but the section is never null and never sets anything. If .Pages[page] returns null, the MyPage constructor simply returns. So what am I missing?
source share