Pages

September 20, 2014

List view with GroupBy error: Attempted to use an object that has ceased to exist


Error Scenario:
In SharePoint, when navigating to a list view page (ex: 'All Items' view), or to a site page (like home page) that contains a list view web part, the page crashes, throwing the following error:

Server Error in '/' Application.

Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED)) 


Debugging:
We know its something with list that causes the error, could be the view itself, or the columns or even something with the content types. The problem is that you cannot reach the list settings because 

1. Using PowerShell to get ID of the list and store it on text file:

$rrdbWeb = Get-SPWeb “http://{sitename}”
$rrdbWeb.Lists[“{listname}”].ID > C:\ListID.txt

Example result: 522ba78b-f2e4-4335-b3e3-2a0ff6bb6d2e

 2. Manually construct list settings page url by adding the list ID as parameter to listedit.aspx page:

http://{sitename}/_layouts/listedit.aspx?List={522ba78b-f2e4-4335-b3e3-2a0ff6bb6d2e}

3.  Create new personal view 

4. Using PowerShell to get ID of the problematic view:

$rrdbWeb.Lists[“{listname}”].Views[“{viewname}’].ID > C:\ViewID.txt

Example result: c6a3293a-377d-4757-b5f3-26de78564f04

5. Remember to dispose objects you created  in PowerShell like $rrdpWeb when you finish

6. Manually construct the modify page for the problematic view, by adding List & View parameters to ViewEdit.aspx page:

http://{sitename}/_layouts/ViewEdit.aspx?List={522ba78b-f2e4-4335-b3e3-2a0ff6bb6d2e}&View={c6a3293a-377d-4757-b5f3-26de78564f04}

 Now have a look on all details of this view. 

7. Create Another view (I prefer personal one) & enter the exact same details from the our original view. The objective here is to be able to replicate and test the error. After playing with details, I found that GroupBy option is causing the error. When GroupBy is not used then view works perfectly well!


Root Cause:
The error is thrown because of the resource throttling in that list. The GroupBy is counting & folding too many items causing SharePoint to prevent the SQL server from processing the view query. When checking the number of items in list settings page, it shows it had 18670 items (way above the default list view threshold of 5000).


Solution:
The fix is to enable larger resource throttling for the target web application.
Example: In this case I set to 20000.

From Central Administration site > Manage Web Applications > select target web app > General Settings > Resource Throttling > change List View Threshold > OK

Note: there is a reason of why Microsoft set the default theshold into 5000 which is to avoid getting a performance hit on SQL server by queries on too many items. When you have very large lists or libraries, try to think about alternative approaches to divide the data, such as split into multiple lists, or using folders in case of document libraries.





May 2, 2014

Show More Field Info on List Settings Page




I thought it would be useful for the SharePoint site admin to see additional info about the columns in list, so decided to customize the list edit page (/_layouts/listedit.aspx) to display the internal name, ID and validation info for each column.

Previous work:
I found this post where it shows how to display the internal name for columns. The idea is nice but the description was not very clear. So I decided to write a post on how to do it with adding additional column info bu leveraging more properties from SPField class.

Before you begin:
Changes to SharePoint OTB files in not recommended. You can always create your custom page for example: ListEditEx.aspx and redirect to it through a custom navigation link or a ribbon button. But for the sake of simplicity, I am assuming your are working on a dev environment to test this customization.

Steps:
1. Backup the out-of-the-box (original) listedit.aspx file.


2. In page code, look for the following for statement line:
for (Int32 iIndex = 0; iIndex < spFields.Count; iIndex ++ )


3. Add the headers cells in the table row immediately before the for statement from step 2:
<th scope="col" class="ms-vh2-nofilter" width="15%" id="1900">Internal Name</th>
<th scope="col" class="ms-vh2-nofilter" width="25%" id="2000">ID</th>
<th scope="col" class="ms-vh2-nofilter" width="25%" id="2100">Validation Formula</th>

   You can adjust the width parameter for all columns to your needs.


4. In code after the for statement, look for condition:
if ((spField.ReadOnlyField && !bCountRelated && !bMcolLookup) || spList.HasExternalDataSource)


