none
Error “Evaluating the function '…SharePoint.PortalPath.get' timed out and needed to be aborted in an unsafe way” RRS feed

  • Question

  • We are having an issue with our software (C# .NET Framework 4) when requesting document information from SharePoint 2010 server.
    We are requesting the information this way:

            public string GetListItemPropertiesByUrl(string url)
            {
                try
                {
                    string redUrl = string.Empty;
                    using (ClientContext clientContext = new ClientContext(PortalPath))
                    {
                        clientContext.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["SPUser"], System.Configuration.ConfigurationManager.AppSettings["SPUserPass"]);
                        redUrl = GetRedirectUrlFromDocIdUrl(url).Replace("http://portal.grolman.de", "").Replace("http://testportal.grolman.de", "");
                    }
                    return redUrl;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

    This works fine if we have only some documents to request. If we request many documents, it works only 3-4 times, then the application hangs up with this error:

    > Evaluating the function '...SharePoint.PortalPath.get' timed out and
    > needed to be aborted in an unsafe way. This may have corrupted the
    > target process.

    > If the problem happens regularly, consider disabling the
    > Tools->Options setting "Debugging->General->Enable property
    > evalualtion and other implicit function calls" or change the code to
    > disable evaluation of this method. See help for information on doing
    > this.

    It happens at this line of code

    using (ClientContext clientContext = new ClientContext(PortalPath))


    I already tried the advise in the error message and searched a lot on the internet, but all solutions did not solve this issue. This error still happens.
    I.e. we enabled the option "User Managed Compatibility Mode" and "Use the legacy C# and VB expression evaluators".
    We are using Visual Studio 2017 15.9.11.
    I already saw this post on Stackoverflow, but this did not help either.

    https://stackoverflow.com/questions/48891185/evaluating-the-function-function-timed-out

    Are there any hints or tipps, how we can try to solve this issue?

    Tuesday, April 9, 2019 12:26 PM

All replies

  • If that call to PortalPath.get() will cause timeout, try cache it in your class as static variable (I assume that the path will not change often, but if that will change, feel free to add code to trigger reload by setting the _cachedPortalPath to null.

    private static _cachedPortalPath = null;
    public static CachedPortalPath
    {
    	get
    	{
    		if (_cachedPortalPath == null)
    		{
    			_cachedPortalPath = PortalPath;
    		}
    		return _cachedPortalPath;
    	}
    }

    Then change your call to ClientContext like this:

    using (ClientContext clientContext = new ClientContext(CachedPortalPath))

    Of course, this seems to be a sign that the SharePoint server is configured with thread count less then enough to serve your requests. The real fix is either 1) increase the thread count in IIS Manager (possibly need to adjust the memory limit as well); or 2) Put every code your application need to access the SharePoint site in singleton class, using shared ClientContext, and protect every use of ClientContext with lock(ClientContext) block to serialize access. In this way there will be at most 1 thread using ClientContext to access the SharePoint site. However, also be sure to add logic to recreate ClientContext on exception if needed, preferably with retry limit.


    Wednesday, April 10, 2019 2:24 AM
    Answerer