Tuesday, January 19, 2010

Troubleshooting “An unexpected error has occurred” in SharePoint

Typical scenario in SharePoint Projects on hosted environment where Developers don’t have access to server:


Developer 1: SharePoint is throwing “An unexpected error has occurred” without giving any other information.

Developer 2: Did you try updating your Web.Config ? You need to set CallStack to false and customErrors mode to “Off”

Developer 1: Duh, I would have done that first thing if I had access to the server. I am working on a hosted SharePoint environment. I don’t have remote access to the machine, the event viewer and log files.

Developer 2: Then you are gone. Nothing can be done.

Developer 1: Oh God, Please Help Me!


You may face such scenarios in your project, don’t get tensed and give up. You need patience and common sense in such situations.

You can try to identify the root cause of the error in a methodical manner.

Step 1: Determine whether the error is at page level, page layout or master page.

Browse through different pages created using same layout. If the error is observed on Page A but not on Page B, the error is most likely on page A.

Browse through pages created using different layout. If error is observed on pages based on layout X, but not on pages based on layout Y, the error is most likely with the page layout X.

Temporarily change your Site or System master page. If changing the master page fixes the error, the error is most likely on the master page.

Step 2: Identify the control throwing the error.

Create a temporary copy of the page/ page layout / master page.

On the temporary copy, keep deleting chunks of code (table, div tag, control, webpart) and refresh the page in the browser till your page starts working. If your page stopped throwing error after removing control X, the error is likely to be in control X.

You can also do the reverse by starting with a blank page layout or master page, and adding controls one at a time till your page breaks.

Step 3: Fix the broken or corrupted control.

Once the control throwing error has been identified, your job is easier. Look for invalid attributes, properties, missing tags, dependencies, compare with implementation in default or other custom pages.

This simple approach has helped us troubleshoot issues on multiple occasions.

Developer 1: I found the issue, and fixed it.
Developer 2: Wow! You are the real SharePoint Guru.
Client: Great work. You are rock stars!

Note: Do not forget to hide your temporary pages from navigation while you are troubleshooting. And do not forget to delete them once you are done.

Monday, January 04, 2010

Installing SharePoint 2010 on Win 7 64 bit OS

With the intention of installing SharePoint 2010 on my box, I switched my OS to 64 bit version of Win 7.

To install SharePoint 2010, I followed the steps mentioned in MSDN article http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx . There were few hiccups that I had while running  the SharePoint configuration wizard, and have described the solutions below for the benefit of all.
--------------------------------------------------------------------------------------------------
1) Error: Failed to create the configuration database.

An exception of type Microsoft.SharePoint.SPException was thrown. Additional exception information: User cannot be found.

Microsoft.SharePoint.SPException: User cannot be found.

at Microsoft.SharePoint.Administration.SPSiteCollection.Add(SPContentDatabase database, SPSiteSubscription siteSubscription, String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, String quotaTemplate, String sscRootWebUrl, Boolean useHostHeaderAsSiteName)

at Microsoft.SharePoint.Administration.SPSiteCollection.Add(SPSiteSubscription siteSubscription, String siteUrl, String title, String description, UInt32 nLCID, String webTemplate, String ownerLogin, String ownerName, String ownerEmail, String secondaryContactLogin, String secondaryContactName, String secondaryContactEmail, Boolean useHostHeaderAsSiteName)

at Microsoft.SharePoint.Administration.SPAdministrationWebApplication.CreateDefaultInstance(SqlConnectionStringBuilder administrationContentDatabase, SPWebService adminService, IdentityType identityType, String farmUser, SecureString farmPassword)

at Microsoft.SharePoint.Administration.SPFarm.CreateAdministrationWebService(SqlConnectionStringBuilder administrationContentDatabase, IdentityType identityType, String farmUser, SecureString farmPassword)

at Microsoft.SharePoint.Administration.SPFarm.CreateBasicServices(SqlConnectionStringBuilder administrationContentDatabase, IdentityType identityType, String farmUser, SecureString farmPassword)

at Microsoft.SharePoint.Administration.SPFarm.Create(SqlConnectionStringBuilder configurationDatabase, SqlConnectionStringBuilder administrationContentDatabase, IdentityType identityType, String farmUser, SecureString farmPassword, SecureString masterPassphrase)

at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.CreateOrConnectConfigDb()
at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.Run()
at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()
--------------------------------------------------------------------------------------------------

Solution: You need to be connected to the network/domain while running the SharePoint configuration wizard.
--------------------------------------------------------------------------------------------------
 
2) Error: Failed to create the configuration database.


An exception of type System.Security.Cryptography.CryptographicException was thrown. Additional exception information: The data is invalid.



System.Security.Cryptography.CryptographicException: The data is invalid.

at System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData, Byte[] optionalEntropy, DataProtectionScope scope)

