Friday 28 February 2014

Operation is not valid due to the current state of the object.

Error :Exception Source : Microsoft.SharePoint
Stack Trace : at Microsoft.SharePoint.SPUserToken.GetClaimsUserLoginName()
   at Microsoft.SharePoint.SPSite.CopyUserToken(SPUserToken userToken)
   at Microsoft.SharePoint.SPSite.SPSiteConstructor(SPFarm farm, Guid applicationId, Guid contentDatabaseId, Guid siteId, Guid siteSubscriptionId, SPUrlZone zone, Uri requestUri, String serverRelativeUrl, Boolean hostHeaderIsSiteName, SPUserToken userToken, Boolean appWebRequest, String appHostHeaderRedirectDomain, String appSiteDomainPrefix, String subscriptionName, String appSiteDomainId, Uri primaryUri)
   at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, Boolean swapSchemeForPathBasedSites, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
   at Microsoft.SharePoint.SPSite..ctor(String requestUrl, SPUserToken userToken)
Exception Message: Operation is not valid due to the current state of the object.
SharePoint Log: [Forced due to logging gap, cached @ Original Level: Verbose] SQL connection time: 0.2037 for Data Source=;Integrated Security=True;Enlist=False;Pooling=True;Min Pool Size=0;Max Pool Size=100;Connect Timeout=15;Application Name=SharePoint[w3wp][2]   0x1358  SharePoint Foundation                 Authentication Authorization    ajmmt   High       [Forced due to logging gap, Original Level: VerboseEx] SPRequestParameters: AppPrincipal={0}, UserName={1}, UserKye={2}, RoleCount={3}, Roles={4} w3wp.exe SharePoint Foundation        ak8dj     High       UserAgent not available, file operations may not be optimized.    at Microsoft.SharePoint.SPFileStreamManager.CreateCobaltStreamContainer(SPFileStreamStore spfs, ILockBytes ilb, Boolean copyOnFirstWrite, Boolean disposeIlb)     at Microsoft.SharePoint.SPFileStreamManager.SetInputLockBytes(SPFileInfo& fileInfo, SqlSession session, PrefetchResult prefetchResult)     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPCoordinatedStreamBufferFactory.CreateFromDocumentRowset(Guid databaseId, SqlSession session, SPFileStreamManager spfstm, Object[] metadataRow, SPRowset contentRowset, SPDocumentBindRequest& dbreq, SPDocumentBindResults& dbres)     at Microsoft.SharePoint.SPSqlClient.GetDocumentContentRow(Int32 rowOrd, Object ospFileStmMgr, SPDocumentBindRequest& dbreq, SPDocumentBindResults& dbres...  

One of the major issue in designer workflow 2013 was that we were using User Token to kick off the workflow because it can not be triggered directly using System account due to security reasons. It took around 1 month to resolve it. The user which we were using to Kickoff the workflow was getting expired if the Site was not getting used for more than 24 hours. The reason for 24 hour is that the SharePoint stores the User Token in cache from the logging time. Hence if the User does not login manually or via code its gives a error of Operation is not valid due to the current state of the object. Once the User login in the System manually the problem gets rectified. If you go to  Site Settings-> Site Permissions-> Check Permission it gives a error same error of Operation is not valid due to the current state of the object.

Solution: To kickoff the workflow Use Following piece of code:SPContext.Current.Site.SystemAccount.UserToken

using (SPSite oSPSite = new SPSite(SPContext.Current.Web.Url, SPContext.Current.Site.SystemAccount.UserToken))
            {
                using (SPWeb oSPWeb = oSPSite.OpenWeb())  //Subsite URL
                {
                    oSPWeb.AllowUnsafeUpdates = true;
                               foreach (var workflowSubscription in subscriptions)
                            {
                                if (workflowSubscription.Name == "Workflow Name")
                                {
                                    //initiation parameters
                                    var inputParameters = new Dictionary<string, object>();
                                    inputParameters.Add("Comments", "TEST");
                                    inputParameters.Add("ItemId", item.ID);
                                    inputParameters.Add("WorkflowStart", "StartWorkflow");
                                    workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, item.ID, inputParameters);
                                    break;
                                }
                            }
  oSPWeb.AllowUnsafeUpdates = false;
This piece of code will use app pool account token which never expires and hence the problem solved. Regarding the Security if I am using User token of my app pool account it gives me access to content DB and Workflow manager.
 

Thursday 27 February 2014

SharePoint 2013 designer workflow error 400 or Email activity error

RequestorId: 6b3b2ca8-21cd-122b-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.ApplicationException: HTTP 400 {"Transfer-Encoding":["chunked"],"X-SharePointHealthScore":["0"],"SPClientServiceRequestDuration":["79"],"SPRequestGuid":["6b3b2ca8-21cd-122b-8415-1dbd28108890"],"request-id":["6b3b2ca8-21cd-122b-8415-1dbd28108890"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"MicrosoftSharePointTeamServices":["15.0.0.4551"],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1; RequireReadOnly"],"Cache-Control":["max-age=0, private"],"Date":["Thu, 27 Feb 2014 08:20:02 GMT"],"Server":["Microsoft-IIS\/8.0"],"X-AspNet-Version"

This error mainly comes when the email ID is not registered to any of the User in SharePoint. You can definitely send email to any of the Email ID of the world. But that Email ID need to be registered in any of the Email ID of the User.
Email ID of a user can easily be changes by using the power shell  to update the user detail information in User Information list of the site. Or it can be changed by Updating the User profile information from the Central Admin.
Power shell command to update the User Email:
Set-SPUser -Identity 'yourmachine\Roberto' -DisplayName 'Roberto' -Email 'robertosljunior@yahoo.com.br' -Web http://yourmachine

Wednesday 26 February 2014

SharePoint 2013 Designer workflow 500 Error in Send mail Activity

Error: RequestorId: 1ca8de59-3d62-782a-0000-000000000000. Details: RequestorId: 1ca8de59-3d62-782a-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.ApplicationException: HTTP 500 {"Transfer-Encoding":["chunked"],"X-SharePointHealthScore":["0"],"SPClientServiceRequestDuration":["1073"],"SPRequestGuid":["1ca8de59-3d62-782a-b382-5cad0b97cc22"],"request-id":["1ca8de59-3d62-782a-b382-5cad0b97cc22"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"MicrosoftSharePointTeamServices":["15.0.0.4420"],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1; RequireReadOnly"],"Cache-Control":["max-age=0, private"],"Date":["Thu, 27 Feb 2014 06:03:49 GMT"],"Server":["Microsoft-IIS\/8.0"],"X-AspNet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"]} at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Error Code: 500


This error because the SMTP server is off. This kind of problem normally occurs when we restart the IIS.

Solution: Start the SMTP server and to rectify the problem in the Future make sure the Simple Mail Transfer Protocol(SMTP) service is set to start automatic. For doing that go to Services.msc and find out the SMTP service and make it automatic.

Workflow not getting kicked off with Current User

Errro: RequestorId: 75337308-d065-9a23-8e25-34499695740b. Details: System.ApplicationException: HTTP 401 {"error_description":"The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs."} {"x-ms-diagnostics":["3001000;reason=\"There has been an error authenticating the request.\";category=\"invalid_client\""],"SPRequestGuid":["a37979da-2b2d-4fb7-aec5-0fc79065450d"],"request-id":["a37979da-2b2d-4fb7-aec5-0fc79065450d"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"SPRequestDuration":["35"],"SPIisLatency":["0"],"Server":["Microsoft-IIS\/8.0"],"WWW-Authenticate":["Bearer realm=\"3fe89713-c11e-40a7-a6c0-0e1b0ea08e5d\",client_id=\"00000003-0000-0ff1-ce00-000000000000\",trusted_issuers=\"00000005-0000-0000-c000-000000000000@*,00000003-0000-0ff1-ce00-000000000000@3fe89713-c11e-40a7-a6c0-0e1b0ea08e5d\"","NTLM","Basic realm=\"qa2-sanofi-sharepoint.adjilityhealth.com\""],"X-Powered-By":["ASP.NET"],"MicrosoftSharePointTeamServices":["15.0.0.4551"],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1; RequireReadOnly"],"Date":["Wed, 26 Feb 2014 07:36:43 GMT"]} at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

This error occurs because User profile of current user is not been created. In SharePoint 2013 designer workflow it is a must to have a User Profile from which you are kicking off the workflow.
It has been clearly mentioned in a TechNet article by Microsoft.
http://technet.microsoft.com/en-us/library/jj658588.aspx
Solution: Create User Profile for the Current User problem will be resolved.

Tuesday 25 February 2014

Workflow devloped not getting open in SharePoint Designer 2013


Workflow devloped not getting open in Designer 2013.


Error:
1) Failed to load this workflow. To correct this problem restart the designer.
2) Windows workflow foundation, part of .Net Framwork 3.0, must be installed to use this feature.

This error comes beacuse of the designer you are using and the designer where this workflow is devloped is of different version. If after the installation of the latest deigner updates the problem does not get resolved. The reason behind that is that in website keeps DLL in the cache folder which does not get refreshed when the new updates for designer is installed.
 Solution: Install the latest updates for designer SharePoint 2013 and clear the website cache.It will work fine.
To clear the designer workflow cache go to the folder:

1. Go to %System Drive%\Documents and Settings\%user%\Local Settings\Application Data\Microsoft\WebSiteCache
2. Go to a directory which is for website you were connecting to and delete all the files.
3. Restart SPD.

SharePoint 2013 Workflow mail not getting sent


If SharePoint 2013 March and December cumulative updates are not installed. You may face a error of mail not getting sent from Designer. The root cause of it is that SharePoint designer workflow takes from email ID from its WFResourceManagementDB which is Workflow@noreplay. So when the request goes to SMTP to send email from this email address SMTP sends it to BAD Email. To rectify this Update the WFResourceManagementDB with the Email ID from which the mails getting sent. 



UPDATE [WFResourceManagementDB].[Activities]
SET [Xaml].modify('declare namespace ns="http://schemas.microsoft.com/netfx/2009/xaml/activities";
                    declare namespace p="http://schemas.microsoft.com/workflow/2012/07/xaml/activities";
                    declare namespace scg="clr-namespace:System.Collections.Generic;assembly=mscorlib";
                    declare namespace x="http://schemas.microsoft.com/winfx/2006/xaml";
                    replace value of (/ns:Activity/ns:Sequence/p:BuildDynamicValue/scg:Dictionary/ns:InArgument[@x:Key="properties/From"]/text())[1] with "example@mail.com"')
WHERE Name = 'EMail'”

Replace  example@mail.com with the email from will be sent.

If after that also mails not getting sent please make sure that mail are getting sent via SharePoint. You can easily varify that by sending an Email alert from a list.



Note: Make Sure the password for the mail you are using must be set to Never expired. Because mails will stuck to Queue if the password expire. 

Bug Solved: With SharePoint 2013 March and Dec Cumulitive updates.