- I started with the Silverlight Business Application Template
- I will call this MyApp and MyApp.Web
- I added a new SL application project.
- and added a ria link to the existing web project.
- I will call this Loader
This new SL app is the entry point of my solution, and basically loads the mainpage from the other xap file. Checks for updates, etc.
- I removed the App.xaml and App.xs files from MyApp
- Because Loader is now the Application
- I copied the relevant code from MyApp - App.cs to Loader - App.cs
- I added the relevant code from MyApp - App.xaml to Loader - App.xaml
- Mostly this is the WebContext stuff.
The problem is that the RIA Services generated code for Loader is not the same code as the code for MyApp
The generated code for MyApp contains the following namespaces:
- MyApp
- MyApp.Web
- MyApp.Web.Models
- MyApp.Web.Services
The generated code for Loader contains the namespace:
- Loader
The following line of code in Loader - App.cs throws InvalidOperationException.
WebCon开发者_如何学Gotext.Current.Authentication.LoadUser(this.Application_UserLoaded, null);
The error msg for the exception is:
The DomainContextType is null or invalid and there are no contexts generated from
AuthenticationBase<T>
I've had this same problem (with a similar setup) today. After looking around a little bit, I found this post on the silverlight forums which has the answer (look in the bottom for the solution, since there were some API changes in RIA Services).
Long story short, the issue is that your WebContext can't find the DomainContext (in this case an AuthenticationContext
) that handles LoadUser
in your case. to solve this problem you'll need to add the following to your App.xaml
:
<Application.ApplicationLifetimeObjects>
<dmnsvc:WebContext>
<dmnsvc:WebContext.Authentication>
<appsvc:FormsAuthentication>
<appsvc:FormsAuthentication.DomainContext>
<!--Your AuthenticationContext here-->
</appsvc:FormsAuthentication.DomainContext>
</appsvc:FormsAuthentication>
</dmnsvc:WebContext.Authentication>
</dmnsvc:WebContext>
</Application.ApplicationLifetimeObjects>
Hope this helps :)
精彩评论