.NET Questions and Solutions

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries for January, 2010

BUG: You may receive a “COMException (0×80010105): The server threw an exception” error message in Visual Studio .NET 2003

Symptoms
In Microsoft Visual Studio .NET 2003, if you automate your application to run out-of-process, you may receive a COM exception error message that is similar to the following from the Devenv.exe out-of-processcomponent:

Unhandled Exception: System.ApplicationException: Failed —> System.Runtime.Int
eropServices.COMException (0×80010105): The server threw an exception.at EnvDTE._Solution.Open(String FileName)at DTEAutomation.Class1.Main(String[] args) in c:\vs7play\enterprisetemplate\dteautomation\class1.cs:line 45
— End of inner exception stack trace —at DTEAutomation.Class1.Main(String[] args) in c:\vs7play\enterprisetemplate\dteautomation\class1.cs:line 80
Resolution
This problem occurs because a cached pointer to the selected data is not valid.Then,the Enterprise Template Project is opened.

BUG: XmlTextReader Decodes URLs Before Downloading Resources Resulting in Unpredictable Behavior

Symptoms
When you use the XmlTextReader object to download resource files, the reader decodes the URL for the resources. If the URL contains any special characters (for example, ampersands or percent signs), this may result in unpredictable behavior.
Resolution
To resolve the problem, follow these steps: Use the XmlUrlResolver and the System.IO.Stream classes to map the specified URL.Create an XmlTextReader object and pass the Stream as the parameter. For an example, see the “More Information” section of this article.

BUG: Various errors may occur when you try to call managed code from unmanaged code in Visual C++ .NET 2003

Symptoms
You have a Microsoft Visual C++ .NET 2003 application that uses multiple application domains. When you try to call managed code from unmanaged code in a DLL that has already been loaded in another application domain, you may receive the following error message:

An unhandled exception of type ‘System.NullReferenceException’ occurred in mscorlib.dll
Additional information: Object reference not set to an instance of an object.Note In some scenarios, you may receive one of the following error messages:

DllNotFoundException

Illegal Instruction
Resolution
You may notice this problem if your application contains unmanaged code and uses multiple application domains.
For example, if you have an application that uses multiple application domains that use a set of DLLs, you can successfully load and use these DLLs in the first application domain. However, when you try to call the managed code in one of these DLLs from unmanaged code in a different (second) application domain, the behavior that is mentioned in the “Symptoms” section of this article occurs. The application does not load the managed code in the second application domain because the code has already been loaded in another application domain that is in the same process.

BUG: Unhandled exception filter not called inside debugger

Symptoms
Win32 processes can install an unhandled exception filter function to catchexceptions that are not handled in a __try/__except block on a process-widebasis. When debugging such a process, you find that the unhandled exceptionfilter is never executed, even when you put a breakpoint inside it.However, when the process is not being debugged, its unhandled exceptionfilter is called as expected.
Resolution
When called from a process being debugged, the UnhandledExceptionFilter()Win32 API function does not call the application-installed unhandledexception filter.
Note The UnhandledExceptionFilter() API determines whether the process is being debugged. If the process is being debugged, the UnhandledExceptionFilter API passes the exception to the debugger. Then, the UnhandledExceptionFilter API calls the unhandled exception filter for the process.

BUG: The System.Collections.Queue.Clone method loses data while cloning objects

Symptoms
The Queue class is a Microsoft .NET Framework Class Library class. It represents a first-in, first-out collection of objects. However, if you use the Queue.Clone method to clone a queue, and if the call to the Queue.Dequeue method is made before the call to Queue.Clone method is made, the data is lost.
Resolution
A bounded buffer is used to implement the Queue class. The Clone method uses the beginning of the buffer, instead of the head pointer, as the starting point. When the Dequeue method is called, the first element is removed. However, the beginning of the buffer remains the same. Therefore, the first element appears as an empty element and the last element is lost in the cloning process.

BUG: Unhandled exception error occurs when you enumerate through the Hashtable

Symptoms
In a Remoting scenario, you may try to move the Enumerator for a Hashtable from the server side to the client side. You do this so you can iterate through the Hashtable on the client side. While you are enumerating through the Hashtable, you may receive the following error message:

An unhandled exception of type ‘System.InvalidOperationException’ occurred in mscorlib.dll
Additional information: Collection was modified; enumeration operation may not execute.
Resolution
The error occurs because the Hashtable Enumerator is a MarshalByValue component. Therefore, the Hashtable stores the owner of the Hashtable internally. When you request the Hashtable on the client side, the Hashtable is deserialized on the client side. During deserialization, the internal Hashtable is reconstructed. Therefore, the enumerator fails.