locked
Why does WinJS.UI.AppBar need resources.resjson file?

    Question

  • I added a simple AppBar to a blank project like this:

    <body>
        <p>Content goes here</p>
        <!-- Define the App Bar -->
    	<div data-win-control="WinJS.UI.AppBar">
    		<button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{icon:'back', id:'', label:'example', onclick:null, section:'global'}"></button></div>
        
    </body>

    and found that when Debug > Exceptions... > JavaScript Runtime Exceptions was enabled, an exception was thrown when running the program. 

    Exception was thrown at line 641, column 21 in ms-appx://microsoft.winjs.0.6.debug-8wekyb3d8bbwe/js/base.js
    0x80073b1f - JavaScript runtime error: ResourceMap Not Found.

    Examining the base.js script where the exception was halted suggested that the script was looking for a resources map.  Adding a default resources.resjson item to the project allowed the program to run without throwing the exception.  Experiments indicate that this file name is required.

    So, what is going on here?  What is the significance of this file to the AppBar?  What should it contain?

    Monday, April 16, 2012 10:51 PM

Answers

  • Hi jrboddie,

    This is a known issue with the Community Preview release of WinJS. It's due to a WinRT API throwing an exception when WinJS checks to see if a resource map exists or not. You can either safely ignore the first chance exception or work around it by adding a resjson file as you discovered.

    Cheers,

    -Jeff

    • Marked as answer by jrboddie Tuesday, April 17, 2012 4:46 PM
    Tuesday, April 17, 2012 4:31 PM
  • The AppBar makes a call to WinJS.Resources.getString() to retrieve localized resources it uses for the label and icon. For example, some AppBar icons may change for apps that support and users that speak a different language.

    The way WinJS.Resources.getString() works is that all resource identifiers passed in are relative to a ResourceMap called 'Resources', which is the resource map for the resources.resjson file. The code will successfully catch exceptions of this form and will only allow path absolute references to retrieve resources with. The AppBar only passes absolute resource identifiers to WinJS.Resources.getString() so this code will complete successfully. Feel free to ignore these exceptions.

    • Marked as answer by jrboddie Tuesday, April 17, 2012 4:46 PM
    Tuesday, April 17, 2012 4:38 PM

All replies

  • Hi jrboddie,

    This is a known issue with the Community Preview release of WinJS. It's due to a WinRT API throwing an exception when WinJS checks to see if a resource map exists or not. You can either safely ignore the first chance exception or work around it by adding a resjson file as you discovered.

    Cheers,

    -Jeff

    • Marked as answer by jrboddie Tuesday, April 17, 2012 4:46 PM
    Tuesday, April 17, 2012 4:31 PM
  • The AppBar makes a call to WinJS.Resources.getString() to retrieve localized resources it uses for the label and icon. For example, some AppBar icons may change for apps that support and users that speak a different language.

    The way WinJS.Resources.getString() works is that all resource identifiers passed in are relative to a ResourceMap called 'Resources', which is the resource map for the resources.resjson file. The code will successfully catch exceptions of this form and will only allow path absolute references to retrieve resources with. The AppBar only passes absolute resource identifiers to WinJS.Resources.getString() so this code will complete successfully. Feel free to ignore these exceptions.

    • Marked as answer by jrboddie Tuesday, April 17, 2012 4:46 PM
    Tuesday, April 17, 2012 4:38 PM