Tuesday, July 21, 2009

SPFeatureReceiver Guidance

CAUTION! This is starting to become a PET PEEVE of mine!

Features can be managed from stsadm.exe, Site collection features web ui, Site features web ui, console apps, powershell scripts, feature staplers and the list goes on and on.
To make sure your feature receivers work no matter where the feature is being activated from do yourself a favour and keep on reading.


SPFeatureReceiverProperties.Feature.Parent can be many things depending on the scope of your feature and where it's being activated from so please make sure you check before using it. So many times have I found great features in CodePlex that I would like to staple to site definitions or deploy/activate using powershell or other mediums and find I get this.

Value does not fall within the expected range. at ###.###.FeatureReceiver.FeatureActivated(SPFeatureReceiverProperties properties)

For Site Scoped Features

public override void FeatureActivated(SPFeatureReceiverProperties properties) {
SPSite site = properties.Feature.Parent as SPSite;
if (site == null)
{
SPWeb web = properties.Feature.Parent as SPWeb;
if (web != null)
site = web.Site;
}
if(site == null)
return new ArgumentNullException("Can't find a refrence to a site!");
//Or check for parent being a Web app or log it

// Do Stuff
}

For Web Scoped Features
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
SPWeb web = properties.Feature.Parent as SPWeb;
if (web == null)
{
SPSite site = properties.Feature.Parent as SPSite;
if (site != null)
web = site.OpenWeb();
}
if(web == null)
return new ArgumentNullException("Can't find a reference to a web!");
//Or check for parent being a Web app or log it

// Do Stuff
}


You get the idea! (I'll format the code as soon as I'm back on my normal PC)

Thursday, March 26, 2009

HRESULT: 0x80040E2F the Why and How

Just a quick update an why I was getting this error and how we fixed it. By WE I mean my bestest buddy ol' pal Angela Knight. Will post a link to her blog as soon as she starts one!

What it was is a custom Contentype that was based off the OOB Event ContentType with a bunch of custom SiteColumns where the offending SiteColumn was of type lookup. Problem was the custom ContenType was deployed to the SiteCollection level however the look up list was only provisioned at the web level.

So how did Ange fix it?
She removed the offending SiteColumn, Created a Web level ContetType thats based off our custom ContentType that's provisioned after the look up list is. Thus we no longer get the error. See the juicy bits below.

..oops.. out of time will update tomorrow <<such a tease>>

Error Message of the day

List does not exist

The page you selected contains a list that does not exist.  It may have been deleted by another user.

Friday, February 27, 2009

Tuesday, February 17, 2009

C# PriorityQueue<T> Implementation

Before I get any more abusive comments. This post is targeted at the 2.0 version of the Framework.

Guess I could of just used a SortedList<T1, T2> implementation in System.Collections.Generic, but I want a PriorityQueue<T>. So here goes.

public class PriorityQueue<T> : SortedList<T, T>
{
public PriorityQueue()
: base()
{
}

public PriorityQueue(IComparer<T> comparer)
: base(comparer)
{
}

//
// Summary:
// Returns the object at the beginning of the System.Collections.Generic.Queue<T>
// without removing it.
//
// Returns:
// The object at the beginning of the System.Collections.Generic.Queue<T>.
//
// Exceptions:
// System.InvalidOperationException:
// The System.Collections.Generic.Queue<T> is empty.
public T Peek()
{
return this.Last().Key;
}

//
// Summary:
// Removes and returns the object at the beginning of the System.Collections.Generic.Queue<T>.
//
// Returns:
// The object that is removed from the beginning of the System.Collections.Generic.Queue<T>.
//
// Exceptions:
// System.InvalidOperationException:
// The System.Collections.Generic.Queue<T> is empty.
public T Dequeue()
{
T item = this.Last().Key;
this.RemoveAt(this.Count - 1);
return item;
}

//
// Summary:
// Adds an object to the end of the System.Collections.Generic.Queue<T>.
//
// Parameters:
// item:
// The object to add to the System.Collections.Generic.Queue<T>. The value can
// be null for reference types.
public void Enqueue(T item)
{
this.Add(item, item);
}
}

