Skip to content

SPSite throws FileNotFoundException: The Web application at … could not be found. Verify that you have typed the URL correctly.

May 30, 2011

Awful error. Took a long time to troubleshoot and the solutions was so straightforward that it made me very mad.

So the story is the following:
I created a simple console application and I wanted to create an SPSite from the application to be able to access the SharePoint context. Sounds very simple:

class Program
{
	static void Main(string[] args)
	{
		using (SPSite site = new SPSite("http://site-collection-url"))
		{
			//TODO:
		}
	}
}

When I tested the application I received the following error right at line 05:

System.IO.FileNotFoundException: The Web application at could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application. at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean con
textSite, SPUserToken userToken)

Did a lot of googling to find out what can be the reason for this. What I found:
A lot of people get this error.

  • For some people the error is caused by insufficient permission. This was not my case.
  • For some people the error is caused by incompatibility between x86 and x64 assemblies. This was not my case.
  • For some people the error is caused by Alternate Access Mapping issues. This was not my case either.

So what else can it be? I didn’t expect too much from the ULS logs (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\LOGS) but gave it a try in my desperation. Luckily. I found the following clue:

An exception occured while trying to acquire the local farm: System.TypeInitializationException: The type initializer for ‘System.Data.SqlClient.SqlConnection’ threw an exception.
—> System.TypeInitializationException: The type initializer for ‘System.Data.SqlClient.SqlConnectionFactory’ threw an exception.
—> System.TypeInitializationException: The type initializer for ‘System.Data.SqlClient.SqlPerformanceCounters’ threw an exception.
—> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize
—> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section web.config.
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) — End of inner exception stack trace —
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.Switch.InitializeConfigSettings()
at System.Diagnostics.Switch.InitializeWithStatus()
at System.Diagnostics.Switch.get_SwitchSetting()
at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)
at System.Data.SqlClient.SqlPerformanceCounters..ctor()
at System.Data.SqlClient.SqlPerformanceCounters..cctor() — End of inner exception stack trace —
at System.Data.SqlClient.SqlConnectionFactory..ctor()
at System.Data.SqlClient.SqlConnectionFactory..cctor() — End of inner exception stack trace —
at System.Data.SqlClient.SqlConnection..cctor() — End of inner exception stack trace —
at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
at Microsoft.SharePoint.Utilities.SqlSession.OpenConnection()
at Microsoft.SharePoint.Utilities.SqlSession.ExecuteReader(SqlCommand command, CommandBehavior behavior)
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.FetchId(QualifiedObjectName qName)
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.GetObject(String name, Guid parentId, Type type)
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_Farm()
at Microsoft.SharePoint.Administration.SPFarm.FindLocal(SPFarm& farm, Boolean& isJoined)

Then I checked the app.config file of my console application and I found out. It was corrupt. I made some changes in the file earlier that I never thought to cause such issues. I restored the original app.config file and the error was resolved.

Advertisements
One Comment
  1. tschuege permalink

    i had the same problem. i thought it was the x86 / x64 issue… until i found your post.
    thanks a lot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: