错误“评估函数'... SharePoint.PortalPath.get'超时并需要以不安全的方式中止” [英] Error “Evaluating the function '…SharePoint.PortalPath.get' timed out and needed to be aborted in an unsafe way”

查看:144
本文介绍了错误“评估函数'... SharePoint.PortalPath.get'超时并需要以不安全的方式中止”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


SharePoint 2010 服务器请求文档信息时,我们的软件( C#.NET Framework 4 )出现问题。 />
我们以这种方式请求信息:

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;
            }
        }

如果我们只有一些文件可以请求,这样可以正常工作。如果我们请求许多文档,它只能工作3-4次,那么应用程序会挂起此错误:



>评估函数'... SharePoint.PortalPath.get'超时和

>需要以不安全的方式中止。这可能已损坏

>目标流程。



>如果问题经常发生,请考虑禁用

>工具 - >选项设置"调试 - >常规 - >启用属性

> evalualtion和其他隐式函数调用"或将代码更改为

>禁用此方法的评估。有关执行操作的信息,请参阅帮助

>这个。



在这行代码中发生这种情况。


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.e.我们启用了选项"用户管理兼容模式"和"使用旧版C#和VB表达式评估程序"。"
我们正在使用 Visual Studio 2017 15.9.11

我已经在Stackoverflow上看过这篇文章了,但这也没有帮助。



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



是否有任何提示或提示,我们如何尝试解决此问题?


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?

推荐答案

如果对PortalPath.get()的调用会导致超时,请尝试将其作为静态变量缓存在您的类中(我假设路径不会经常更改,但如果更改,请随意添加代码通过将_cachedPortalPath设置为null来触发重新加载。

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;
	}
}

然后将您的调用更改为ClientContext,如下所示:

Then change your call to ClientContext like this:

using (ClientContext clientContext = new ClientContext(CachedPortalPath))




当然,这似乎表明SharePoint服务器配置的线程数少于足够满足您的要求。真正的修复是1)增加IIS管理器中的线程数(可能还需要调整内存限制);或
2)使用共享ClientContext将您的应用程序所需的每个代码放入单一类中访问SharePoint站点,并使用lock(ClientContext)块保护ClientContext
的每次使用序列化访问。这样,使用ClientContext最多可以有一个线程来访问SharePoint站点。但是,如果需要,还要确保添加逻辑以在异常时重新创建ClientContext,最好是带有重试限制的


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.


这篇关于错误“评估函数'... SharePoint.PortalPath.get'超时并需要以不安全的方式中止”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