Monday, January 26, 2009

SharePoint and me

This about sums it up for me,

Peter Jone's "What Is Wrong With SharePoint"

Thank you Peter for an excellent analogy.

Thursday, January 15, 2009

HRESULT: 0x80040E2F Why Me?

How did it happen?

I tried to edit an existing SPListItem through the Web UI.

image

What now?
I reach for my search bar and find blah blah Violation of PRIMARY KEY constraint blah Backup blah Restore.

Shouldn't the API gracefully handle such an error?
Time to dig through the logs.
Event logs say nada but I found the following in SharePoint logs.

01/13/2009 14:09:52.60     w3wp.exe (0x1670)                           0x1458    Windows SharePoint Services       General                           0    Verbose     Releasing SPRequest with allocation Id {87F373C4-DE0E-4294-8012-85AF991E4A7F}     


01/13/2009 14:09:52.65     w3wp.exe (0x1670)                           0x1458    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): "BEGIN TRAN;DECLARE @@iRet INT,@DN nvarchar(256),@LN nvarchar(128),@@S uniqueidentifier,@@Level tinyint,@@DocUIVersion int,@ExtraItemSize bigint;SET @@iRet = 0;SET @@S='73897537-074B-404A-B7FF-814BEF2D21C8';SET @@Level=1;SET @@DocUIVersion = 512;SELECT @ExtraItemSize = 0  EXEC @@iRet = proc_UpdateListItem @SiteId='73897537-074B-404A-B7FF-814BEF2D21C8',@WebId='71DC2E37-8A9D-4FDC-A504-6AA845885ABC', @ListID = '2446D5BB-34F8-4366-8839-B13CB55D24D0', @ItemID=2, @RowOrdinal = 0,@ReturnRowset = 1,@ItemDirName=@DN OUTPUT,@ItemLeafName=@LN OUTPUT,@UserId=2,@TimeNow = '20090113 01:09:52',@MajorVersionsLimit=0,@MajorMinor...     


tabase                          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): "BEGIN TRAN;DECLARE @@iRet INT,@DN nvarchar(256),@LN nvarchar(128),@@S uniqueidentifier,@@Level tinyint,@@DocUIVersion int,@ExtraItemSize bigint;SET @@iRet = 0;SET @@S='73897537-074B-404A-B7FF-814BEF2D21C8';SET @@Level=1;SET @@DocUIVersion = 512;SELECT @ExtraItemSize = 0  EXEC @@iRet = proc_UpdateListItem @SiteId='73897537-074B-404A-B7FF-814BEF2D21C8',@WebId='71DC2E37-8A9D-4FDC-A504-6AA845885ABC', @ListID = '2446D5BB-34F8-4366-8839-B13CB55D24D0', @ItemID=2, @RowOrdinal = 0,@ReturnRowset = 1,@ItemDirName=@DN OUTPUT,@ItemLeafName=@LN OUTPUT,@UserId=2,@TimeNow = '20090113 01:09:52',@MajorVersionsLimit=0,@MajorMinor...     


