The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Visual studio 2017: Debugging a UWP app works in debug mode, but not in release mode RRS feed

  • Question

  • Hello,

    I am developing a UWP application with Visual Studio 2017 called My Projects. When I run this application in Debug - x86 mode, it runs correctly from VS, and also from the start menu. On the other hand, when I run it in Release - x86 mode, sometimes it runs, sometimes Visual Studio tells me that it is in Stop mode, sometimes the SplashScreen appears, then everything crashes. And from the start menu, SplachScreen appears, stays on for a few seconds, then closes.

    When debugging in Release - x86 mode completes correctly, I can generate a package (which I have been able to upload to the store), but the certification kit crashes when launching the platform version. I am forced to do an End of Task on the process to stop it.

    Thank you for helping me, because I do not see where the problem is, and I cannot publish my application on the Store.


    • Edited by Mani035 Thursday, November 14, 2019 5:44 PM
    Thursday, November 14, 2019 5:41 PM

Answers

  • Hi,

    I reproduced your problem and investigated the entire project.

    ---

    1. Change the initially loaded page (from MainPage to a BlankPage) in App.xaml.cs to exclude interference caused by the reference. The application is successfully loaded, proving that the problem is not on the reference.

    2. Skip the loading of MainPage and load ListeProjets directly, unable to load. Switch to debug state and test that the database is not initialized.

    ---

    This caught my attention. I analyzed your writing of the database in MainPage and the timing of navigating to the ListeProjets page. I think the problem is here.

    I tried to modify your code in MainPage, using the Task, to force the application to complete the database initialization first, and then navigate to the ListeProjets page.

    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        await Task.Run(() =>
        {
            Db_Helper.CreateDatabase(App.DB_PATH);
        });
        ReadAllMonnaiesList dbmonnaies = new ReadAllMonnaiesList();
        DB_MonnaiesList = dbmonnaies.GetAllMonnaies(); //Get all DB Monnaies
        Monnaies itemMonnaie = new Monnaies();
        if (DB_MonnaiesList.Count == 0)
        {
            itemMonnaie.NomMonnaie = "€";
            Db_Helper.Insert(new Monnaies(itemMonnaie.NomMonnaie));
            itemMonnaie.NomMonnaie = "$";
            Db_Helper.Insert(new Monnaies(itemMonnaie.NomMonnaie));
            itemMonnaie.NomMonnaie = "£";
            Db_Helper.Insert(new Monnaies(itemMonnaie.NomMonnaie));
        }
        foreach (NavigationViewItemBase item in NavViewMain.MenuItems)
        {
            if (item is NavigationViewItem && item.Tag.ToString() == "Listes")
            {
                NavViewMain.SelectedItem = item;
                break;
            }
        }
        contentFrame.Navigate(typeof(ListeProjets));
    }

    This application can be started smoothly.

    In Release mode, the loading of the application is optimized. The loading order of some code may be different from the debug mode. This should be the reason for your application crash.

    The application navigates to the ListeProjets page when the database has not been initialized, causing some operations that require the database to behave abnormally, causing the application to fail to load.

    By the way, We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!

    Best regards.


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.


    Wednesday, November 20, 2019 8:36 AM

