none
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.

    Wednesday, May 06, 2015 12:30 PM

Answers

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.

    Wednesday, May 06, 2015 7:02 PM
  • Thank you for reporting the issue. I forwarded it to the team for investigation.

    Anastasia

    Wednesday, May 06, 2015 11:44 PM
    Moderator
  • I just ran into this problem today in the Windows Phone half of a Windows Universal App project.  I was initially on version 0.14.3-build00177, but upgraded to 0.16.1-build00418, and both exhibit the problem.  I'm running VS 2015 RC on Windows 10 build 10074.
    Friday, May 08, 2015 3:44 AM
  • 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

    Saturday, May 09, 2015 8:56 AM
  • 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.

    Tuesday, May 12, 2015 11:43 AM
  • Hello Robert,

    I am working on the Application Insights SDK team and we are trying to repro your issue with no luck, can you share with me your code or the call stack?

    my emails is meniz@microsoft.com

    Thanks,

    Meni Zalzman

    Tuesday, May 12, 2015 5:31 PM
  • 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.

    Tuesday, May 12, 2015 7:40 PM
  • 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.

    Wednesday, May 13, 2015 6:47 AM
  • 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

    Wednesday, May 13, 2015 2:59 PM
  • Hi Jakup,

    thanks for the update, as we're in private beta I'm in no big hurry here, but of course I don't know how it is for the others...

    Thanks and looking forward to the release - and keep up the good work!

    Robert


    Changing the world... bit by bit.

    Wednesday, May 13, 2015 3:08 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.

    Wednesday, May 13, 2015 3:18 PM
  • 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


    Friday, May 22, 2015 10:01 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

    Saturday, May 23, 2015 9:25 AM
  • Is it possible for you to reproduce this in the emulator? Can you try to catch first-chance exceptions and figure out the stack it is happening on? This is a new one for us. 

    Jakub Oleksy | Developer | Visual Studio Online

    Saturday, May 23, 2015 5:41 PM
  • 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.

    Sunday, May 24, 2015 12:07 AM
  • 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

    Sunday, May 24, 2015 6:35 PM
  • Deleted comment. Please see my next response to Nikita.

    Monday, May 25, 2015 5:50 AM
    Moderator
  • Hi, Izik L.
    I have same issues with 17th version of nuget. If repeatedly opened the app from the Start screen or use SearchPane (tap search) - it crashed. 
    And if I remove two lines  from ApplicationInsights.config - problem still here.

    Regards, Nikita.

    Monday, May 25, 2015 2:59 PM
  • Hi Nikita Bondarenko,

    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

    Tuesday, May 26, 2015 6:54 PM
    Moderator
  • 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.

    Monday, June 01, 2015 7:23 AM
  • 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

    Tuesday, June 02, 2015 7:40 PM
  • 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.

    Wednesday, June 03, 2015 9:41 AM
  • 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.0

    we 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



    Thursday, June 25, 2015 3:18 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

    Thursday, June 25, 2015 5:43 PM
  • How do we set developer mode now, or the app version?
    Tuesday, July 28, 2015 2:03 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

    I would like also know how to add App Insights to BackgroundTask in Windows Phone 8.1? I have tried to add the core package and everything was working fine on emulator and phone. After I published my app to the store I cannot installed it because I was getting 80073cf9 error.
    Monday, August 10, 2015 5:23 PM
  • 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

    Monday, August 10, 2015 7:58 PM
  • 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 this

    await 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...

    Monday, August 10, 2015 9:52 PM
  • 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 .

    Monday, August 10, 2015 9:53 PM
  • 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.  



    Tuesday, August 11, 2015 4:51 PM
  • I am not sure that error is related? Is it possible something else is causing it? What leads you to your conclusion about this being a result of the AI code?



    Jakub Oleksy | Developer | Visual Studio Online

    Tuesday, August 11, 2015 4:52 PM
  • 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.


    Tuesday, August 11, 2015 5:18 PM
  • Can you send me an email (jakubo@microsoft.com) with your product id and a picture of the error you see? I will follow-up with the store team and we will see what we can figure out. 

    Jakub Oleksy | Developer | Visual Studio Online

    Tuesday, August 11, 2015 7:21 PM
  • Has that problem been resolved?
    Monday, January 04, 2016 3:21 AM
  • Which problem? Are you running into an issue?

    Jakub Oleksy | Developer | HockeyApp

    Monday, January 04, 2016 7:24 PM
  • I was a bit doubtful, when reading Arturs problems as I didnt want to publish an app which is causing problems in release but not in debug. Did it anyway and everything works as expected!
    Monday, January 04, 2016 7:48 PM