System.IO.FileNotFoundException: The Web application could not be found – Part #1

Well, it’s right there, isn’t it? *points finger*

First of all, this is not a developer’s post. This is general troubleshooting, useful for administrators as well.

For non-developers reading this: Here’s a brief intro to the simplest things you can possibly do in SharePoint programming and that is connecting to a site. You’d do that with a call like this:

SPSite site = new SPSite("http://someurl/");

As developers, we generally do about as often as we blink, so it’s pretty rooted in our fingertips. And yes, the URL is always correct.

The problem appears when you start to do this in applications that run outside the IIS web application on which SharePoint runs. This, for example, could be a console application, a Windows application, or a web service.

Developers are lazy bastards so unless something blows up, we don’t really care about potential situations. For that same reason, we usually test all our code running as the account with which we develop, usually an administrator account who has permissions to rival the gods themselves.

So, what is the inevitable consequence? Well, when our code runs as less privileged users (‘minions’ as we like to call them, to further boost our overly bloated egos), the code isn’t blessed with our divine powers and fails miserably.

And waddaya know, when we write that simplest of tests, connecting to a site using that weird syntax above, running as a minion, our code fails, telling us System.IO.FileNotFoundException.

Yeah, I know it works on your machine, developer. I don’t care, the code blows up where it matters, which is in production, and you are responsible for fixing it!

When getting a FileNotFoundException, because we don’t always think (or are too lazy to fire up enough synapses), we assume something is missing. So, we start testing our URL by opening it in the browser, to make sure it works. Lo’ and behold, of course it works! So, there must be a bug in SharePoint, right? The site is there, but SharePoint is claiming that the file is not found.

These situations are likely a cause for people yelling ‘SharePoint sucks!’ (try Googling that term, btw). However, in this case at least, it’s more a case of ‘SharePoint developers suck!’.

SharePoint Frustration

The problem, you see, is in permissions. Minions, as cute as they are, don’t have the awe-inspiring powers that their developer gods possess. That’s why, if we want those minions to be happy, we have to elevate their privileges. Somehow, a few clicks of a mouse and keyboard seems to be enough to keep the minions in their place and leave us to sip our ambrosia in peace.

Which permissions? Well, that’s the trick, isn’t it..?

If you Google around, you’ll find a lot of creative answers. Microsoft suggests (question 10) that you make your users Farm Administrators, give them read/write permissions to the content database, and, just to be sure, grant them site collection administrator rights. If that doesn’t work, which it actually won’t, you’ll need a nuclear device to be able to do more damage.

Paul Galvin, MVP and a nice guy I’m sure, suggests granting users the same permissions as your application pool account. While seemingly logical, it doesn’t explain _what_ permissions you need to set, just that if you give users everything, something is likely to be correct. Making minions as powerful as gods have been scientifically proven (just watch Bruce Almighty) to be a bad idea.

Note: Paul _is_ a great guy, so don’t take this the wrong way. It is symptomatic of an immature platform, however, that its experts are incapable of explaining why something works.

As many other’s mention, if you’re developing against SP2010 and don’t have your platform build set correctly, you get similar errors, although those are easy to spot. I’ve never seen them because, well, I never make mistakes.

None of these things work. I’ll tell you how to find out what works in the next part of this post and even how you can figure out exactly what isn’t found, but in the meantime, ponder this: Why is it that, with the immense amount of traction that SharePoint has and with the truckloads of money that the business world pours into this platform, that so extremely few people really understand what is going on behind the scenes? Even Microsoft recommends handing out keys with dynamite sticks as key chains in case, you know, they door doesn’t open.

I’d love to hear your thoughts about this.


Found this article valuable? Want to show your appreciation? Here are some options:

a) Click on the banners anywhere on the site to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.

b) Donate Bitcoins! I love Bitcoins, and you can donate if you'd like by clicking the button below.

c) Spread the word! Below, you should find links to sharing this article on your favorite social media sites. I'm an attention junkie, so sharing is caring in my book!

Pin It

Published by

Bjørn Furuknap

I previously did SharePoint. These days, I try new things to see where I can find the passion. If you have great ideas, cool projects, or is in general an awesome person, get in touch and we might find out together.

2 thoughts on “System.IO.FileNotFoundException: The Web application could not be found – Part #1”

Leave a Reply

Your email address will not be published.