Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Value cannot be null. Parameter name: serverContext

  Asked By: Alec    Date: Feb 01    Category: Sharepoint    Views: 3233

I'm creating a web part in VS2005. The webpart is being used (for
debugging) in an ASP .NET page in a different project in the same
solution as my web part. It's eventually going to be used on a
SharePoint site. Below is the code for the main function in the
webpart. The machine I'm developing on has the SQL & SharePoint site
running on it also. After line 07 executes, the object site appears
to be correct. After line 10 executes, the context object does not
appear correct. It has the values . . . Current: Nothing
Default: Microsoft.Office.Server.ServerContext
Status: Online {0} After line 11 execute, the profileManager object
seems to be correct. It has the proper number of profiles in the site,
etc, etc, etc But, after line 12 executes I get the exception error
"Value cannot be null. Parameter name: serverContext" If The context
object cannot be null, then how come line 11 seemed to work fine? I do
know that if I copy the webpart out to the SharePoint site referenced in
line 07 of the code and place it on a page there it will run ok in
SharePoint. But I shouldn't have to right? Isn't there a way to get
this to work in an ASP .NET page? 01 Public Function
GetUserProfileInfo(ByVal sAccount As String) As String
03 Dim context As ServerContext
04 Dim profileManager As UserProfileManager
05 Dim u As UserProfile
07 Dim site As New SPSite("http://omcit052691vm2:80
<http://omcit052691vm2/> ") 'My machine. My site.
09 Try
10 context = ServerContext.GetContext(site)
11 profileManager = New UserProfileManager(context)
12 u = profileManager.GetUserProfile(sAccount)
14 Catch ex As Exception
15 Return ex.Message
17 Finally
18 CType(site, IDisposable).Dispose()
20 End Try
22 Return u(PropertyConstants.HomePhone).Value.ToString
24 End Function



2 Answers Found

Answer #1    Answered By: Virendar Bahudur     Answered On: Feb 01

Try naming context  something else. There is a property of the page  which is
called context. This is often used to instantiate the site  object that you
are pointing at. You may actually have a naming conflict, so in line  10
context is not getting set.

Answer #2    Answered By: Sierra Beck     Answered On: Feb 01

I gave that a try but it did not make a
difference. Sure would like to be able to develople these things in VB
without having to put it in sharepoint  every time.

Didn't find what you were looking for? Find more on Value cannot be null. Parameter name: serverContext Or get search suggestion and latest updates.