.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

CryptographicException: The supplied handle is invalid. Possible thread safety issue?

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :.NET Framework

I was seeing a "The supplied handle is invalid" message in CryptographicExceptions intermittently, so I created the following program to reproduce the problem based on the hunch that there was a concurrency issue. Originally the problem was occurring when encrypting data, but I've pruned away as much code as I can to make it smaller/easier to understand (of course the KeyWork method doesn't do too much). 

Note: this is CPU intensive and takes a while to complete. Sorry.

The code:


using System;
using System.Security.Cryptography;
using System.Text;

public class P
	public static void Main()
		byte[] public_encrypting_key = StringToByteArray("45434B3542000000016FE13A42A9D54503BC694E9E298760FC03BA99FB224691BF03830BA9FB58354227541F120667843A8813628ADA70126EA06CBCB3537A1986283D3FA3612F124673010CA5F372A32B50E6B648F61DCF70B3E3782324AA6795891ACD8B87F9CA89F128BD

View Complete Post

More Related Resource Links

ASP.net ResizableControlExtender Handle Issue

I have a resizablecontrolextender hooked to a panel. The panel contains a treeview. As the tree is expanded the panels' scrollbars kick-in so the expanded content can be viewed. The problem is that the RCE handle scrolls with the panel and ultimately disappears. is there any way to keep this from happening? What I am trying to achieve is the panel like effect you would find with VS or Outlook etc...   Thanks, Todd

ThrottledParallelForEach thread safety

I am looking into using ThrottledParallelForEach from http://msdn.microsoft.com/en-us/library/ee620808.aspx but a bit concerned that there is no synchronization in implementation. Is it correct?

Invalid Handle exception when browsing a site on the web front end


We are building a 3-tiered SharePoint 2010 farm that consists of 1 web front end (WFE), 1 app/CA server, and 1 database server.  All servers are running Windows 2008 service pack 1.  We can browse the Central admin site without any issue, but when we attempt to access sites on the WFE we get the 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 t

Issue with Size Property has an invalid size of 0


In my code I have:

SqlParameter param = new SqlParameter("ID", id);
                param.Direction = ParameterDirection.InputOutput;
                wrapper.ParameterCollection.Add("StudentObjectiveID", SqlDbType.Int).Value = objectiveid;
                wrapper.ParameterCollection.Add("SessionID", SqlDbType.Int).Value = sessionid;
                wrapper.ParameterCollection.Add("StaffID", SqlDbType.Int).Value = staffid;
                wrapper.ParameterCollection.Add("EnteredDate", SqlDbType.DateTime).Value = entereddate;
                wrapper.ParameterCollection.Add("Achievement", SqlDbType.NText).Value = Achievement;
                wrapper.ParameterCollection.Add("SessionStudentID", SqlDbType.Int).Value = session_student_id;
                wrapper.ParameterCollection.Add("ImageName", SqlDbType.NVarChar, 255).Value = imagename;
                wrapper.ParameterCollection.Add("ActualDate", SqlDbType.DateTime).Value = actualdate;
                wrapper.ParameterCollection.Add("FileType", SqlDbType.VarChar, 10).Value = filetype;

                int result = wrapper.ExecuteNonQuery();
                id = (int)param.Value;

And in the relevant stored procedure I

"The Handle is Invalid" error in loading SQL Server Management Studio Express

I've instaleld SQL 2005 Express Edition
Then Installed SQL Server Management Studio Express 

Both installation were completed successfully.
However when I try to run "SQL Server Management Studio Express", I can the following error:

"C:\Program Files\Microsoft SQl Server\90\tools\binn\vsshell\common7\IDE\ssmsee.exe"
"The Handle is Invalid"

I can't get it resolved no matter what I do: uninstalling and installing many times, disabling the Virus Scan, etc.
I searched the Web, but unfortunately there is no information about it.

Can anyone help?


Thread.Sleep() issue


 Hello all -


I'm having an issue with thread.sleep, as I'm purposley trying to cause a 5 minute delay in a service oriented application I'm supporting.  When monitoring for a specific exception, I'm doing a Thread.Sleep(300000) statement.  300,000 milliseconds = 5 minutes, right?  Trouble is, the delays encountered are never 5 minutes, always less, and they vary, sometimes 30 seconds, sometimes 40 seconds, sometimes a full minute.  Anybody have any idea why?

Note:  I have my Thread.Sleep(300000) statement in a catch block where I'm monitoring for IOException, specifically a semaphore timeout, or not enough storage available.  Would this type of exception cause the thread.sleep() to behave sporadically like I described above?  Seems to always be consistantly a five minute delay as intentioned when tested elsewhere in my application.

Any insight would be appreciated!




Cannot open 153 channels in .NET 3.5 : an invalid argument was supplied


In .NET 3.5, it is not possible to register more than 152 channels :

class Program
 static void Main(string[] args)
  int port = 8000;
  for (int i = 0; i < 2000; i++)
   TcpServerChannel serverChannel = null;
    IDictionary properties = new Hashtable();
    properties.Add("port", port);
    properties.Add("secure", true);
    properties.Add("name", "channel" + port);
    serverChannel = new TcpServerChannel(properties, null);
   catch (SocketException e)
    Console.WriteLine(string.Format("{0} : {1}", e.GetType().Name, e.Message));

Bitmap.Clone() thread safety

Is it safe to use the output of Bitmap.Clone() on a separate thread?  Or do I need to force a deep copy (make a new bitmap and blit over the contents) to make sure it works right?

Remoting Issue - Authentication Type changes from Kerberos to NTLM in Thread.CurrentPrincipal.Identi


Am facing followingproblem, Authentication Type changes from Kerberos to NTLM in Thread.CurrentPrincipal.Identity where as the user name comes properly while calling the method of service2 through remoting from service1.

Actually the problem scenario is as follows, from client am making calls to service1 and from the service1 am making the call to another service2 where the problem occurs.

             Kerberos                              NTML
Client ----------------> Server1 -------------------------> another service2
         remoting call                      remoting call

But When I made the remoting call from the client directly to service2, am getting the security type as Kerberos properly.

Please advise.

Am running out of time, looking for you valuable comments...!!!



IsapiModule Error 500 Issue


I am about exhausted trying to figure out this error:

HTTP Error 500.0 - Internal Server Error

Description: The page cannot be displayed because an internal server error has occurred.

Error Code: 0x8007007b

Notification: ExecuteRequestHandler

Module: IsapiModule

Requested URL: http://localhost:80/ReportServer

Physical Path: c:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer

When I enable Failed Request Tracing Rules and view the log output I am supposing that the actual problem is in the 2nd call where there are 2 backslashes before the actual filename in the specified path:


CALL_ISAPI_EXTENSION DllName="C:\Windows\Microsoft.NET\Framework\v2.0.50727\\aspnet_isapi.dll"


MVC2 issue - Stuck. Trying to create a cms with nested partials


I am currently trying to display multiple items on a single page. I am not sure as to how to tackle this. What I have is a database table that has all the page data in. I have this run as a PagesController and this works fine. However what I would like to do is, if say the Products page is selected via the menu, I want to pull back not only the Products page html but also get all the products, and even be able to pull them through via category. I was trying to use a partial view, but I can't get it to work. The same would be for other pages, having partial views to display the other content, ie if Gallery is selected, the page html for Gallery shows and it then can push to a partial view that pulls all the gallery images from the gallery db table and so on. 

Maybe I am tackling this the wrong way. I have the pages stored in the db to allow for a CMS system I have setup. Maybe I need to use models for all the other items(Products, Gallery, Videos and such) and use the partial for the page html?

Any help would be greatly appreciated as I am confused.

xpath issue


Hi i am using xpath to loop through each node,

the xml is below i can get the value of "link" but i cant get the thumbnail value, have you got any ideas how i can do this, my code is below.



     <link>test 1</link>
     <media:thumbnail url="http://test.com/image.jpg" height="75" width="75" />



     <link>test 2</link>
     <media:thumbnail url="http://test.com/image.jpg" height="75" width="75" />


public void FindLinks(XPathNavigator p_xPathNav, DataTable dt)
            //run the XPath query
            XPathNodeIterator xPathIt = p_xPathNav.Select("//item");

            //use the

User validation Issue in xlsx file



I am validating user from Login.xlsx file. It was working fine by validating email and password from that file. For testing i got new file same contents of file but added some more user names.

So after that when i validating the user i am getting the following error "Data type mismatch in criteria expression".

But when i replaced the new to old one it is working fine. The contens of both files are the same. So why this kind of error happened.


Multiple Paramatized Threading issue


I need the funcitonality to have two methods run concurrently of each other and the parent thread (aka the method that makes these two calls) to halt until BOTH are done. After the threads are done, I need to perform logic on the returns of the method, so it is essential for both of them to be complete before the parent thread continues. I have searched the internet and tried varous attacks, and I always come up with the same result, this being the parent thread continues operation after the first thread finishes, leaving the second thread running.  Can someone show me a quick example of how I can do this. I have tried checking states of the threads, halting the threads, but I always end up with the same thing. Any help would be great. Thanks.

Data Truncation issue with Enterprise Library Logging WriteLog stored Proc


Hi ,

I'm using Enterprise Library Logging  feature for logging. The issue i am facing is when the Logging message is too large(more than 65534 chars) ,complete data  is not logged in the Formatted Mesage column which is  of data Type nText .

I am able insert complete data if i try inserting from Sql insert Query from sql management studio. Do i need to add any attributes to data base listener or do i need to change the sp.

 Is there any way to increase the WriteLog stored proc param size in EnterpriseLibrary.Logging config file ? . Please let me know.


Thanks In Advance.

Word Automation Issue in Windows Server 2008 Hosting



The problem I am posting here is that I was facing nearly 2 weeks around. Any body comes with this stuff please help.

Word Automation in sample ASP.NET(C#) application.

I am using Microsoft.Office.Inetrop.Word Assembly for automation. Here I am reading a XXX.dot template file and fill the contents with dynamic data.

When i am executing my code in localhost:someportnumber the automation is working fine and I could get expected result and when I am hosting in my inetmgr(Windows XP is my OS) it is also working fine.

But the problem is that when I am hosting in my production server(Windows Server 2008 Standard Edition) I am not able to perform automation and results in the following error.

Data: System.Collections.ListDictionaryInternal
Message: Word has encountered a problem.
Source: Microsoft Word

The code gets failed in the following line:

ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

Document wordDoc = wordApp.Documents.Add(ref oTemplate, ref oFalse, ref oMissing, ref oMissing); // Error in this line

I cannot able to proceed further. Can anybody please help me in solving this issue?

Thank you.

With Regards,


Invalid length for a Base-64 char array for my coding in ASP.net C#. How to solve it ?


Hi Friends ,

I have done encrypted password and decode but i got error  like  this  " Invalid length for a Base-64 char array" .

Pls help . Thanks


psswd = txtPassword.Text;

pwed = base64Decode(psswd);

public string base64Decode(string sData)
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(sData);
            int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string result = new String(decoded_char); return result;

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend