.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 Tagged ‘microsoft net framework’

FIX: A .NET Framework 2.0-based application may experience an ArgumentNullException exception and may exit unexpectedly

Symptoms
When you run a Microsoft .NET Framework 2.0-based application, the application may experience an ArgumentNullException exception and may exit unexpectedly (crash).
Resolution
This problem occurs because the FileSystemWatcher class throws an unhandled ArgumentNullException exception. This exception is generated because a race condition occurs between events that raise loops and the StopRaisingEvents method.

Description of the documentation error in the “HttpServerUtility.Transfer Method (String, Boolean)” topic in the Microsoft Developer Network

Symptoms
This article describes the undocumented change in behavior of the HttpServerUtility.Transfer method call from the Microsoft .NET Framework 1.0 to the Microsoft .NET Framework 1.1.
For more information, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/aa332847(VS.71).aspx(http://msdn2.microsoft.com/en-us/library/aa332847(VS.71).aspx)
Resolution
The HttpServerUtility.Transfer method contains two parameters. The first parameter is a URL path of the new page on the server to execute.The second optional parameter indicates whether the Form and the QueryString values can pass from the calling page to the page that the user is being transferred to.

HttpServerUtility.Transfer(String, Boolean); In the .NET Framework 1.0, if the second optional parameter of the HttpServerUtility.Transfer method is not specified, the second parameter is set to false.
In the .NET Framework 1.1, if the second optional parameter of the HttpServerUtility.Transfer method is not specified, the second parameter is set to true.
The “Parameters” section of the “HttpServerUtility.Transfer Method (String, Boolean)” topic in MSDN states the following:
path
The URL path of the new page on the server to execute.
preserveForm
If true, the QueryString and Form collections are preserved. If false, they are cleared. The default is false.
The following is the correct information:
path
The URL path of the new page on the server to execute.
preserveForm
If true, the QueryString and Form collections are preserved. If false, they are cleared. In the .NET Framework 1.0, the default value of the preserveForm parameter is false. In the .NET Framework 1.1, the default value of the preserveForm parameter is true.

Description of the .NET Framework 1.1 post-Service Pack 1 hotfix rollup package for System.windows.forms.dll

Symptoms
This article describesthe Microsoft.NET Framework 1.1 issues that are fixed in the .NET Framework 1.1 post-Service Pack 1 hotfix rollup package for System.windows.forms.dll.
Issues that are fixed in the hotfix packageFor more information, click the following article number to view the article in the Microsoft Knowledge Base:
875434?(http://support.microsoft.com/kb/875434/) FIX: You receive a NullReferenceException exception when you manually set a Control ID in the .NET Framework 1.1
840503?(http://support.microsoft.com/kb/840503/) FIX: The scroll bar may not show the correct position in a spreadsheet in a Windows Forms application in the Microsoft .NET Framework 1.1
841096?(http://support.microsoft.com/kb/841096/) Validation event does not fire for Microsoft Windows Forms controls
873429?(http://support.microsoft.com/kb/873429/) FIX: A gradual memory leak occurs in a WinForm application when you create, modify, or remove a MenuItem property for an MDI form in the .NET Framework 1.1
884579?(http://support.microsoft.com/kb/884579/) FIX: The Click event for a button in a UserControl control occurs even though another UserControl control is set to cancel form validation in a Microsoft Windows Forms application that is built on the Microsoft .NET Framework 1.1
886802?(http://support.microsoft.com/kb/886802/) FIX: You may receive the “AxImp error object reference not set to an instance of an object” error message when you run AxImp.exe on an ActiveX control in the .NET Framework 1.1
886686?(http://support.microsoft.com/kb/886686/) FIX: You can close a form by using the Close button even if the Cancel property of a Validating event is set to True on an object in a Windows Forms application in the .NET Framework 1.1
885446?(http://support.microsoft.com/kb/885446/) FIX: You may experience unexpected behavior when you press TAB or ENTER in a Windows Form on a computer that is running the .NET Framework 1.1 S885446
Resolution
Hotfix informationA supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next .NET Framework 1.1 service pack that contains this hotfix.
To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:
http://support.microsoft.com/contactus/?ws=support(http://support.microsoft.com/contactus/?ws=support)NoteIn special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.PrerequisitesYou must have the.NET Framework 1.1 Service Pack 1 (SP1) installed to apply this hotfix.Restart informationYou do not have to restart your computer after you apply this hotfix.Hotfix replacement informationThis hotfix is not replaced by any later hotfix.Registry informationYou do not have to create or to modify any registry keys to activate any hotfixes that are contained in this package.Hotfix file informationThis hotfix contains only those files that you must have to correct the issues that this article lists. This hotfix may not contain of all the files that you must have to fully update a product to the latest build.
The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.

DateTimeVersionSizeFile name———————————————————————07-Oct-200421:461.1.4322.20382,052,096System.windows.forms.dll

BUG: You receive a security exception error message when you call the EventLog.WriteEntry method by using the EventLogPermissionAccess.Write access level in the .NET Framework 2.0

Symptoms
Consider the following scenario. In the Microsoft .NET Framework 2.0, you create an instance of the EventLogPermission class that has the EventLogPermissionAccess.Write access level. You call the EventLogPermission.PermitOnly method to restrict code access. Then you call the EventLog.WriteEntry method to write an entry to the event log. In this scenario,you receive a security exception error message that resembles the following:

Unhandled Exception: System.Security.SecurityException: Request for the permission of type ‘System.Diagnostics.EventLogPermission, …’ failed.
Resolution
To work around this issue, you must request the EventLogPermissionAccess.Administer access level before you call the EventLogPermission.PermitOnly method. After you specify this access level, you can call the EventLog.WriteEntry method and write an entry to the event log. The following code example demonstrates how to write an entry to the event log by using this workaround.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

using System;using System.Diagnostics;public class TestCase{ public static void Main() { EventLogPermission eventLogPermission = new EventLogPermission(EventLogPermissionAccess.Administer, “.”); eventLogPermission.PermitOnly(); EventLog.WriteEntry(“Source”, “Message”); }}

BUG: You receive a COMException exception when you pass late-bound parameters to methods of Office objects in Visual Basic 2005 or in Visual Basic .NET

Symptoms
In a Microsoft Visual Basic 2005 or Microsoft Visual Basic .NET application, when you pass late-bound parameters to methods of Microsoft Office objects, you may receive COMException exceptions. For example, when you pass the Name property of a late-bound UserProperty object to the UserProperties.Items method, you may receive the following error message:

An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in microsoft.visualbasic.dll
Additional information: Property is read-only.Note Similar symptoms may also occur when you call methods of other Microsoft Office objects.
Resolution
If you pass a property of an object to a method by reference and the property has a set accessor, Visual Basic calls the set accessor to set the property to the value that the method returns. At compile time, if you pass a property of a late-bound object, the Visual Basic compiler cannot determine whether the property is passed by reference. Also, the Visual Basic compiler cannot determine whether the property has a set accessor. Therefore, the Visual Basic compiler permits the late binder to determine these details at run time.
However, if the relevant objects are Component Object Model (COM) objects at run time, the late binder cannot obtain sufficient information about these details. The late binder uses managed reflection to try to determine these details. The late binder assumes that such method calls involve a ByRef parameter and that the property that you pass has a set accessor. If the property that you pass does not have a set accessor, the Microsoft .NET Framework generates a MissingMethodException exception. The late binder handles the MissingMethodException exception.
The .NET Framework generates a MissingMethodException exception when the call to a method of a Microsoft Office object returns a HRESULT value of COR_E_MISSINGMETHOD. The Microsoft Office object is a COM object. Visual Basic .NET incorrectly assumes that all the methods of Microsoft Office objects return COR_E_MISSINGMETHOD if the property that you pass does not have a set accessor. However, not all the methods of Microsoft Office objects return COR_E_MISSINGMETHOD if the property that you pass does not have a set accessor. Therefore, the behavior that is mentioned in the “Symptoms” section of this article occurs if you pass a property that does not have a set accessor, such as the UserProperty.Name property, to a method.
Note This behavior does not occur if you use early-bound Microsoft Office objects.

BUG: An “Object reference not set to an instance of an object” error occurs when you try to access data by using ADO Interop on an ASP.NET page

Symptoms
On a computer that has Microsoft .NET Framework 1.0 installed (and that does not have Microsoft Visual Studio .NET installed), when you try to access data using ADO Interop on an ASP.NET page that resides at an identical site and that is hosted on the same computer, you may receive the following error message:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Resolution
To resolve this problem, register the Adodb.dll file in the global assembly cache (GAC). On a computer where only the .NET Framework is installed, the file Gacutil.exe does not exist.. Either obtain the gacutil file by installing Microsoft .NET Framework SDK, or create a Visual Studio.NET setup project that uses the installer to install the correct components.
To register Adodb.dll in the GAC, follow these steps: Click Start and then click Run. In the Run dialog box, type the following command, and then click OK:
C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\gacutil /i C:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll