Microsoft KB Archive/815635

= PRB: “System.NullReferenceException” Unhandled Exception Error Occurs When You Run a .NET Portable Executable in Internet Explorer =

Article ID: 815635

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-





Beta Information
This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about how to obtain support for a Beta release, see the documentation that is included with the Beta product files, or check the Web location from which you downloaded the release.



SYMPTOMS
When you run a .NET Portable Executable (PE) in Microsoft Internet Explorer, and the PE accesses certain members of the System.Windows.Forms.Application class, an error may occur. The relevant members of the System.Windows.Forms.Application class include:
 * CommonAppDataRegistry
 * CompanyName
 * ProductName
 * ProductVersion
 * UserAppDataRegistry

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.



CAUSE
The .NET Framework assemblies that deploy from an intranet are typically granted the default Intranet Permissions set. The error occurs when the assembly is run from Internet Explorer. Internet Explorer does not have sufficient permissions to access the methods. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

311301 INFO: How Internet Explorer Determines Permissions for .NET Framework Assemblies



WORKAROUND
To work around this problem, do not run the PE in Internet Explorer. You must redirect to a Web page that prompts you to download the PE. After you download the PE, you can run the PE from the command prompt.

- or -

You can ignore the error message that you receive. Move to the Temporary Internet Files directory and then copy the PE to a local folder. Run the PE from the command prompt. You can typically find temporary Internet files at the following location:

C:\Documents and Settings\UserName\Local Settings\Temporary Internet Files



STATUS
This behavior is by design.



Steps to Reproduce the Problem
 Run Visual Studio .NET. Create a new console application that is named NullReferenceDemo.

You can use either Visual Basic .NET or Visual C# .NET. In Solution Explorer, right-click NullReferenceDemo and then click Add Reference. Click to select System.Windows.Forms.dll. Click Select and then click OK.

This adds the reference to the project.  Replace the existing code with the following code:

Visual Basic .NET Code Module Module1

Sub Main Console.WriteLine(System.Windows.Forms.Application.ProductVersion) End Sub

End Module Visual C# .NET Code using System;

namespace NullReferenceDemo {  class Class1 {     [STAThread] static void Main(string[] args) {        Console.WriteLine(System.Windows.Forms.Application.ProductVersion); }  } } </li> On the Build menu, select Build Solution.</li> Copy the NullReferenceDemo.exe file that you created in step 6 to the root folder of your Web server.</li> Run Internet Explorer. Type the following URL in the Address Bar:

http://WebServer/NullReferenceDemo.exe

Note Replace WebServer with the name of your Web server.</li> Click Go.</li></ol>

<div class="references_section">