共用方式為


Troubleshooting porting Windows Phone Silverlight to Windows Runtime 8

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Note  For info about porting to a Universal Windows Platform (UWP) app for Windows 10, see Troubleshooting.

 

The previous topic was Porting the project.

We highly recommend reading to the end of this porting guide, but we also understand that you're eager to forge ahead and get to the stage where your project builds and runs. To that end, you can make temporary progress by commenting or stubbing out any non-essential code, and then returning to pay off that debt later. The table of troubleshooting symptoms and remedies in this topic may be helpful to you at this stage, although it's not a substitute for reading the next few topics. You can always refer back to the table as you progress through the later topics.

Using a binary split to track down issues

If your app terminates and all you know is that an unhandled exception was thrown during XAML markup parsing, then that could be the result of a reference to a missing resource (that is, a resource whose key exists for the Windows Phone Silverlight platform but not for the Windows Runtime platform, such as some system TextBlock Style keys). Or it could be an exception thrown inside a UserControl, a custom control, or a custom layout panel.

If the issue isn't immediately obvious, then tracking it down might require a binary split. Remove about half of the markup from a Page and re-run the app. You will then know whether the error is somewhere inside the half you removed (which you should now restore in any case) or in the half you did not remove. Repeat the process by splitting the half that contains the error, and so on, until you've zeroed in on the issue.

Troubleshooting symptoms and remedies

The remedy information in the table is intended to give you enough info to unblock yourself. You'll find further details about each of these issues as you read through later topics.

Symptom Remedy
The XAML compiler gives the error "XAML files '<page path and name>' and '<path to Shared project folder><page path and name>' have the same project path '<page path and name>'. Each file must have a unique project path." A XAML file in the Shared project is duplicated in either the Windows project node, the Windows Phone project node, or both. You probably just want to keep the Shared version because the others are likely the empty versions that Visual Studio generated.
The XAML parser or compiler gives the error "The name "<typename>" does not exist in the namespace […]." If <typename> is a custom type then, in your namespace prefix declarations in XAML markup, change "clr-namespace" to "using", and remove any assembly tokens. For platform types, this means that the type doesn't apply to the Windows Runtime, so find the equivalent and update your markup. Examples you might encounter right away are phone:PhoneApplicationPage and shell:SystemTray.IsVisible.
The XAML parser or compiler gives the error "The member "<membername>" is not recognized or is not accessible." or "The property "<propertyname>" was not found in type [...].". These errors will begin to show up after you've ported some type names, such as the root Page. The member or property doesn't apply to the Windows Runtime, so find the equivalent and update your markup. Examples you might encounter right away are SupportedOrientations and Orientation.
The XAML parser or compiler gives the error "The attachable property [...] was not found [...]." or "Unknown attachable member [...].". This is likely to be caused by the type rather than the attached property, in which case you will already have an error for the type and this error will go away once you fix that. Examples you might encounter right away are phone:PhoneApplicationPage.Resources and phone:PhoneApplicationPage.DataContext.
The XAML parser or compiler gives the error "The resource "<resourcekey>" could not be resolved.". The resource key doesn't apply to the Windows Runtime, so find the equivalent and update your markup. Examples you might encounter right away are system TextBlock Style keys such as PhoneTextNormalStyle.
The C# compiler gives the error "The type or namespace name '<name>' could not be found [...]" or "The type or namespace name '<name>' does not exist in the namespace [...]" or "The type or namespace name '<name>' does not exist in the current context". This is likely to mean that the compiler doesn't yet know the correct Windows Runtime namespace for a type. You can use Visual Studio's Resolve command to fix that. In other cases, the port will be less straightforward. Examples you might encounter right away are DesignerProperties and BitmapImage.
When run on the device the app terminates, or when launched from Visual Studio you see the error “Unable to activate Windows Store app […]. The activation request failed with error ‘Windows was unable to communicate with the target application. This usually indicates that the target application’s process aborted. […]”. The problem could be the imperative code running in your own Pages or in bound properties (or other types) during initialization. Or it could be happening while parsing the XAML file about to be displayed when the app terminated (if launching from Visual Studio, that will be the startup page). Look for invalid resource keys, and/or perform a binary split as described in the paragraph above this table.
XamlCompiler error WMC0055: Cannot assign text value '<your stream geometry>' into property 'Clip' of type 'RectangleGeometry' In the Windows Runtime, the type of the Clip property is RectangleGeometry, so you can only clip a rectangular region. Delete the Clip attribute and add it as property element syntax similar to the following: <UIElement.Clip><RectangleGeometry Rect="10 10 50 50"/></UIElement.Clip>. Note that you can use arbitrary geometry as a mask in a layer with Direct2D in a Microsoft DirectX and XAML C++ Windows Runtime app.
XamlCompiler error WMC0001: Unknown type 'RadialGradientBrush' in XML namespace [...] The Windows Runtime doesn't have the RadialGradientBrush type. Remove the RadialGradientBrush from markup and use some other type of Brush. In some cases a raster image is an acceptable compromise. Note that you can create a radial gradient brush with Direct2D in a Microsoft DirectX and XAML C++ Windows Runtime app.
XamlCompiler error WMC0011: Unknown member 'OpacityMask' on element '<UIElement type>' The Windows Runtime UIElement type doesn't have the OpacityMask property. Remove the OpacityMask from markup. If your use case is to display a raster suitable for light and dark themes then see the Media section in the next topic. In some cases a raster image is an acceptable compromise. Note that you can create an opacity mask with Direct2D in a Microsoft DirectX and XAML C++ Windows Runtime app.
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in SYSTEM.NI.DLL. Additional information: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)). The work you're doing needs to be done on the UI thread. Call the CoreDispatcher.RunAsync method to achieve that. You can obtain a CoreDispatcher from the CoreWindow.Dispatcher property (and the current CoreWindow instance can be obtained by calling CoreWindow.GetForCurrentThread).
An animation is running, but it's having no effect on its target property. Either make the animation independent, or set EnableDependentAnimation="True" on it. See Animation.

 

The next topic is Porting XAML and UI.