5. Add the following code cells under each switch statement for that condition (from step 4), and inside the Else statement
<td><%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%></td>
<td><%SPHttpUtility.UrlKeyValueEncode(spField.Id.ToString(), Response.Output);%></td>
<td><%Response.Output.Write(spField.ValidationFormula);%></td>

Notice that you don't want to use the UrlKeyValueEncode() method on the validation formula (last line above) because validation formula contains special characters that needed to be shawn as is.

For example:
Below is the default switch case code where I highlighted the added custom lines.

default:
if (!spField.Hidden)
{
  if (spField.XPath != null || spList.HasExternalDataSource)
  {
%>
    <tr class="<%=rowClass%>">
    <td class="ms-vb2">
       <%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%>
    </td>
    <td class="ms-vb2"><%SPHttpUtility.HtmlEncode(spField.TypeDisplayName, Response.Output);%></td>
    <td colspan="2" class="ms-vb2">
        <% if ( !spList.ContentTypesEnabled && spField.Required == true ) { %> <img      src="/_layouts/images/check.gif" alt="Checked"> <% ; } %>
        <%SPHttpUtility.HtmlEncode(GetUsedIn(spField), Response.Output);%>
    </td>
    <td><%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%></td>
    <td><%SPHttpUtility.UrlKeyValueEncode(spField.Id.ToString(), Response.Output);%></td>
    <td><%Response.Output.Write(spField.ValidationFormula);%></td>
    </tr>
<%
   }
}


6. Save the ListEdit.aspx page and test from any list settings to see the additional column info.

April 25, 2014

PowerShell Cheat Sheet

Found a handy reference here for using PowerShell combined with commands for SharePoint.

Original post is: http://sharepointjack.com/2013/powershell-cheat-sheet-v2-00/
The authors did a nice job illustrating the commands and use in a straight forward way!

PS sheet image

Happy PowerShelling!

April 16, 2014

User Profile JobTitle Property Returns Null

Problem:

Using SharePoint Object Model, the JobTitle property will always return NULL value for all users, even when users have valid user profiles with available Job Title property and is accessible from CA.

Example: I highlighted the code where JobTitle returns Null:
bool UserExist = uprofileManager.UserExists(user.LoginName);
if (UserExist)
{
UserProfile userProfile = uprofileManager.GetUserProfile(user.LoginName);
returnValue = (String)userProfile[PropertyConstants.JobTitle].Value;
}

While the same user has a Job Title value in his user profile:



Digging for Answers:

- First, I made sure that Job Title property accessibility is set to 'Everyone' in Central Admin
- I elevated the code privileges by using SPSecurity.RunWithElevatedPrivilages code block
- Also while debugging the code, I made sure the user.LoginName variable is in format "Domain\Username"
- Also, found that code to read SPS-JobTitle property would return Null too:
returnValue = (String)userProfile["SPS-JobTitle"].Value; // returns null

- However, all other user profile PropertyConstant properties (like Office, HomePhone,..) are readable correctly for the same users:
PropertyCollection props = uprofileManager.Properties;
UserProfile userProfile = uprofileManager.GetUserProfile(user.LoginName);
foreach (Property prop in props)
{
    Console.WriteLine(prop.Name.ToString() + "=" + userProfile[prop.Name].Value);
}


I concluded that its not the code that has issues, so there must be something with 'Title' and 'SPS-JobTitle' properties preventing the code from reading them.

We know that Title and SPS-JobTitle are special properties linked to Metadata keywords when profile import takes place from Active Directory. The Metadata service is running on 2 servers: WFE & APP. From Central Administration, I can access the Metadata service normally, and see all the Enterprise keywords (System -> Keywords) in Metadata Term Store without an issue.

Okay, now let's have a look on ULS logs. I found errors & highlighted the important lines:

1) Error in Topology:
SharePoint Web Services Round Robin Service Load Balancer Event: EndpointFailure Process Name: UserProfileImport Process ID: 10560 AppDomain Name: UserProfileImport.exe AppDomain ID: 1 Service Application Uri: urn:schemas-microsoft-com:sharepoint:service:02cb72f4a15149bd848db2ba8ab1f055#authority=urn:uuid:235674f601ec4ef1ae9cb964c49bf0d6&authority=https://usascsppro03-nt:32844/Topology/topology.svc Active Endpoints: 1 Failed Endpoints:1 Affected Endpoint: http://usascsppro04-nt:32843/02cb72f4a15149bd848db2ba8ab1f055/MetadataWebService.svc


