“CallList:无法导入此 Web 部件”安装 SharePoint Web 部件时
我创建了一个 Web 部件。当我将 WebPart 添加到页面时,出现以下错误。
如果我删除 WebPart 构造函数中的内容,它将添加到页面中。然后,如果我在页面上部署代码并将 WebPart 全部准备好,WebPart 将正确显示。我无法将其添加到之前收到错误的其他页面。
所以我推测构造函数有问题。破坏它的行是
var site = new SPSite("http://website/site");
This 已通过注释代码找到。安装WebPart时不能创建SPSite吗?
I have created a WebPart. When I add the WebPart to a page I get the error below.
If I delete what is in my constructor for my WebPart it will then add to the page. Then if I deploy my code with the WebPart all ready on a page the WebPart will display correctly. I can't add it to other pages I get the error before.
So I presume that there is a problem with the constructor. The line that is breaking it is
var site = new SPSite("http://website/site");
This has been found by commenting code out. Can you not create an SPSite when installing a WebPart?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否将构造函数代码封装在 try/catch 块中?它可能会由于某种原因引发异常。
否则,请尝试将构造函数代码移至 OnInit 以查看是否会产生影响。
Do you have your constructor code wrapped in a try/catch block? It may be throwing an exception for some reason.
Otherwise, try moving your constructor code to OnInit to see if that makes a difference.
是的,我们可以使用 spsite 对象。
您可以更改您的代码吗,例如
让我知道它是否有效。
yes we can use spsite object.
Can you change your code like
let me know if it works.