404 error on a Sharepoint Site : COMException (0x80004005) : The operation cannot be completed successfully

Here's one behavior that you might see. Since the error is not that enlightening and the logs do not tell you what happens, I thought it's usefull to document it.

You have configured your farm and attempt to browse to the site you created. Instead of the page you receive a 404 error ( the webpage cannot be found )  and, if you configured the web.config to display the callstack and the error ( CustomErrors="Off") you might see an exception like below:

COMException (0x80004005) : Cannot complete this action.

Stack :
Microsoft.SharePoint.SPGlobal.HandleComException
Microsoft.SharePoint.Library.SPRequest.PreInitServer
Microsoft.SharePoint.SPSite.PreinitializeServer
Microsoft.SharePoint.SPWeb.InitializeSPRequest()

Scouting the ULS logs for an error does not show clarifying results.

Event viewer might display the following message :  Microsoft-SharePoint Products-SharePoint Foundation 6631

Error: RuntimeFilter: Failed to load all runtime filter configurations or the runtime filter component. Exception has been thrown by the target of an invocation.

Also not that enlightening.

What happens?

When we attempt to open the page, first, the code will try to identify the database where the site resides. In order to achieve this, we go through the PreInitServer routine that should fetch these informations.

The function call fails and you are presented with the above message.

Some of you might have seen this when developing code using VS2010 and targeting the assembly to x86 instead of x64.

The explanation.

The problem is caused by an inability of the worker process to use the Microsoft.Sharepoint.dll assembly .

How can it come to this ?

When the process starts , it will attempt to load and register the needed COM assemblies .If for some reason the operation fails, the assemblies are not loaded in the COM cache. Futher, when we attempt to use them, we cannot find the assembly in the cache, hence we fail when calling the method.

Why it happens ?

Missing permissions on the following registry key HKEY_CLASSES_ROOT\CLSID\{BDEADF25-C265-11D0-BCED-00A0C90AB50F}

How come ?

Usually all the Users should have the read permissions on the above key. If for some reason you have ( at some point in time ) secured the server by removing the Users local group from the readers , the operation will fail.

Additional information.

If you add the application pool account to the administrators group, it will work ( administrators have full control )

Why don't we grant the permissions when running the configuration wizard? - The configuration wizard will grant the permissions to the specific Sharepoint Groups (WSS_). the key does not have specific permission requirements (by default all the users should be able to read it) so it is not touched by the wizard.

Why don't we see access denied operations in the Process Monitor ? Well because the problem occurs when the process loads not when it is already running. Capturing a log after an IIS reset on the first call to the page will show the access denied on the key.

Resolution ? grant the Users the read permission on the key .

Cheers!