Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 681279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:27:58+00:00 2026-05-14T01:27:58+00:00

I am trying to register a WebDeleting event receiver within SharePoint. This works fine

  • 0

I am trying to register a WebDeleting event receiver within SharePoint. This works fine in my development environment, but not in several staging environments. The error I get back is “Value does not fall within the expected range.”. Here is the code I use:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite elevatedSite = new SPSite(web.Site.ID))
    {
        using (SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID))
        {
            try
            {
                elevatedWeb.AllowUnsafeUpdates = true;
                SPEventReceiverDefinition eventReceiver = elevatedWeb.EventReceivers.Add(new Guid(MyEventReciverId));
                eventReceiver.Type = SPEventReceiverType.WebDeleting;
                Type eventReceiverType = typeof(MyEventHandler);
                eventReceiver.Assembly = eventReceiverType.Assembly.FullName;
                eventReceiver.Class = eventReceiverType.FullName;
                eventReceiver.Update();
                elevatedWeb.AllowUnsafeUpdates = false;
            }
            catch (Exception ex)
            {
                // Do stuff...
            }
        }
    }
});

I realize that I can do this through a feature element file (I am trying that approach now), but would prefer to use the above approach.

The errors I consistently get in the ULS logs are:

03/11/2010 17:16:57.34  w3wp.exe (0x09FC)                           0x0A88  Windows SharePoint Services     Database                        6f8g    Unexpected  Unexpected query execution failure, error code 3621. Additional error information from SQL Server is included below. "The statement has been terminated." Query text (if available): "{?=call proc_InsertEventReceiver(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"  
03/11/2010 17:16:57.34  w3wp.exe (0x09FC)                           0x0A88  Windows SharePoint Services     General                         8e2s    Medium      Unknown SPRequest error occurred. More information: 0x80070057   

Any ideas?


UPDATE – Some interesting things I have learned…

I modified my code to do the following:

  • I call EventReceivers.Add() without the GUID since most examples I see do not do that
  • Gave the event receiver a Name and Sequence number since most examples I see do that

I deployed this change along with some extra trace statements that go to the ULS logs and after doing enough iisresets and clearing the GAC of my assembly, I started to see my new trace statements in the ULS logs and I no longer got the error!

So, I started to go back towards my original code to see what change exactly helped. I finally ended up with the original version in source control and it still worked :-S.

So the answer is clearly that it is some caching issue. However, when I was originally trying to get it to work I tried IISRESETs, restarting some SharePoint services OWSTimer (this, I believe runs the event hander, but probably isn’t involved in the event registration where I am getting the error), and even a reboot to make sure no assembly caching was going on – and that did not help before.

The only thing I have to go on is maybe following steps such as:

  1. Clear the GAC of the assembly that contains the registration code and event hander class.
  2. Do an IISRESET.
  3. Uninstall the WSP.
  4. Do an IISRESET.
  5. Install the WSP.
  6. Do an IISRESET.

To get it working I never did a reboot or restarted SharePoint services, but I had done those prior to getting it working (before changing my code).

I suppose I could dig more with Reflector to see what I can find, but I believe you get to a dead end (unmanaged code) pretty quick. I wonder what could be holding on to the old DLL? I can’t imagine that SQL Server would be in some way. Even so, a reboot would have fixed that (the entire farm, including SQL Server are on the same machine in this environment).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:27:58+00:00Added an answer on May 14, 2026 at 1:27 am

    So, it appears that the whole problem was creating the event receiver by providing the GUID.

    EventReceiverDefinition eventReceiver = elevatedWeb.EventReceivers.Add(new Guid(MyEventReciverId));
    

    Now I am doing:

    EventReceiverDefinition eventReceiver = elevatedWeb.EventReceivers.Add();
    

    Unfortunately this means when I want to find out if the event is already registered, I must do something like the code below instead of a single one liner.

    // Had to use the below instead of: web.EventReceivers[new Guid(MyEventReceiverId)]
    private SPEventReceiverDefinition GetWebDeletingEventReceiver(SPWeb web)
    {
        Type eventReceiverType = typeof(MyEventHandler);
        string eventReceiverAssembly = eventReceiverType.Assembly.FullName;
        string eventReceiverClass = eventReceiverType.FullName;
    
        SPEventReceiverDefinition eventReceiver = null;
    
        foreach (SPEventReceiverDefinition eventReceiverIter in web.EventReceivers)
        {
            if (eventReceiverIter.Type == SPEventReceiverType.WebDeleting)
            {
                if (eventReceiverIter.Assembly == eventReceiverAssembly && eventReceiverIter.Class == eventReceiverClass)
                {
                    eventReceiver = eventReceiverIter;
                    break;
                }
            }
        }
    
        return eventReceiver;
    }
    

    It’s still not clear why things seemed to linger and require some cleanup (iisreset, reboots, etc.) so if anyone else has this problem keep that in mind.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to register the NSMouseMoved event globally using this line of code: [NSEvent
I am trying to register a c++ function in Lua. But getting this error:
I'm trying to register a simple script - ClientScript.RegisterClientScriptBlock(typeof(Page), myscript, <script>testfun();</script>); This line works
I am trying to register a receiver for the removal of the sdcard, but
I'm trying to register this simple script, but i can't get this to show
I'm trying to register a broadcast receiver to handle the VOLUME_CHANGED_ACTION event, only for
I'm trying to register the DialogBoxShowing event of the UIControlledApplication. But I cannot use
I have a problem trying to register my own Event/Listener to the event dispatcher.
Trying to write out syslog entries containing strings but they don't register. // person.name
I'm trying to register a hot key, I'm translating this C++ code into C#:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.