.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 ‘access’

FIX: A NullReferenceException error occurs when you run a .NET Framework 2.0 program

Symptoms
When you run a Microsoft .NET Framework 2.0 program, aNullReferenceException error occurs, or you receive an access violation error message. If you debug the crash, you find an access violation in the MSCORJIT!emitter::emitJumpDistBind function.
Resolution
This problem occurs because of an optimization bug in the just-in-time (JIT) compiler.

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: Access Violation Occurs with Non-Updateable Derived Table in UPDATE Statement

Symptoms
If you run a query that tries to update a derived table that contains a UNION statement, a handled Access Violation occurs and the connection is closed. For example, the following query:

declare @x intupdate tset @x = coalesce( @x , 0 ) + nfrom ( select 1 union all select 2 union all select 3 ) as t( n ) returns this error message:

ODBC: Msg 0, Level 19, State 1
SqlDumpExceptionHandler: Process 51 generated fatal exception c0000005
EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process.
Connection BrokenSQL Server also prints a stack dump to the error log with text similar to the following example. Please check the error log for the Access Violation and note that the Exception Address is in (res_view(class CAlgStmt *,class TREE * *):

2000-08-28 12:13:37.77 spid51Error: 0, Severity: 19, State: 02000-08-28 12:13:37.77 spid51SqlDumpExceptionHandler: Process 51 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process..********************************************************************************* BEGIN STACK DUMP:*08/28/00 12:13:37 spid 51**Exception Address = 0067CA0C (res_view(class CAlgStmt *,class TREE * *) + 000003E3 Line 0+00000000)*Exception Code= c0000005 EXCEPTION_ACCESS_VIOLATION*Access Violation occurred reading address 00000000* Input Buffer 256 bytes -*declare @x intupdate tset @x = coalesce( @x , 0 ) + nfrom ( select*1 union all select 2 union all select 3 ) as t( n )**
Resolution
Microsoft has confirmed this to be a problem in SQL Server 2000.

BUG: “Unhandled exception in EXENAME.EXE(OLE32.DLL): 0xC0000005: Access Violation” when you use an ATL Composite control on computers without Visual C++ installed

Symptoms
When you create an ATL Composite control with other ActiveX controls embedded in it, you may get an access violation in Ole32.dll. Usually, a message box is displayed with the following error message:

Unhandled exception in EXENAME.EXE(OLE32.DLL): 0xC0000005: Access ViolationYou may also see a Web Browser control displayed with the following message, instead of the child ActiveX control:
This page cannot be displayed. Usually, these controls work correctly on computers with Visual C++ installed, but they do not work on computers without Visual C++ installed.
Resolution
The ActiveX controls embedded in the Composite control may be licensed controls. Composite controls and ATL containment do not directly support creation of licensed controls.
When the Composite control attempts to create a licensed control on a computer without providing a run-time license, the Composite control fails with an HRESULT of 0×80040112 (CLASS_E_NOTLICENSED – Class is not licensed for use). The default handling of this failure creates a Web Browser control; the default handling also tries to initialize the Web Browser control with persisted properties of the licensed control. This mismatch of properties may result in an access violation in the Ole32.dll file.
If there is no access violation, the Web Browser control attempts to navigate to a URL that is the string representation of the licensed control’s CLSID. This action results in the error message “The page cannot be displayed.”

An illegal instruction exception or an access violation exception causes the Intersite Messaging service to crash

Symptoms
An illegal instruction (C00000FD) exception or an access violation (C0000005) exception occurs in the Intersite Messaging service (ismserv.exe). The exception causes ismserv.exe to crash.
Resolution
This problem occurs if a function in the Adsiis.dll component leaves a released cache item in the server cache when a remote procedure call (RPC) error occurs. When a subsequent client request tries to use the released cache item, the illegal instruction exception or the access violation exception occurs.

An Exception Occurs in WtvMailApp

Symptoms
You may receive an “Access violation while reading from location 0×0FB04000″ exception in the worker thread of the mail program.
Resolution
Offset and length parameters for CWtvMailApp::GetRequestParam that are not valid cause the mail program to try to access memory that is beyond the message’s data.