Custom Sharepoint 2007 Timer Job - Object Reference Not set to an instance
Hi, I am creating a Custom Sharpeoint timer job (in 2007) and i used Andrew Connel's blog and his code to create it. But for some reason I always get this error. I commeted out all my code inside execute method but still its the same. I am deploying my timer using Solution Package installation and activated the Feature. Here is the error: The Execute method of job definition CustomSPJobDefinition.CustomSPService (ID 88a735f1-bbb7-4fea-932f-690dfc25a212) threw an exception. More information is included below. Object reference not set to an instance of an object. Code: Guid targetInstanceId = new Guid("EAC61BD1-0C2A-45F6-9148-3A8BC9C93339"); public override void Execute(Guid targetInstanceId) { System.Diagnostics.Trace.Assert(false); try { // get a reference to the current site collection's content database SPWebApplication webApplication = (SPWebApplication)this.Parent; SPContentDatabase contentDb = webApplication.ContentDatabases[targetInstanceId]; // get a reference to the "Tasks" list in the RootWeb of the first site collection in the content database SPList taskList = contentDb.Sites["sites/abc"].RootWeb.Lists["Tasks"]; // create a new task, set the Title to the current day/time, and update the item SPListItem newTask = taskList.Items.Add(); newTask[ "Title"] = DateTime.Now.ToString(); newTask.Update(); } catch (Exception ex) { //Handle errors to make sure we do not pass on errors to the OWSTimer throw ex; } } Please let me know where I am going wrong. Thanks in advance.
November 17th, 2010 4:49pm

Hi, If you are following andrew blog then Your code will automatically take GUID from content database. You don't need to provide your GUID here. Comment this line: Guid targetInstanceId = new Guid ( " EAC61BD1-0C2A-45F6-9148-3A8BC9C93339 " ); Let me know the answer Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 2:13am

That fixed the error and my job started running but the issue is it just enters into Excute method and never excutes the lines inside that function. I attached OWSTIMER and tried to debug the code. While debugging it enters the function but when I try to add breakpoint on any line inside the function it says "Common Langusge Runtime Unable to attach the breakpoint". I did verify the dll in gac is the correct version. Any idea why? In event viewer the error event id's are 2424 and 2436. Thanks.
November 18th, 2010 3:25pm

Hi, This error does not come in sharepoint normally. Follow the below points: 1. Replace below line SPWebApplication webApplication = ( SPWebApplication ) this .Parent; to SPWebApplication webApplication = this.Parent as SPWebApplication ; 2. Rebuild your solution and replace the dll in GAC 3. Reset the IIS and Restart the timer job Let me know if it works Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 11:30pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics