0

I added the Microsoft.SharePoint.dll into a console application and have written some SharePoint code, i can see the results on the console, but when I created a Web API project and added the same code, its throwing the error. Any idea what I am missing? Does Web API support SharePoint or tweaks have to done?

Console Application: Able to get the count of alerts on the site Console project with Microsoft.SharePoint.dll

Web API Application: Getting error here... Web API project with Microsoft.SharePoint.dll

Update1: Hosted the Console and Web API app in the same server where SharePoint is installed. Null reference is for the SPWeb object.

Update2: Not all the values of SPSite and SPWeb objects are not filled with SharePoint data. Some values like SPSite Id are returned, but not all.

"Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation."

enter image description here

krishna
  • 575
  • 2
  • 8
  • 22
  • Related: [What is a `NullReferenceException` and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Soner Gönül Apr 03 '15 at 08:21
  • A few questions. Is it the `web` or the `Alerts` object that is null? How do you authenticate the API? – Eric Herlitz Apr 03 '15 at 08:24
  • The second update is irrelevant - if you try to enumerate eg. AllWebs the delay is so large the debugger times out and refuses to display the rest of the methods. That doesn't mean they are empty – Panagiotis Kanavos Apr 06 '15 at 08:55
  • Does your *application pool identity* have permission to this site? Why do you use the server-side SDK instead of the client-side SDK anyway? – Panagiotis Kanavos Apr 06 '15 at 08:56
  • @PanagiotisKanavos Didnt work with the client side SDK, I have few questions. 1 - How can we use Client side SDK with Web API. 2- Any issue which would come across if we use Client side SDK? – krishna Apr 06 '15 at 10:52
  • @krishna `didn't work` isn't a helpful problem description. – Panagiotis Kanavos Apr 06 '15 at 10:53
  • @krishna you should use client SDK because: 1. your code is not hosted in SharePoint 2. not using it causes problems as you can see. – Jan Vanek Apr 10 '15 at 13:26
  • @JanVanek I would have gone with Client SDK if it supports SharePoint Alerts, but I am afraid it doesn't. Any other alternative? – krishna Apr 14 '15 at 06:00

1 Answers1

0

Resolved it by placing SharePoint Server side code in

RunWithElevatedPrivileges

and using the same Application Pool Identity which is being used to run the SharePoint Web Application.

krishna
  • 575
  • 2
  • 8
  • 22