01/13/2009 14:09:52.65*    w3wp.exe (0x1670)                           0x1458    Windows SharePoint Services       Database                          6f8g    Unexpected    ...VersionsLimit=0, @NewUIVersion = @@DocUIVersion OUTPUT,@Level=@@Level OUTPUT,@IsDocLib=0, @tp_Version = 4, @tp_ContentTypeId = ?, @nvarchar1 = ?, @uniqueidentifier1 = ?, @ntext2 = ?, @nvarchar3 = ?, @nvarchar4 = ?, @nvarchar5 = ?, @datetime1 = ?, @datetime2 = ?, @bit1 = ?, @nvarchar6 = ?, @ntext3 = ?, @nvarchar7 = ?, @nvarchar9 = ?, @bit3 = ?, @nvarchar10 = ?, @ntext4 = ?, @bit4 = ?, @nvarchar11 = ?, @int2 = ?, @int3 = ?, @ntext5 = ?, @int4 = ?, @ntext7 = ?, @nvarchar14 = ?, @ntext8 = ?, @nvarchar15 = ?, @nvarchar16 = ?, @nvarchar17 = ?, @nvarchar18 = ?, @ntext9 = ?, @nvarchar19 = ?, @nvarchar20 = ?, @nvarchar21 = ?, @tp_ContentType = ?, @tp_Modified = ?, @tp_ModerationStatus = ?, @tp_ItemOrder = 200.000000000000, @Size = 720, @ExtraItemSize = @ExtraItemSize ,@CreateItemVersion=1,@ItemName...     


01/13/2009 14:09:52.65*    w3wp.exe (0x1670)                           0x1458    Windows SharePoint Services       Database                          6f8g    Unexpected    ...=N'2 ,jnkj hgh jk',@acl=0xF3FE000001000000000000000500000002000000FFFFFFFFFFFFFF7F190000006110030C000000001A0000007713830CB00100001B0000007713830CB00100001C0000007713830CB0010000; IF @@iRet <> 0 BEGIN ROLLBACK TRAN; GOTO DONE; END   EXEC @@iRet = proc_RemoveJunctions  @SiteId = '73897537-074B-404A-B7FF-814BEF2D21C8', @DirName = @DN, @LeafName = @LN, @FieldId = '6D58D11E-56A7-48B6-94CC-4F4509383ABA', @Level = @@Level; IF @@iRet <> 0 BEGIN ROLLBACK TRAN; GOTO DONE; END   EXEC @@iRet = proc_InsertJunction  @SiteId = '73897537-074B-404A-B7FF-814BEF2D21C8', @DirName = @DN, @LeafName = @LN, @FieldId = '6D58D11E-56A7-48B6-94CC-4F4509383ABA', @Id = 1, @Ordinal = 0, @Level = @@Level, @UIVersion = @@DocUIVersion; IF @@iRet <> 0 BEGIN ROLLBACK TRAN; GOTO DONE; END  EXEC proc_ClearLinks @@S,@DN,@LN,@@...     


01/13/2009 14:09:52.65*    w3wp.exe (0x1670)                           0x1458    Windows SharePoint Services       Database                          6f8g    Unexpected    ...Level,'9DA97A8A-1DA5-4A77-98D3-4BC10456E700'; EXEC proc_ClearLinks @@S,@DN,@LN,@@Level,'D48838AB-DFC6-466C-9CA1-24D035222458'; EXEC proc_ClearLinks @@S,@DN,@LN,@@Level,'53EFC938-7A3C-4189-BE2B-DC0A170F3CF4'; EXEC proc_ClearLinks @@S,@DN,@LN,@@Level,'D12572D0-0A1E-4438-89B5-4D0430BE7603'; EXEC proc_ClearLinks @@S,@DN,@LN,@@Level,'1D15282F-976B-44C7-B2F5-614AFBA80CCF'; EXEC proc_ClearLinks @@S,@DN,@LN,@@Level,'33FB1043-4DE8-483F-A6C6-42E02EDB42ED'; EXEC proc_ClearLinks @@S,@DN,@LN,@@Level,'4A7EDDD9-8639-4734-B3A7-2A5446605547'; COMMIT TRAN; DONE: RETURN;"     


 


In here I saw the SQL Error Code 3621 which pretty much says "The statement has been terminated."

Normally I wouldn't be so worried but in this case it now happens a lot with separate items in this list.

Thinking maybe something has become corrupted I've tried a stsadm -o backup and restore into a fresh site collection in a fresh web application using a fresh content database, but hey the issue has been restored into the new site collection.

Any help and or suggestion would be greatly appreciated, what a way to start the new year at work.

On a great note my holiday was "O" for awesome! Chur Chur.