Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

custom web service generating Operation is not valid due to the curr

  Asked By: Harshini    Date: Feb 12    Category: Sharepoint    Views: 2600

I'm trying to write a custom web service that returns all webs that a
user has full control of. However, I get a "Server was unable to
process request. --> Operation is not valid due to the current state
of the object." error. This is what the code looks like:

public string GetWebs()
string info = string.Empty;
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
Type groupType = typeof(SPGroup);
Type userType = typeof(SPUser);

// site.AllWebs seems to generate the error; all code in the
// foreach loop is commented out.
foreach (SPWeb web in site.AllWebs)
} // end foreach web

} // end using

return info;

The event log was initially reporting a DCOM error with IIS WAMREG,
but I gave the account launch and local activation rights. Now, I get
no clue from the event log.

Does any one have an idea of what's going on?



1 Answer Found

Answer #1    Answered By: Brooke Lewis     Answered On: Feb 12

I figured out my problem. SPContext.Current does not exist when run
inside of SPSecurity.RunWithElevatedPrivileges(). I had to save the
Guid of the site  before entering the elevated state.