locked
Hybrid JS and C# and Expression Blend

    Question

  • Hi,

    I am building an hybrid app with a WinJS based UI over C# based data sync layer (basically, the C# part of the project maintain a local cache and push events to the UI when new things that might interest the currently displayed view are downloaded). At runtime everything is fine, but I am unable to load the project in Expression Blend. When I open my default.html file, Blend is doing stuff during a couple of seconds and then display an unuseful message: An error was encountered while editing this document. Reload the document to try again.

    Of course, clicking the reload button does not resolve the problem.

    Is this a known issue ? Do I have to register my WinMD C# component somewhere in Blend to make it available for loading ? Thanks in advance !

    I am using VS 2012 RC and Blend 2012 RC on Windows 8 RP.

    Simon

    Friday, June 1, 2012 12:07 PM

All replies

  • I m not able to repro this issue. Here are the steps I followed.

    1. Created a New Blank HTML App in Visual Studio
    2. Created a C# Windows Runtime Component in Visual Studio
    3. Added a reference between the HTML App and C# Windows Runtime Component
    4. Save All
    5. Project Context Menu - > Open in Blend

    I can open the default.html just fine. Let me know if I missed something.


    Dev@Mic

    Friday, June 1, 2012 3:12 PM
  • Hi,

    I investigated a bit more the issue, and it seems to be a subtle bug in Blend Designer:

    My C# component captures the SynchronizationContext (SynchronizationContext.Current) when the JS component invokes it in order to dispatch events from background tasks (which are CPU intensive) back into the WinJS UI thread. If I don't do this, when I raise an event I receive a strange "InvalidCastException".

    At runtime, SynchronizationContext.Current is correctly populated. When run Inside Blend, SynchronizationContext.Current is null and my component throws an exception.

    This is a big issue for me, because I am not able to find another way to come back to the UI thread when invoked from JS than using the SynchonizationContext.

    However, if you have a workaround that works at runtime AND at design-time, please share the info !

    Friday, June 1, 2012 4:27 PM
  • In design time the Dispatcher (CoreDispatcher) object is null. I believe this is the root cause of the issue that you are seeing. Have you considered wrapping the SynchronizationContext.Current call in a ApplicationModel.DesignModeEnabled flag. This should unblock you from opening the file.

    Dev@Mic


    Friday, June 1, 2012 7:30 PM
  • Hi,

    That is a real problem, because without capturing the synchronization context at design time, I cannot raise the events either in Blend. And all the data populating the view (those I really need when designing my app) come trough these events...

    Just not being able to rely on the Synchronization Context is too much an issue for me (a workaround to this, would be to generate design time specific data and raise the event in the "start" method of my local cache synchronization engine at design time, instead of starting my background tasks. It would work, but it forces me to maintain 2 different branches of my code : 1 for runtime, and 1 for design time. that is very far to ideal).

    Saturday, June 2, 2012 7:40 AM
  • Thanks for the feedback. We will look into solving this problem in one of the future releases of Visual Studio. I agree its a painful workaround ,If you can share your Data Model with me at harikm (at) microsoft (dot) com , we can try to figure out if there is an easier way to get around this issue


    Dev@Mic



    Monday, June 4, 2012 7:30 PM