at Microsoft.SharePoint.Administration.SPCredentialManager.get_MasterKey()
at Microsoft.SharePoint.Administration.SPCredentialManager.GetFarmEncryptionKey()
at Microsoft.SharePoint.Administration.SPCredentialManager.EncryptWithMasterKey(SecureString sstrPassphrase)
at Microsoft.SharePoint.Administration.SPEncryptedString.SetSecureStringValue(SecureString sstrValue)
at Microsoft.SharePoint.Administration.SPCertificateAuthority.Provision()
at Microsoft.SharePoint.Administration.SPFarm.Create(SqlConnectionStringBuilder configurationDatabase, SqlConnectionStringBuilder administrationContentDatabase, IdentityType identityType, String farmUser, SecureString farmPassword, SecureString masterPassphrase)
at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.CreateOrConnectConfigDb()
at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.Run()
at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()
--------------------------------------------------------------------------------------------------
Solution: Delete Registry Key (i was skeptical to directly edit the registry, but it worked for me)


HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Secure\FarmAdmin
--------------------------------------------------------------------------------------------------


3) Failed to create sample data.


An exception of type Microsoft.Office.Server.UserProfiles.UserProfileException was thrown. Additional exception information: Unrecognized attribute 'allowInsecureTransport'. Note that attribute names are case-sensitive. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile\client.config line 56)

Microsoft.Office.Server.UserProfiles.UserProfileException: Unrecognized attribute 'allowInsecureTransport'. Note that attribute names are case-sensitive. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile\client.config line 56) ---> System.Configuration.ConfigurationErrorsException: Unrecognized attribute 'allowInsecureTransport'. Note that attribute names are case-sensitive. (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebClients\Profile\client.config line 56)

at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)

at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)

at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

at System.Configuration.ConfigurationSectionCollection.Get(String name)
at System.ServiceModel.Configuration.ServiceModelSectionGroup.get_Client()
at Microsoft.Office.Server.UserProfiles.MossClientBase`1.GetServiceBinding(String endpointConfigurationName)
at Microsoft.Office.Server.UserProfiles.MossClientBase`1.GetChannelFactory(String endpointConfigurationName)
at Microsoft.Office.Server.UserProfiles.MossClientBase`1.get_Channel()
at Microsoft.Office.Server.UserProfiles.MossClientBase`1.ExecuteOnChannel(String operationName, CodeBlock codeBlock)
at Microsoft.Office.Server.UserProfiles.ProfilePropertyServiceClient.ExecuteOnChannel(String operationName, CodeBlock codeBlock)

--- End of inner exception stack trace ---

at Microsoft.Office.Server.UserProfiles.ProfilePropertyServiceClient.ExecuteOnChannel(String operationName, CodeBlock codeBlock)
at Microsoft.Office.Server.UserProfiles.ProfilePropertyServiceClient.GetProfileProperties()
at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.RefreshProperties(Guid applicationID)
at Microsoft.Office.Server.Utilities.SPAsyncCache`2.GetValueNow(K key)
at Microsoft.Office.Server.Utilities.SPAsyncCache`2.GetValue(K key, Boolean asynchronous)
at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.InitializePropertyCache()
at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.Provision()
at Microsoft.SharePoint.PostSetupConfiguration.EvalModeProvisionTask.ProvisionServiceApplicationsAndProxies()
at Microsoft.SharePoint.PostSetupConfiguration.EvalModeProvisionTask.Run()
at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()

--------------------------------------------------------------------------------------------------

Solution: You need to install hotfix KB976462 (FIX FOR: WCF: Sharepoint Shared Services Roll-up).
You need to restart your machine after installing the hot fix.
--------------------------------------------------------------------------------------------------

Updates: Upating the article almost after 2.5 years since I originally posted it
4)
Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at Microsoft.SharePoint.Administration.SPFarm.CurrentUserIsAdministrator(Boolean allowContentApplicationAccess)
   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.Microsoft.SharePoint.Administration.ISPPersistedStoreProvider.DoesCurrentUserHaveWritePermission(SPPersistedObject persistedObject)
   at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()
   at Microsoft.SharePoint.Administration.SPFarm.Update()
   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.RegisterDefaultDatabaseServices(SqlConnectionStringBuilder connectionString)
   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.Provision(SqlConnectionStringBuilder connectionString)
   at Microsoft.SharePoint.Administration.SPFarm.Create(SqlConnectionStringBuilder configurationDatabase, SqlConnectionStringBuilder administrationContentDatabase, IdentityType identityType, String farmUser, SecureString farmPassword, SecureString masterPassphrase)
   at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.CreateOrConnectConfigDb()
   at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.Run()
   at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()
--------------------------------------------------------------------------------------------------
Solution: You need to install Windows6.1-KB974405-x64 (Windows Identity Foundation)
--------------------------------------------------------------------------------------------------

Sunday, January 03, 2010

SharePoint 2010 Developer Platform

SharePoint v/s ASP.Net: When does it make sense to build an application on SharePoint instead of on raw ASP.NET? What are the application types for which SharePoint is best suited? And what applications types are SharePoint misfits and should be built using ASP.Net or other technologies?



The “SharePoint 2010: Developer Platform” White Paper tries to answer the above questions.
http://www.microsoft.com/downloads/details.aspx?FamilyID=5184cb27-98d9-4cc0-bb0b-4b24d5b62db6&displaylang=en

Recommended reading material.