Error 170 'WebContext' is not declared. It may be inaccessible due to its protection.
I get this error in 5 out of 6 silverlight projects that I have in my solution when I try to access the WebContext. In the one that is working I can see in the file in generated_code folder that it has this:
Partial Public NotInheritable Class WebContext
Inherits WebContextBase
And a whole heap of other stuff related to the WebContext so its working as it should. What am I doing wrong in the other projects? All the projects are targeting SL4.0 and is setup with a WCF RIA Services link to my server. I've spent hours on this not finding
any difference so some help is appreciated!
WebContext is not generated into class libraries, it will only be generated into your application library. If you need to reference it from other Silverlight libraries, it might be best to create an 'Application' library and manually author the WebContext
there. Getting this to work is a little tricky, but there have been a number of threads on the topic (WebContext/RiaContext) so take a look around.
My big problem is that this is C#, and I'm doing VB.NET - and also you telling me it's tricky and having 2778 points is not very encouraging for me beeing a noobie in Silverlight ;)
So - any easier solution or a VB.net version out there of what ColinBlair did? - Can it be an option to change all my classlibs to application libs - I'm using Prism..?
Question, one of my projects is working i.e getting the webcontext compiled into the generated code. This project is of templatetype Silverlight Business Application. The other 5 which are not working is of templatetype Silverlight Class Library. All of
these projects are setup in a MVVM and PRISM (the projects are modules in the bootstrapper) inspired solution. My question is, can I just convert the 5 Silverlight Class Library projects to type Silverlight Business Application? Or, should I use the third templatetype
WCF RIA Services Class Library?
I'm struggling to see the difference here.. What's really the diff between Silverlight Class Lib, Silverlight Business Application and WCF RIA Services Class Library - and what's the recommended setup when wanting to use PRISM and the Authentication Domain
Service in the Web project?
Going through Colin's guide would be a good place to start. The difference you're seeing is the Business Application Library is getting the WebContext type generated into it. As far as the compiler can tell, that's where you're defining the WebContext type
and the other libraries won't be able to see it unless they reference the Business Application Library. Changing the type of your libraries won't solve this issue (and will cause other problems).
Kyle, thanx again - I think I'm on the right path.
Colin's example was created with the WCF Ria Services PDC - not RC which I'm on. I have succesfully edited all the breaking changes in his example so I now have an working example constructed like this:
So, the BusinessApplicationTemplate.AppServices.csproj now holds the WebContext.cs, which I'm able to reach from my views in BusinessApplicationTemplate.csproj (LoginForm.xaml, does authenticate ok etc). So far, so very good :)
Now what I want to do is to take my BusinessApplicationTemplate.AppServices.csproj and BusinessApplicationTemplate.AppServices.Web.csproj into my original solution. This solution has, as mentioned before a PRISM/MVVM inspired setup. The solution contains 5 projects of templatetype Silverlight Class Library, 1 project of templatetype Silverlight Business Application and a Web project that hosts my xap file. Pretty basic setup that is.
My problem is that I dont really see the next step. I know I need to take my BusinessApplicationTemplate.AppServices.csproj and BusinessApplicationTemplate.AppServices.Web.csproj into the solution, but how can I reference the WebContext.cs in BusinessApplicationTemplate.AppServices.csproj from my Views in the Silverlight Class Libraries? Do I need to have an App.xml inside all of the Silverlight Class Libraries with a reference like this?
There is only one app.xaml needed in the entire application, all of your prism modules are automatically under that same application. In all of your libraries you can get the current web context by calling WebContextBase.Current. That will return the WebContext
that was registered in the app and you will be able to see the base methods and the IPrincipal version of the user object. If you need access to more then just the base level interfaces of the WebContext then you will need to add a reference from your module
to the AppServices library. Again, you get the app's WebContext by calling the WebContext.Current property.
Mcad01
Member
97 Points
148 Posts
WebContext is not declared/inaccessible
May 03, 2010 02:20 PM | LINK
Error 170 'WebContext' is not declared. It may be inaccessible due to its protection.
I get this error in 5 out of 6 silverlight projects that I have in my solution when I try to access the WebContext. In the one that is working I can see in the file in generated_code folder that it has this:
And a whole heap of other stuff related to the WebContext so its working as it should. What am I doing wrong in the other projects? All the projects are targeting SL4.0 and is setup with a WCF RIA Services link to my server. I've spent hours on this not finding any difference so some help is appreciated!
Carlos63
Member
289 Points
81 Posts
Re: WebContext is not declared/inaccessible
May 03, 2010 02:49 PM | LINK
Is your project referencing the assembly: System.ServiceModel.DomainServices.Client.Web? This is the assembly where the WebContextBase resides.
Blog
Twitter
kylemc
Contributor
7243 Points
1147 Posts
Microsoft
Re: WebContext is not declared/inaccessible
May 03, 2010 05:46 PM | LINK
WebContext is not generated into class libraries, it will only be generated into your application library. If you need to reference it from other Silverlight libraries, it might be best to create an 'Application' library and manually author the WebContext there. Getting this to work is a little tricky, but there have been a number of threads on the topic (WebContext/RiaContext) so take a look around.
Kyle
Mcad01
Member
97 Points
148 Posts
Re: WebContext is not declared/inaccessible
May 04, 2010 12:18 PM | LINK
kylemc, you're right - the reason for my problems is that I have class libs - the one that works is an application lib. Thanx!
Ok, So i need to get all my classlibs working with this, I found this post by ColinBlair about the project and will try that: "I have my WebContext in its own class library which I call AppServices. I have a blog post about it at http://www.riaservicesblog.net/Blog/post/RIA-Services-Enterprise-Business-Application-Attempt-Part-One.aspx and a set of videos showing how I did it at http://www.riaservicesblog.net/Blog/post/RIA-Services-Enterprise-Business-Application-The-Movie.aspx. With the AppServices library you can just reference that library from any of your other projects to access the WebContext"
My big problem is that this is C#, and I'm doing VB.NET - and also you telling me it's tricky and having 2778 points is not very encouraging for me beeing a noobie in Silverlight ;)
So - any easier solution or a VB.net version out there of what ColinBlair did? - Can it be an option to change all my classlibs to application libs - I'm using Prism..?
kylemc
Contributor
7243 Points
1147 Posts
Microsoft
Re: WebContext is not declared/inaccessible
May 04, 2010 02:21 PM | LINK
Sorry, didn't mean to scare you. I'd recommend following Colin's guide. It will work best for you if you're using prism.
Kyle
Mcad01
Member
97 Points
148 Posts
Re: WebContext is not declared/inaccessible
May 05, 2010 08:30 AM | LINK
Thanx Kyle, no problem :)
Question, one of my projects is working i.e getting the webcontext compiled into the generated code. This project is of templatetype Silverlight Business Application. The other 5 which are not working is of templatetype Silverlight Class Library. All of these projects are setup in a MVVM and PRISM (the projects are modules in the bootstrapper) inspired solution. My question is, can I just convert the 5 Silverlight Class Library projects to type Silverlight Business Application? Or, should I use the third templatetype WCF RIA Services Class Library?
I'm struggling to see the difference here.. What's really the diff between Silverlight Class Lib, Silverlight Business Application and WCF RIA Services Class Library - and what's the recommended setup when wanting to use PRISM and the Authentication Domain Service in the Web project?
kylemc
Contributor
7243 Points
1147 Posts
Microsoft
Re: WebContext is not declared/inaccessible
May 05, 2010 03:32 PM | LINK
Going through Colin's guide would be a good place to start. The difference you're seeing is the Business Application Library is getting the WebContext type generated into it. As far as the compiler can tell, that's where you're defining the WebContext type and the other libraries won't be able to see it unless they reference the Business Application Library. Changing the type of your libraries won't solve this issue (and will cause other problems).
Kyle
Mcad01
Member
97 Points
148 Posts
Re: WebContext is not declared/inaccessible
May 07, 2010 01:47 PM | LINK
Kyle, thanx again - I think I'm on the right path.
Colin's example was created with the WCF Ria Services PDC - not RC which I'm on. I have succesfully edited all the breaking changes in his example so I now have an working example constructed like this:
Solution 'BusinessApplicationTemplate' (Folder) BusinessApplicationTemplate.AppServices BusinessApplicationTemplate.AppServices.csproj BusinessApplicationTemplate.AppServices.Web.csproj BusinessApplicationTemplate.csproj BusinessApplicationTemplate.Web.csprojSo, the BusinessApplicationTemplate.AppServices.csproj now holds the WebContext.cs, which I'm able to reach from my views in BusinessApplicationTemplate.csproj (LoginForm.xaml, does authenticate ok etc). So far, so very good :)
Now what I want to do is to take my BusinessApplicationTemplate.AppServices.csproj and BusinessApplicationTemplate.AppServices.Web.csproj into my original solution. This solution has, as mentioned before a PRISM/MVVM inspired setup. The solution contains 5 projects of templatetype Silverlight Class Library, 1 project of templatetype Silverlight Business Application and a Web project that hosts my xap file. Pretty basic setup that is.
My problem is that I dont really see the next step. I know I need to take my BusinessApplicationTemplate.AppServices.csproj and BusinessApplicationTemplate.AppServices.Web.csproj into the solution, but how can I reference the WebContext.cs in BusinessApplicationTemplate.AppServices.csproj from my Views in the Silverlight Class Libraries? Do I need to have an App.xml inside all of the Silverlight Class Libraries with a reference like this?
<Application.ApplicationLifetimeObjects> <appServices:WebContext> <appServices:WebContext.Authentication> <appsvc:FormsAuthentication/> <!--<appsvc:WindowsAuthentication/>--> </appServices:WebContext.Authentication> </appServices:WebContext> </Application.ApplicationLifetimeObjects>Someone help me with this last bit of wiring puzzle please :)ColinBlair
All-Star
29787 Points
5012 Posts
Re: WebContext is not declared/inaccessible
May 07, 2010 02:24 PM | LINK
Upshot Blog
ColinBlair on Twitter
MVVM and RIA Services
Mcad01
Member
97 Points
148 Posts
Re: Re: WebContext is not declared/inaccessible
May 09, 2010 07:03 PM | LINK
Thanx Colin, I will give it a try when I get back to work tommorow. You're exellent blog has helped me a lot, keep up the good work! :)