2) Then error in Manages Metadata service:
Failed to get term store for proxy 'Managed Metadata Service'. Exception: System.ServiceModel.ServerTooBusyException: The HTTP service located
 at http://usascsppro04-nt:32843/02cb72f4a15149bd848db2ba8ab1f055/MetadataWebService.svc is too busy.  ---> System.Net.WebException: The remote server returned an error: (503) Server Unavailable.   
 at System.Net.HttpWebRequest.GetResponse()    
 at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)     -
 -- End of inner exception stack trace ---    Server stack trace:    
 at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)   
 at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)   
 at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)   
 at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)   
 at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)   
 at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)   
 at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)   
 at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)    Exception rethrown
 at [0]:    
 at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)   
 at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)   
 at Microsoft.SharePoint.Taxonomy.IMetadataWebServiceApplication.GetServiceSettings(Guid rawPartitionId)   
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.<>c__DisplayClass2f.<ReadApplicationSettings>b__2e(IMetadataWebServiceApplication serviceApplication)   
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.<>c__DisplayClass2c.<RunOnChannel>b__2b()   
 at Microsoft.Office.Server.Security.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)   
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.<>c__DisplayClass2c.<RunOnChannel>b__2a()   
 at Microsoft.Office.Server.Utilities.MonitoredScopeWrapper.RunWithMonitoredScope(Action code)   
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.RunOnChannel(CodeToRun codeToRun, Double operationTimeoutFactor)   
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.ReadApplicationSettings(Guid rawPartitionId)   
 at Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplicationProxy.GetTermStoreId(Guid rawPartitionId)   
 at Microsoft.SharePoint.Taxonomy.Internal.DataAccessManager.GetTermStoreData(MetadataWebServiceApplicationProxy sharedServiceProxy)


3) Then a warning:
The managed Metadata Service ‘Managed Metadata Service’ is inaccessible.

Interestingly, when browsing the Metadata service in IIS:
- MetadataWebService.svc is not available in WFE server (HTTP Error 503)
- MetadataWebService.svs is available in APP server


Root Cause:

It appeared that this all related to an issue Managed Metadata service leading to the issue in SharePoint topology (load balancer) service officially known as "Application Discovery and Load Balancer Service Application".

The Managed Metadata service was setup to work on both WFE and APP servers. on WFE, the Metadata was not working as we saw the HTTP error 503. But that was not a problem since the other Metadata service works fine on the APP server, hence the perfectly fine keywords & user profile accessibility. However, the topology (load balancer) service was having an issue, because it basically round-robin requests to services if we have more than one server to offer these services. Since the Metdata data service is not working in WFE then it's end-point will not be valid. But topology service still thinks it is a perfectly valid end-point and keep trying to connect to the Metdata service through that faulty endpoint, until a connection time-out occurs and a 'server unavailable' exception is thrown in log.


Solution:

  1. Stop the faulty Managed Metadata service (in this case on WFE) from CA             
  2. In some cases, you need to stop/start Metadata service on other server too to refresh the endpoints
  3. Stop then restart the application pool of faulty Topology application from IIS (in this case on WFE)
  4. Make sure all application pools are started normally


Result:

After applying steps above, the Metadata term store & User profiles work normally. Code able to read the values for JobTitle property for all users.


Useful resources:
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/869fb269-2a6b-4efa-a0e0-c4a829065ca4/load-balancer-error-mesaage?forum=sharepointadminprevious

http://blog.henryong.com/2011/10/18/sharepoint-2010-intermittent-search-errors-web-services-round-robin-service-load-balancer-event-endpointfailure/

http://www.mysharepointadventures.com/2012/03/event-8313-topology-load-balancer-endpointfailure-searchservice-svc/

http://blogs.msdn.com/b/russmax/archive/2010/05/06/sharepoint-2010-shared-service-architecture-part-2.aspx

https://adammcewen.wordpress.com/2012/12/14/redirecting-user-profile-sp-job-titles-to-mmd-term-set/