Exception in WinRT app with CCApplication.Create

crpietschmanncrpietschmann USMember

I have the following code in a WinRT app for Windows 8.1 that I'm trying to use CocosSharp in but it throws an Exception:

public MainPage()
    CocosSharp.CCApplication.Create(new AppDelegate());

The following exception is getting thrown on the "CCApplication.Create" call:

An exception of type 'System.Exception' occurred in CocosSharp.DLL but was not handled in user code
Additional information: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

I couldn't find any WinRT Samples, so I started building out my WinRT app based on what's in the Windows Phone 8 samples. I think I have the setup correct which would indicate a bug in CocosSharp rather than an issue with my setup. I tried troublshooting by copying the contents of the "CCApplication.Create" method into my app and Identified that the call to "Windows.ApplicationModel.Core.CoreApplication.Run(factory)" is the line that is throwing the exception; plus the factory delegate isn't getting fired so it isn't anything to do with my "AppDelegate" class.

Could someone point me in the right direction to fix this, or identify if it might be a bug in CocosSharp?


  • crpietschmanncrpietschmann USMember

    It appears that the UI Thread for the WinRT XAML conflicts with the "CCApplication.Create" call so you can't initialize the CocosSharp AppDelegate within the constructor of a XAML Page... :(

    Fortunately, "netonjm" updated the CocosSharp samples with WinRT solutions. The entry point for a WinRT app must be a static class and method just like a standard Windows Console app. Here's the working call to "CCApplication.Create" necessary:

    public static class Program
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
            CCApplication.Create(new AppDelegate());

    It would appear this means you can't mix both XAML and CocosSharp within the same app?... Anyway, hope this info helps someone else out.

  • JoseMedranoJoseMedrano ESMember

    This static method is used to create the XAML dynamic.

    But sure you can skip this and make the classic way (likes WP8).

  • CraigSteeleCraigSteele USMember

    All of the examples use the static method. How do we implement it in WinRT using XAML like in WP8? WinRT does not support the XAML element.

  • crpietschmanncrpietschmann USMember

    There seems to be some platform differences causing the implementation difference between Win8 and WinPhone8. The Win8 app uses WinRT and the WinPhone8 support for CocosSharp uses the Silverlight project type. CocosSharp doesn't currently support Windows Phone 8.1 WinRT application type. This is also the same way that MonoGame is pulled in to Win8 apps, so this is likely due to the dependency on MonoGame underneath.

    Using the static method with Win8 apps to pull in CocosSharp doesn't seem to be a problem.

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    I finally have a Windows 8.1 environment with VS2013 installed. I will be taking a look at this. Thank you for letting us know.

Sign In or Register to comment.