alfah
alfah

Reputation: 2085

InvalidProgramException - Stacktrace

I have received the following stacktrace. But I cannot figure out which function from which class has raised this. Can anyone tell me what MainPage..ctor is??

"Frame Image Function Offset

0 coredll.dll xxx_RaiseException 19

1 mscoree3_7.dll 520892

2 mscoree3_7.dll 461967

3 mscoree3_7.dll 534468

4 TransitionStub 0

5 System.InternalTimeZoneInfo.TransitionTimeToDateTime 520

6 System.InternalTimeZoneInfo.GetDaylightTime 100

7 System.InternalTimeZoneInfo.GetIsDaylightSavingsFromUtc 128

8 System.InternalTimeZoneInfo.GetUtcOffsetFromUtc 500

9 System.DateTime.ToLocalTime 164

10 System.DateTime.get_Now 72

11 System.DateTime.get_Today 44

12 xxxx.MainPage..ctor 84

13 mscoree3_7.dll 507848

14 mscoree3_7.dll 184683

15 mscoree3_7.dll 183987

16 mscoree3_7.dll 183375

17 System.Reflection.RuntimeConstructorInfo.InternalInvoke 104

18 System.Reflection.RuntimeConstructorInfo.InternalInvoke 1056

19 System.Activator.InternalCreateInstance 1112"

This is the mainpage constructor:

public MainPage()
{
    InitializeButtons();
    CreateCalendar();
    DisplayHistory();
    DisplayStatistics();
}

And inside CreateCalendar I have initialized a variable DateTime currentDate = DateTime.Today; Is this the one creating the trouble?

Upvotes: 0

Views: 305

Answers (2)

LVR
LVR

Reputation: 724

In my case this error occasionaly came out of the blue with some insignificant changes. It failed in initialization stage of tests under running Silverlight Unit Test Framework. Changes were made in project that was indirectly referenced from Unit Test project (i.e. Unit Test project referenced Windows Phone library and the library referenced PCL with changes).

It's redundant to say thay the code I added didn't execute at all when the crash happened!

After commenting out new code with bisection method I ended up that commenting a single line stopped throwing the exception. The line was like this:

var items = jData["items"].Select(token => token.ToObject()).ToList();

where jData is JObject instance from well-known Json.NET. Updating to recent version of Json.NET didn't help.

The error is gone after replacing LINQ expression with explicit ugly for loop (scoffing Resharper says "for loop can be converted to LINQ expression).

So I'm starting to believe in magic.

Hope this helps someone.

Upvotes: 1

josemiguel.torres
josemiguel.torres

Reputation: 632

I suggest to you to move the methods to Page loaded event as follow:

public MainPage()
{
     InitializeComponent();
     Loaded += MainPage_Loaded; // you may declare it in xaml as well
}

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    CreateCalendar();
    DisplayHistory();
    DisplayStatistics();
}

Depending on the kind of operations you are performing inside each method -mainly if it envolves UI -it would be recommended to wrap it into a Dispatcher:

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    CreateCalendar(); //assuming this method does not use UI
    Dispatcher.BeginInvoke(() => 
    {
     //asuming these methods use UI
     DisplayHistory();
     DisplayStatistics();
    });
}

Try it out and let us know,,

cheers

Upvotes: 2

Related Questions