Recently while working on asp.net application , I got following exception
Server Error in ‘/’ Application.
The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[COMException (0x80070006): The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))]
[FileLoadException: Could not load file or assembly ‘SMDiagnostics, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b77a5c561934e089’ or one of its dependencies. The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))]
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +0
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +86
After much much of the time , I came to conclusion that following steps can able to solve the problem fast , at least it done the same for me.
First of all check –
Check if the assembly reference added under <assemblies> of Web.config
<add assembly=”SMDiagnostics, Version=22.214.171.124, Culture=neutral, PublicKeyToken=B77A5C561934E089″ />
Verify if the file SMDiagnostics.dll exists in the folder at location:
C:\windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation
Also Verify if the assembly is registered into the GAC :
If the file is there in GAC you can able to see ‘SMDiagnostics, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089’ in the list
If the answer for any of the two questions is no, then .Net framework WCF component may not be installed successfully on the machine. Please try reinstalling it.
If still you are not able to solve the exception,Check if your solution is referring to the any External Dll ,
which is not getting loaded due to some reason and eventually raising the exception.
This was exactly the same case with me.
I was using one COM component funcationality which was placed in dll , which is placed under BIN folder and
was using/accessing the functions from COM in App_code business code files. and path was mentioned in Web.config as Key like
<add key=”FuncPath” value=”C:\Inetpub\wwwroot\XYZ\APPLICATION\Bin\”></add>
and as the files in the BIN are not getting loaded , it was giving me the error.
After some following the issue for more than 3-4 hours of try and error I found the reason that Under IIS , for Virtual Directory Properties Execution Permissions were marked as “Scripts and Executables” the dll is not being loaded and I was getting “System.Runtime.InteropServices.COMException”
After changing Execution Permissions to “Scripts Only” and applying it. it was started working fine.
I dont know the any special difference other than
Scripts only Run only scripts,such as ASP applications and
Scripts and Executables Run both scripts, such as ASP applications, and executables
Although my problem is solved, I am still searching for difference… Anyone Please ……