All replies

  • Hi,

    There are many reasons for the app crash, you can open the Event Viewer to view detailed error information, which helps to analyze the problem.

    - After application crashed, open the Event Viewer.

    - Open the Windows Logs -> Application

    - Find your application error message, it may provide more information.

    Best regards.


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Friday, November 15, 2019 1:26 AM
  • Hello,

    I checked the event / application log after running in release mode, and there is no error corresponding to my application. When the compilation is finished, the SplashSceen appears, and  then the application is running correctly.

    However, when running the application from the Start menu, I get an error message:

     

    The program MesProjets.exe version 1.0.0.0 stopped interacting with Windows and was closed. To see if more information about the problem is available, check the problem history in the Security and Maintenance Control Panel. 

    Process ID: 3160 

    Start time: 01d59bdb85c2e1ab 

    Stop time: 4294967295 

    Application path: F: \ Users \ marceldelhaye \ Documents \ Visual Studio 2017 \ Projects \ MyProjects \ MyProjects \ bin \ x86 \ Release \ AppX \ MyProjects.exe 

    Report ID: 343bcd14-47f6-4070-8426-77c5e0eea241 

    Failed Package Full Name: 503ApriSoft.MesProjets_4.0.0.0_x86__p639jsfcetr2j 

    Application ID for a faulty package: App 

    Blocking type: Cross-thread

     

    Name of the event log : Application

    Source :       Application Hang

    Date :         15/11/2019 18:39:47

    Event ID : 1002

    Category of the task : (101)

    Level :       Error

    Keywords:    Classic

    User :  N/A

    Computer :   PC-WIN10

     

    Note : there is nothing about the application in the Security and Maintenance Control Panel.

     

    Thank you for your help.

    Friday, November 15, 2019 6:06 PM
  • Hi,

    I noticed that one of the error reports you provided may be related to an app crash.

    >> Blocking type: Cross-thread

    Since your app crashes while loading, you can find the corresponding code in App.xaml.cs or Mainpage.xaml.cs.

    For example, if you have opened a new thread to communicate with the UI, etc.

    If your self-inspection has no results, consider removing the sensitive information from the project and providing a sample that can reproduce the problem so that we can test it.

    Best regards.


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Monday, November 18, 2019 7:22 AM
  • Hello Richasy and thank you for this information.

    I used in the program (ListeProjets.xaml.cs) the following instruction:

     

    localculture = Thread.CurrentThread.CurrentCulture;

    I replaced it with:

    culture = CultureInfo.CurrentCulture.Name;

     

    And further:

     

    string culture = "en-US"; // set this thread's current culture to the culture associated with the local thing

    CultureInfo newCulture = new CultureInfo (culture);

    Thread.CurrentThread.CurrentCulture = newCulture;

     

    Which I replaced by:

     

    CultureInfo.CurrentCulture = new CultureInfo ("fr-FR", false);

     

    Likewise for this one:

     

    Thread.CurrentThread.CurrentCulture = localculture;

     

    Which I replaced by:

     

    CultureInfo.CurrentCulture = new CultureInfo (culture, false);

     

    All this to remove the Treads. Unfortunately, I still have the same error when compiling in release mode. Since I do not see where the problem comes from, I would like to put my source program on OneDrive here:

    https://1drv.ms/u/s!Am0yZGVkguZvjZVcfMOobPrCMdh-mw?e=cCebA1

    There is no confidential data, everything can be shared.

    Thank you very much for testing it and telling me if the problem is reproducing on another PC, and if it's possible, tell me where the error comes from. It would be really nice.

    Best Regards,

    Marcel

    Tuesday, November 19, 2019 9:49 AM
  • Hi,

    I downloaded your code and tested it, this is my testing process.

    1. Run the app in debug x64 mode with Visual Studio 2017 and it works fine.

    2. Switch to Release x64 mode, start successfully, run normally

    3. Switch to Release x86 mode, the startup fails, but the error type is not related to the thread.

    ---

    I think this may be related to a reference to a dll, so I did the following test.

    1. Remove references to Visual C++ 2015 UWP Desktop Runtime for native apps, rebuild the project, and run successfully in Release x86 mode.

    2. Re-add the reference of Visual C++ 2015 UWP Desktop Runtime for native apps, this operation did not report an error, successfully started.

    ---

    In order to troubleshoot the IDE, I re-tested it with Visual Studio 2019, and it worked fine in both Release x86 and Release x64 modes.

    ---

    I think this may be some of the failures in Visual Studio compilation. You can try removing the reference to Visual C++ 2015 UWP Desktop Runtime for native apps, clean up the current project, and regenerate it.

    Best regards.


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.


    Tuesday, November 19, 2019 2:30 PM
  • Hello Richasy,

    I just read your answer, and I was very happy to know that everything works after removing Visual C++ 2015 UWP Desktop Runtime for native apps. That's what I did on my PC, then cleaned up all bin and release folders, and then regenerated the solution. And indeed, the debug mode is running (it was already the case before) AND the release mode too.

    BUT ... When I close Visual Studio 2017 and run the app from the Start menu, that's when the app crashes and generates an error message in the Application Event Viewer.

    On the other hand, when I compile in debug mode, the app runs properly from the start menu.

    Do you have another idea? Thanks a lot for your help.


    • Edited by Mani035 Tuesday, November 19, 2019 3:26 PM
    Tuesday, November 19, 2019 3:25 PM
  • Hi,

    I reproduced your problem and investigated the entire project.

    ---

    1. Change the initially loaded page (from MainPage to a BlankPage) in App.xaml.cs to exclude interference caused by the reference. The application is successfully loaded, proving that the problem is not on the reference.

    2. Skip the loading of MainPage and load ListeProjets directly, unable to load. Switch to debug state and test that the database is not initialized.

    ---

    This caught my attention. I analyzed your writing of the database in MainPage and the timing of navigating to the ListeProjets page. I think the problem is here.

    I tried to modify your code in MainPage, using the Task, to force the application to complete the database initialization first, and then navigate to the ListeProjets page.

    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        await Task.Run(() =>
        {
            Db_Helper.CreateDatabase(App.DB_PATH);
        });
        ReadAllMonnaiesList dbmonnaies = new ReadAllMonnaiesList();
        DB_MonnaiesList = dbmonnaies.GetAllMonnaies(); //Get all DB Monnaies
        Monnaies itemMonnaie = new Monnaies();
        if (DB_MonnaiesList.Count == 0)
        {
            itemMonnaie.NomMonnaie = "€";
            Db_Helper.Insert(new Monnaies(itemMonnaie.NomMonnaie));
            itemMonnaie.NomMonnaie = "$";
            Db_Helper.Insert(new Monnaies(itemMonnaie.NomMonnaie));
            itemMonnaie.NomMonnaie = "£";
            Db_Helper.Insert(new Monnaies(itemMonnaie.NomMonnaie));
        }
        foreach (NavigationViewItemBase item in NavViewMain.MenuItems)
        {
            if (item is NavigationViewItem && item.Tag.ToString() == "Listes")
            {
                NavViewMain.SelectedItem = item;
                break;
            }
        }
        contentFrame.Navigate(typeof(ListeProjets));
    }

    This application can be started smoothly.

    In Release mode, the loading of the application is optimized. The loading order of some code may be different from the debug mode. This should be the reason for your application crash.

    The application navigates to the ListeProjets page when the database has not been initialized, causing some operations that require the database to behave abnormally, causing the application to fail to load.

    By the way, We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!

    Best regards.


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.


    Wednesday, November 20, 2019 8:36 AM
  • Hello Richasy,

    It's great, you saw where the problem came from. I applied the changes you proposed, and the compilation in release mode ran correctly on the first try.

    I cannot thank you enough, because without you, I could never publish my application. And I learned a lot again thanks to you.

    Thank you very much, and congratulations!

    Marcel

    Wednesday, November 20, 2019 7:07 PM