PRB: "System.NullReferenceException" Unhandled Exception Error Occurs When You Run a .NET Portable Executable in Internet Explorer (815635)



The information in this article applies to:

  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)

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.

MORE INFORMATION

Steps to Reproduce the Problem

  1. Run Visual Studio .NET. Create a new console application that is named NullReferenceDemo.

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

    This adds the reference to the project.
  5. 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);
          }
       }
    }
  6. On the Build menu, select Build Solution.
  7. Copy the NullReferenceDemo.exe file that you created in step 6 to the root folder of your Web server.
  8. 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.
  9. Click Go.

REFERENCES

For additional information about the NullReferenceException class, visit the following Microsoft Web site:

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemNullReferenceExceptionClassTopic.asp

Modification Type:MinorLast Reviewed:5/12/2003
Keywords:kbWindowsForms kbWebServer kbConsole kbweb kbprb KB815635 kbAudDeveloper