Tag Archives: Silverlight

InvalidOperationException in Silverlight designer

After creating a BasePage for all my pages and moving the DomainContext initialization to the base class, I got this design time error:

The current instance of WebContext is not available. You must instantiate a WebContext and add it to Application.ApplicationLifetimeObjects within the default App constructor.

Looks like a Silverlight bug, but all I did is checking the design time at the beginning of the constructor:

public BasePage()
{
   if (DesignerProperties.IsInDesignTool) return;
   ...
}

That’s it!

Create base page for Silverlight Page

If you would like to create a base page with common functionality – create your own base page and derive each new page from the base class.

Create BasePage.cs

namespace MyApp.Views
{
    public class BasePage:Page
    {
    }
}

Derive the real page from the BasePage.cs

namespace MyApp.Views
{
    public partial class NewPage: BasePage
    {
    }
}

Now if you compile the project you will get the following error:
Partial declarations of ‘MyApp.Views.NewPage’ must not specify different base classes

Here you should do two more steps: Read more »