SharePoint 2010 事件处理程序
我在尝试调试 Sharepoint 列表的事件接收器时遇到了一场噩梦。 这是我正在做的代码:
//Add an event receiver to the list
list.EventReceivers.Add(SPEventReceiverType.ItemAdded, "DatasEvent, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 6f4db1e1fedbed57", "DatasEvent.DatasEventReceiver");
public override void ItemAdded(SPItemEventProperties properties)
{
try
{
int itemIdSql;
SPListItem item = properties.ListItem;
...
}
catch (SqlException ex)
{
Debug.WriteLine(ex.Message);
}
}
如果我在事件接收器中放置断点,它就不会停止。
I am having a nightmare trying to debug the event receiver of a Sharepoint list.
This is the code of what I am doing:
//Add an event receiver to the list
list.EventReceivers.Add(SPEventReceiverType.ItemAdded, "DatasEvent, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 6f4db1e1fedbed57", "DatasEvent.DatasEventReceiver");
public override void ItemAdded(SPItemEventProperties properties)
{
try
{
int itemIdSql;
SPListItem item = properties.ListItem;
...
}
catch (SqlException ex)
{
Debug.WriteLine(ex.Message);
}
}
If I place a breakpoint in the event receiver it will not stop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
进入你的视觉工作室调试->附上流程->附上列表中所有可用的 w3wp.exe。现在尝试在网络浏览器中激活该功能。您的断点应该被加载并命中。
go to your visual studio Debug -> Attach process -> attach all available w3wp.exe in the list. Now try activating the feature in the web browser. Your breakpoint should be loaded and hit.
我个人更喜欢将 System.diagnostic.debug.WriteLn() 消息添加到事件接收器代码中,并使用服务器上的 DebugView 查看它们。每次都附加到工作进程很烦人。
I personally prefer adding System.diagnostic.debug.WriteLn() messages to the event receiver code and view them using DebugView on the server. Attaching to worker processes every time is annoying.
首先确保最新的程序集版本到达 GAC。最简单的方法是使用项目上下文菜单中的“部署”选项或直接按 F5。
然后请让我们知道这段代码分配在哪里
//将事件接收器添加到列表中
list.EventReceivers.Add(SPEventReceiverType.ItemAdded, "DatasEvent, 版本 = 1.0.0.0, Culture = 中性, PublicKeyToken = 6f4db1e1fedbed57", "DatasEvent.DatasEventReceiver");
如果它被放置在功能接收器中,请确保在尝试附加到与目标 Web 应用程序对应的应用程序池对应的 w3wp.exe 之前已激活它。
First of all ensure that the latest assembly version gets to the GAC. The easiest way for it is to use the "Deploy" option from the context menu of the project or simply hit F5.
Then please let us know where this code is allocated
//Add an event receiver to the list
list.EventReceivers.Add(SPEventReceiverType.ItemAdded, "DatasEvent, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 6f4db1e1fedbed57", "DatasEvent.DatasEventReceiver");
if it is placed in a feature receiver then make sure that it is activated before you try to attach to w3wp.exe that corresponds to the app pool your target web application corresponds to.
我会尝试:
仅在开发环境中,否则它将尝试对每个请求进行调试。
我会把它放在添加事件接收器之前。
I would try:
Only in a development environment, otherwise it will try to debug for every request.
I would put it before adding the event receiver.
ItemAdded 处理添加项目后发生的异步事件。执行是通过计时器作业执行的(而不是在当前工作进程 w3wp 中)。所以你应该附加到 OWSTIMER 进程来调试它。
ItemAdded handles the asynchronous event that occurs after an item is added. The execution is carried out via timer job (and not in current worker process w3wp). So you should attach to OWSTIMER process to debug it.
您应该在两个 web.config 文件中启用共享点调试。
您应该使用 Debugger.Launch() 来停止运行时。
例如,部署和激活事件触发后(在EventReceiver的代码中有一个Debugger.Launch()命令)并且VS要求您调试代码。
不需要使用“附加到进程”,但这是另一种可能的调试方式。
此链接对我帮助很大
You should enable debugging of sharepoint in two web.config files.
You should use Debugger.Launch() to stop the runtime.
E.g. After deployment and Activation event fires (in EventReceiver's code there is a Debugger.Launch() command) and VS asks you to debug the code.
There is no need to use "attach to process", but it's another possible way to debug.
this links helped me a lot