Debugging Custom Event Receivers – Strange Error on custom Event Receiver SharePoint 2010. .c__DisplayClass2.b__0()Object reference not set to an instance of an object.
Debugging Custom Event Receivers.
Here’s a weird error that took some time to figure out. Generic “Object reference not set to an instance of an object.” Error on a custom SharePoint 2010 event receiver. If I went through the UI to change a field on a list, the event receiver fires fine. But, if a workflow changed the field it threw the error below. I finally found if I attached the OWSTimer process to Visual Studio, it would debug, but still not show the exact problem. The solution is to find the Log On account for OWSTimer in the Services console (services.msc) and then to grant that account permissions on the list that the event receiver is running on.
Edit -checking the permissions of the OWSTimer account is just one possible solution. What I found out was that the list was hanging on to old event receivers as well. I had to use SPManager to see how many event receivers were still active on the list.
Also, I thought the OWSTimer process may be holding onto cached dll’s, so you will need to restart the OWSTimer service in services.msc, and IIS Reset to reset the app pools in order to see new dll changes.
After starting over, checking the number of event receivers, attaching to the W3 process for UI changes, and the OWSTimer for timer based changes, I was able to get a stable debugging environment. I also reset the OWSTimer service and IIS between each debugging session.
Object reference not set to an instance of an object.
PricingRequestReceiver.UpdateDashboardItem(SPItemEventProperties properties, Boolean bNewItem)
We use this to delete users from the site collection. It was gone in 2010, but really just “hidden.”
Here’s a quick reusable way to hide the left navigation.
Create a text file called “HideLeftNav.txt” in a document library.
Add the following css code:
/*–Hide Quick Launch –*/
Edit the page you want to hide the nav on, add a content editor webpart. Then, simply reference the url to the HideLeftNav.txt file and you are done.
Creating a WCF service on a SharePoint 2010 server in Visual Studio 2010 and “Type can not be found” error
If you get the “Type cannot be found” error after installing your WCF service, go to the section about unloading your project below.
Here are the main steps to creating a WCF service and installing it on a SharePoint 2010 server:
- Open Visual Studio 2010
- Create an Empty SharePoint 2010 project to get the packaging files
- Change your namespace in the Project Properties.
- Add a new Item, WCF Service with a new file name
- Add the following lines above the class declaration that implements the “IService” file:
[AspNetCompatibilityRequirementsAttribute(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
PricingRequestService : IPricingRequestService
Add the following references to your project:
- C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll
- Add a mapped folder to the “_Layouts” folder
- Inside the _Layouts folder create a text file with a .svc extension such as PricingRequestService.svc
Add the following sample: <%@ServiceHost
Factory=”Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=220.127.116.11, Culture=neutral, PublicKeyToken=71e9bce111e9429c”
- Change the namespace and service name to your own. Leave the public key token alone as it refers to the ServerRuntime dll.
Gotcha from MSDN:
Make sure to Unload your project and add this to the project file:
Just above </PropertyGroup>
Because Visual Studio 2010 by default does not process the type of tokens used in the previous .svc file, you must add an additional instruction in the project file. Save all changes in your project, right-click the RevertService project, and then click Unload Project. Right-click the RevertService node again, click Edit RevertService.csproj or Edit RevertService.vbproj, and add a <TokenReplacementFileExtensions> tag as follows to the first property group in the .csproj or .vbproj file to enable processing of tokens in .svc file types.
- Package your project to get your .wsp package
Run the following Powershell commands to add/install the solution
- Add-SPSolution “i:\YourPath\PricingRequestCP.wsp”
- Install-SPSolution -Identity PricingRequestCP.wsp –GACDeployment
- Verify your dll is in the GAC and your .svc file is in the _Layouts folder in a subfolder.
To undeploy your solution, run these Powershell commands:
- Uninstall-SPSolution -Identity PricingRequestCP.wsp -Confirm:$false
- Remove-SPSolution -Identity PricingRequestCP.wsp -Confirm:$false
Find and make a backup copy of the Core.JS file(14\template\layouts\inc)
Edit the Core.JS file(14\template\layouts\inc)
Find the function called ErrorVisualization_ShowShortMessage
Add “return;” as the first command in the function.
Here’s a kind of fun web part I found on Codeplex. You can jump on the tiles bandwagon in SharePoint 2010. It’s packaged nicely in 2 wsp files and creates a list to hold the data. Built in images are very nice.
It’s called the Metro Grid webpart and they have done a nice job on the packaging and icons.
Having just got home from Las Vegas, I’d like to relate some of the things I saw at the MS SharePoint 2012 conference. With over 10,000 attendees filling up the Mandalay Bay beach, I am amazed year after year of the growth. When I started working with SharePoint in 2001, who would have thought it turned into this.
Bon Jovi rocking out at Mandalay Bay for the SharePoint conference.
There was just so much content to handle in the limited time with multiple overlapping sessions. I have a to-do list a mile high on getting the slide decks from all the sessions I couldn’t make. I was turned away at the door multiple times because the rooms were full. It baffles me how some rooms have 500 empty seats and others are overbooked by 500. It seems the developer ones are always oversubscribed and they should have a better logistical forecast based on surveys. While we are on a rant, the hands on labs were down for the first 2 and a half days due to network issues. But I digress, the conference was a lot of fun and I met some very cool people.
Some questions about the future:
-Forget Sandboxed Solutions
No more sandbox, all cloud App model. Kind of funny as sandboxed solutions were just released not too long ago.
-No more SharePoint as a platform
What does this mean? SharePoint has always been a platform. Well, no more server side code. It just doesn’t fit into the Cloud model. SharePoint is moving towards being an App. All custom logic will be in cloud apps in the cloud app model. No more server side code like custom visual studio workflows, you need to realize they won’t get migrated to SharePoint online today. If you need server side code, get to know Azure. Be careful about creating a lot of custom server-side SharePoint code unless you know for sure you will stay on-premise for a long time. Are you willing to bet your job on it? As a consultant, I realize on-premise installations will be around for many, many years. One case in point is that I spoke with a person at the conference who said many of her clients are still on not just SharePoint 2007, but still SharePoint 2003.
Get to know Azure
Azure has been around for a while, but it’s growing more important as the cloud model increases. I would suspect MS’s cloud strategy is driven from a profitability model based on the recurring subscriptions. That said, it doesn’t really matter why, it’s happening very fast. Azure can host web sites, sql servers, workflows, etc. This will be very important as many on-premise SharePoint installations begin migration into the cloud and need a place to put their server side code.
Cool and important things that I made notes to get a deeper understanding on. I’ll try to fill out these topics more as time permits.
Power Pivot in Excel 2013
Power View in Excel and SharePoint 2013
_API – new API in SharePoint 2013
OData – Open Data protocol
OAuth – Open Authorization protocol for all authentication
Workflow alerts getting sent into a Messaging service into Windows 8 tiles and toast
Twilio SMS to add messaging to workflows
Azure websites, workflow engine, SQL databases.
Office 365 service description
Limitations of Office 365, SharePoint online
Jquery, Knockout, DataJS
If you were at the conference, feel free to add your comments or opinions. I’d like to hear what you have to say.