Thursday, April 19, 2012

Windows RT Deployment Error

I created a Windows RT (Windows 8) Metro app, packaged it and tested in dev environment without any problem. However I got below error when installing the package in another machine (a Samsung tablet):

Add-AppxPackage : Deployment failed with HRESULT: 0x80073CFF, To install this application you need either a Windows developer license or a sideloading-enabled system Deployment of package 02897621-4EBE-4E92-9B00-263BAA300DAC_1.0.0.2_x64__32kjnh8rzfyae [Package Full Name] failed because no valid license or sideloading policy could be applied. A developer license (http://go.microsoft.com/fwlink/?LinkId=233074) or enterprise sideloading configuration (http://go.microsoft.com/fwlink/?LinkId=231020) may be required. NOTE: For additional information, look for [ActivityId] 692ada4a-1bf0-0003-86dc-2a69f01bcd01 in the Event Log or use the command line Get-AppxLog -ActivityID 692ada4a-1bf0-0003-86dc-2a69f01bcd01
At line:1 char:236
+ ... $PackageFile; Add-AppxPackage $PackageFile; if(!$?) {exit 8}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (C:\Users\in..._x64_Debug.appx  :String) [Add-AppxPackage], Exception
+ FullyQualifiedErrorId : DeploymentError,Microsoft. Windows.Appx.PackageManager.Commands. AddAppxPackageCommand
ERROR: FAILED TO INSTALL DEVELOPER PACKAGE!

It turned out that a developer license is required in the tablet although it's not a development machine. One thing interesting is that I built another Windows 8 XAML application based on a solution came with Microsoft Metro app samples, and that application was installed and run successfully in the tablet. It looks like Windows RT has a certificate check process, and developer license is not required if the app's certificate belongs to Microsoft.

Monday, April 16, 2012

Windows 8 Metro PopupMenu Issue

How to create a popup in Windows 8 Metro apps? MessageDialog and PopupMenu seem to be the only two options if you go with XAML/C# approach (at least for current Customer Preview edition). MessageDialog is just the Metro implementation of WinForm MessageBox. PopupMenu represents a context menu for quick commands/actions.

Today I created a Metro application and used PopupMenu to populate a list of hints for user's input. But it's just not showing anything. I digged into the issue and found a big limitation of PopupMenu: the maximum number of popup items (UIComment or UICommandSeparator) is only 6! For example following code would throw a "The operation attempted to access data outside the valid range" exception:
            var popupMenu = new PopupMenu();
            popupMenu.Commands.Add(new UICommand("Hints", null, string.Empty));
            popupMenu.Commands.Add(new UICommandSeparator());
            popupMenu.Commands.Add(new UICommand("Hint 1", null, "Hint 1"));
            popupMenu.Commands.Add(new UICommand("Hint 2", null, "Hint 2"));
            popupMenu.Commands.Add(new UICommand("Hint 3", null, "Hint 3"));
            popupMenu.Commands.Add(new UICommand("Hint 4", null, "Hint 4"));
            popupMenu.Commands.Add(new UICommand("Hint 5", null, "Hint 5")); // <== Throw exception here
I am not sure if it's bug or limitation. There may be some reason behind that but I couldn't find any information about this limit in any MSDN documentation. Another limitation of PopupMenu is that you can't customize the look and feel of it. You may end up implementing your own popup control since the out-of-box popup function is so limited.
2012-8-28 update: the same issue still exists in the latest Windows 8 RTM version. Let's just say this is by design and is an undocumented limitation.

Thursday, April 05, 2012

ThrowIfMaxHttpCollectionKeysExceeded Error When Populating WebPart

A custom WebPart won't show in the available WebPart list when it's deployed to WebPart Gallery by a Feature. In order to use such WebPart, we need to manually populate it inside SharePoint WebPart Gallery. What you do is go to site collection's WebPart gallery, click "New" button on the toolbar, select the WebPart and click "Populate Gallery" button:



It used to be working fine but all in a sudden I got an error when populating a WebPart:



This runtime error doesn't provide any hints. There're two options to see the error detail.

1. Go to SharePoint ULS logs in SharePoint_12_Or_14_Hive\LOGS and do the search.
2. Set <customErrors mode="Off" /> in SharePoint_12_Or_14_Hive\TEMPLATE\LAYOUTS\Web.config (not the WebApplication itself).

The error found in the ULS log is:

w3wp.exe (0x21BC) 0x1EB0 SharePoint Foundation Runtime tkau Unexpected System.InvalidOperationException: Operation is not valid due to the current state of the object. at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) at System.Web.HttpRequest.FillInFormCollection() d5fef840-8ad4-46a3-ab11-0b37346e7a9f

It turns out the submit form has too many post values. Adding following appSetting to the WebApplication's web.config (C:\inetpub\wwwroot\wss\VirtualDirectories\{WebApplication}\Web.config) resolves the problem:
 <appSettings>
     <add key="aspnet:MaxHttpCollectionKeys" value="2000" />
 </appSettings>
As the key name suggested it's an ASP.NET related setting. Why the error happens in SharePoint suddenly? We have installed some Microsoft and SharePoint security patches recently. The default maximum 500 post values policy was introduced by those patches, specifically from Critical MS11-100 patches.