Answered by:
AI crashing my app upon restart

Question
-
Hi everyone,
We've integrated Application Insights into our Windows Universal app and it crashes on Windows Phone 8.1 in this scenario. I launch the app, then press the Windows button to return to the home screen. Then I start the app again by tapping on it's tile. Then the app crashes with the following stack trace:
System.Runtime.InteropServices.COMException: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)) at System.StubHelpers.InterfaceMarshaler.ConvertToManaged(IntPtr pUnk, IntPtr itfMT, IntPtr classMT, Int32 flags) at Windows.ApplicationModel.Core.CoreApplicationView.get_Dispatcher() at Microsoft.ApplicationInsights.Extensibility.Implementation.Platform.PlatformDispatcher.OnViewActivated(CoreApplicationView sender, IActivatedEventArgs args)
Note that the root is Microsoft.ApplicationInsights.Extensibility.Implementation.Platform.PlatformDispatcher.OnViewActivated(CoreApplicationView sender, IActivatedEventArgs args). We can reproduce this problem both on real devices and the emulator. As we're concentrating on Windows Phone for now I don't know if this can be reproduced on the PC, too.
We tried to reproduce this problem in plain vanilla projects without success, so this seems to be specific to our project setup. We're using SQLite for Windows Phone 8.1 (3.8.9), the Microsoft Player Framework (2.0), the Microsoft Visual C++ Runtime Package for Windows Phone (12.0) and some non-native libraries, too.
Has someone encountered such an issue and knows how to work around it? I'm happy to share the project with the Application Insights developers privately.
All the best,
yours
Robert
Changing the world... bit by bit.
Answers
-
Should be in .17 which we plan to release end of next week (5/22). If this is blocking you, we could also release an update to .16. Is waiting until next week ok?
Jakub Oleksy | Developer | Visual Studio Online
- Proposed as answer by Anastasia BaranchenkovaModerator Wednesday, May 13, 2015 5:51 PM
- Marked as answer by enough2012 Wednesday, May 13, 2015 6:42 PM
All replies
-
Forgot to mention that Application Insights is working fine otherwise, i.e. I get the events correctly and all.
Is this the right forum at all? Just wondered because AI is now part of Azure as far as I understood.
Best
Robert
Changing the world... bit by bit.
-
-
-
Hi
I have the same issue With Version 0.16.1.418. Plain Windows Phone 8.1 Universal app crashes every time when app is launched, then re-launched.
Not sure what the exception is as this does not happen when running in a debugger.
The following is logged to Application Insights when this happens.
"The application called an interface that was marshalled for a different thread. The application called an interface that was marshalled for a different thread. "
foo.App.OnLaunched(LaunchActivatedEventArgs e)Windows.UI.Xaml.Window.Activate()I'm running Visual Studio 2013 Update 4
Kristian
-
Hi Anastasia and all,
any news from the team? I haven't had any feedback so far about this relaunch-crash. I can confirm that this is unrelated to Winows 10 preview, as this happens with both VS13 on Win8.1 as well as VS15 on Windows 10 preview.
All the best,
Robert
Changing the world... bit by bit.
-
-
Hi Meni, thanks for getting in touch, I send you a mail with more information just a minute ago. You will also find the stacktace above, here it is once more for your convenience:
System.Runtime.InteropServices.COMException: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)) at System.StubHelpers.InterfaceMarshaler.ConvertToManaged(IntPtr pUnk, IntPtr itfMT, IntPtr classMT, Int32 flags) at Windows.ApplicationModel.Core.CoreApplicationView.get_Dispatcher() at Microsoft.ApplicationInsights.Extensibility.Implementation.Platform.PlatformDispatcher.OnViewActivated(CoreApplicationView sender, IActivatedEventArgs args)
Thanks for looking into this,
yours
Robert
Changing the world... bit by bit.
-
FYI: Meni was able to locate and fix this relaunch issue, so this should be resolved in the next release of Application Insights. I don't have an ETA for that, but I thought it's still good to know that this is going to be resolved.
Best
Robert
Changing the world... bit by bit.
-
Should be in .17 which we plan to release end of next week (5/22). If this is blocking you, we could also release an update to .16. Is waiting until next week ok?
Jakub Oleksy | Developer | Visual Studio Online
- Proposed as answer by Anastasia BaranchenkovaModerator Wednesday, May 13, 2015 5:51 PM
- Marked as answer by enough2012 Wednesday, May 13, 2015 6:42 PM
-
-
I've been looking to get the first release of a particular app out to the store within the next week or two, so 5/22 works for me, but I could use it earlier :) I'm impressed by Microsoft's responsiveness, and wasn't really expecting such a quick turnaround, so I don't mind waiting.
I have to agree with Robert here--keep up the good work! So far AI is looking really nice, and I plan to phase it in as a replacement for the third-party tool I've been using.
-
Hello All,
we just publish latest version of the SDK 0.17 which include fixes for this issue above.
https://www.nuget.org/packages/Microsoft.ApplicationInsights.WindowsApps/0.17.0
Thanks,
Meni Zalzman
- Edited by Meni Zalzman [MSFT]Microsoft employee Friday, May 22, 2015 10:48 PM
-
Hi,
I've just updated to 0.17 but my app still crashes the third or fourth time I open the app from the Start menu.
The exception message is: "The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))"
There is no stacktrace.
If I comment out my Telemetry code, I can restart the app many times without crashing it, so I'm pretty sure it has something to do with AI.
Yannik
-
-
Hi Jakub and Meni,
many thanks for the fresh update - it's much better now!
However, I can also reproduce Yannik's crash in the emulator. I have to repeatedly go to the hone screen and restart the app (in my case I have pinned it to the home screem for faster access, but that doesn't seem to matter).
My error is this:
System.AccessViolationException was unhandled
Message: An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.ni.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.Not really helpful, I know. If you want, I can share my project again, but I assume this can be reproduced with the previous version of my project as well. The important thing is that you need to start the app several times to crash it. So while it's much better than before, I don't think we could use AI in a live app right now.
Thanks and all the best,
Yours
Robert
Changing the world... bit by bit.
-
Hi Jakub,
Yes, I can reproduce it in the emulator
I've tried to enable first change exceptions but that didn't give me any stacktrace either.
But it is easy to reproduce. Here is what I did:
Created a new Windows 8.1 universal app.
Added Application.Insights.Windows v. 0.17 from Nuget
Created a new instance of TelemetryClient in App and added an InstrumentionKey to ApplicationInsights.config
Started the windows phone app in the emulator.
Pinned the App to Start
And repeatedly opened the app from the Start screen (like Robert did)
Yannik
-
Deleted comment. Please see my next response to Nikita.
- Edited by Izik LisbonEditor Tuesday, May 26, 2015 6:57 PM To avoid confusion. The latest reply has all the needed information.
-
-
Thanks for your response. Indeed, this only reduces the likelihood of a crash.
To completely avoid the crash you should remove the following:
<Add Type="Microsoft.ApplicationInsights.Extensibility.Windows.PageViewTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Windows"/> <Add Type="Microsoft.ApplicationInsights.Extensibility.Windows.UnhandledExceptionTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Windows"/> <Add Type="Microsoft.ApplicationInsights.Extensibility.DeviceContextInitializer, Microsoft.ApplicationInsights.Extensibility.Windows"/>
Please note that we are actively working on a fix and we will update this thread once we will have a fix for it.
Thanks,
Izik
-
Hi lzik Lisbon,
<Add Type="Microsoft.ApplicationInsights.Extensibility.Windows.PageViewTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Windows"/>
<Add Type="Microsoft.ApplicationInsights.Extensibility.Windows.UnhandledExceptionTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Windows"/>
<Add Type="Microsoft.ApplicationInsights.Extensibility.DeviceContextInitializer, Microsoft.ApplicationInsights.Extensibility.Windows"/>Even though I removed the above three from ApplicationInsights.config file, I am getting below same exception.
"An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. "
Note:
we have updated Application.Insights.Windows v. 0.17 package as well.
Looking for your reply ASAP. We are blocking for this issue. If you can Please provide the path where we can find the Updated packages/dll.
-
Hello Sakthivel,
can you please validating that after you are removing the lines above from the configuration file that the application package contained the update version of the configuration file?
we experience the same issue that the build didn't update the configuration file as part of the build, the best approach to delete the bin folder and rebuild.
Thanks,
Meni Zalzman -
Hi Meni Zalzman,
I did the steps as you suggested, but still I am getting the same below exception.
"An unhandled exception of type 'System.AccessViolationException' occurred in mscorlib.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Waiting for your further support.
Thanks,Sakthivel Natrayan.
-
public App() { // start all the auto-collectors by default WindowsAppInitializer.InitializeAsync(); this.InitializeComponent(); this.Suspending += OnSuspending; }
Hello Everyone,
wanted to inform everyone that we shipped our 1.0 SDK version and we addressed all these issues.
http://www.nuget.org/packages/Microsoft.ApplicationInsights.WindowsApps/1.0.0we changed the way we are configuring the auto-collection from now on we are not using the configuration file and we added a new API to call on the application constructor which will configure the SDK to start auto-collection and will set all the needed configuration for windows SDK
see code sample below
// start all the auto-collectors by default WindowsAppInitializer.InitializeAsync(); // you can pick which of the collectors to use by passing the flags enumeration WindowsAppInitializer.InitializeAsync( WindowsCollectors.Metadata | WindowsCollectors.PageView | WindowsCollectors.Session | WindowsCollectors.UnhandledException); // This call will set the instrumentation key and start all auto-collection // with this approach you don't need the configuration file WindowsAppInitializer.InitializeAsync("00000000-0000-0000-0000-000000000000");
This call should be added the app.xaml.cs constructor as follow:
public App() { // start all the auto-collectors by default WindowsAppInitializer.InitializeAsync(); this.InitializeComponent(); this.Suspending += OnSuspending; }
Thanks,
Meni Zalzman
- Edited by Meni Zalzman [MSFT]Microsoft employee Thursday, June 25, 2015 9:01 PM
-
How should it be initialized from a Background Agent?
Should the Initialize just be awaited on?//start defer
await WindowsAppInitializer.InitializeAsync("SOMEID",
WindowsCollectors.Metadata |
WindowsCollectors.Session |
WindowsCollectors.UnhandledException);do stuff
//complete defer
-
How do we set developer mode now, or the app version?
- Edited by Andy-PennellMicrosoft employee Tuesday, July 28, 2015 2:16 PM
-
How should it be initialized from a Background Agent?
Should the Initialize just be awaited on?//start defer
await WindowsAppInitializer.InitializeAsync("SOMEID",
WindowsCollectors.Metadata |
WindowsCollectors.Session |
WindowsCollectors.UnhandledException);do stuff
//complete defer
-
Using Core without any initialization is the right way to work in Background tasks. The Windows initialization must be done in the app constructor:
https://azure.microsoft.com/en-us/documentation/articles/app-insights-windows-get-started/
For a background task, you can think of it as a desktop application for the purposes of using AI. Not auto-collection aspects are expected to be used:
https://azure.microsoft.com/en-us/documentation/articles/app-insights-windows-desktop/
Jakub Oleksy | Developer | Visual Studio Online
-
Using Core without any initialization is the right way to work in Background tasks. The Windows initialization must be done in the app constructor:
https://azure.microsoft.com/en-us/documentation/articles/app-insights-windows-get-started/
For a background task, you can think of it as a desktop application for the purposes of using AI. Not auto-collection aspects are expected to be used:
https://azure.microsoft.com/en-us/documentation/articles/app-insights-windows-desktop/
Jakub Oleksy | Developer | Visual Studio Online
Good to know :-) That's basically how I have it setup and it seems to be collecting information effectively...
If you try to do thisawait WindowsAppInitializer.InitializeAsync("SOMEID", WindowsCollectors.Metadata | WindowsCollectors.Session | WindowsCollectors.UnhandledException);
in the background task it actually crashes :-) so I figured pretty quickly to not have that in there and just log stuff using the Telemetry client in the catch or from the cancellation...
One question though ... When is this data sent to App Insights? At some point I thought I remember App Insights saying that data is sent from a mobile device when the application comes back into the foreground... Is that true? Or if I'm sending data purely from the background task will that data show up? Or will it not show up until the user brings the application into the foreground...
-
Hi,
I did as you mentioned. In Run method of BackgroundTask I'm initializing TelemetryClient, providing instrumentation key, and assigning session id. Everything is working fine on emulator and phone. The problem starts when I publish my app to the store. It crashes when after being downloaded from the store it starts to install with the error code 80073cf9 .
-
The answer to when depends a bit on how you have configured it and how you use it.
InMemoryChannel (Default when using Microsoft.ApplicationInsights Nuget package):
Send() will enqueue the telemetry in an in memory buffer. Telemetry will be sent when buffer is full, or after SendingInterval (30 seconds by default) or after a call to Flush().
PersistenceChannel (Default channel in Microsoft.ApplicationInsights.WindowsApps Nuget package): Send()will enqueue the telemetry in an in memory buffer. Telemetry will be flushed to disk when buffer is full, or after SendingInterval (30 seconds by default) or after a call to Flush().
The actual sending will be after 5 seconds to 1 hour (see the table below for explanation on timing).
Sending Intervals
Class
Property
Default
Description
InMemoryChannel
SendingInterval
30 seconds
Flush the In Memory Queue and sends it
PersistenceChannel
SendingInterval
5 seconds
The interval between each successful sending.
PersistenceChannel
FlushInterval
30 seconds
Gets or sets the interval between each flush to disk.
PersistenceChannel
maxIntervalBetweenRetries (private)
1 hour
Holds the maximum time for the exponential back-off algorithm. The sending interval will grow on some HTTP errors until this max value.
PersistenceChannel
sendingIntervalOnNoData (private)
10 seconds
Holds the interval between each sending. Unlike SendingInterval
This interval is used when the Storage is empty. When Storage is not empty the channel will try to drain it and thus the interval is smaller.
- Edited by Jakub Oleksy [MSFT]Microsoft employee Tuesday, August 11, 2015 9:34 PM Edit text
-
-
Hi,
I have a working app in the store with background music player task. When I add Application Insight Core package to project with the background task and then publish it to the store the installation process crashes on error 80073cf9. After I remove the package and comment the AI init code and publish it to the store, the app is being downloaded and installed correctly.
Here is my init code for AI in backgroundtask:
public sealed class BackgroundAudioTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { // Initialize telemetry TelemetryClient = new TelemetryClient(); TelemetryClient.InstrumentationKey = "my_key"; TelemetryClient.Context.Session.Id = Guid.NewGuid().ToString(); // other stuff } }
It is very strange that it works while debugging on emulator and on my phone, but it crashes after publishing it to the store. It even works when I deploy the appbundle directly to my phone.
- Edited by Artur Lipski Tuesday, August 11, 2015 6:37 PM
-
-
-
-