Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Error message when you use the C# compiler to compile an ASP.NET resource: "Compiler Error Message: CS1595"


View products that this article applies to.

Symptoms

When you use the C# compiler (Csc.exe) to compile an ASP.NET resource, you may receive a compiler error message that is similar to one of the following error messages:
Message 1
Compiler Error Message: CS1595: 'System.Collections.ArrayList' is defined in multiple places; using definition from 'c:\winnt\microsoft.net\framework\v1.0.3705\mscorlib.dll'
Message 2
Compiler Error Message: CS1595: 'System.Runtime.CompilerServices.CompilerGlobalScopeAttribute' is defined in multiple places; using definition from 'c:\windows\microsoft.net\framework\v1.0.3705\mscorlib.dll'
This issue may occur when you try to run a Visual C# .NET Web application for the first time or when you run a Microsoft Visual Basic .NET or Visual C# .NET Web service.

↑ Back to the top


Cause

This issue occurs because the C# compiler does not have permission to access the folders in the path to the mscorlib.dll assembly.

↑ Back to the top


Resolution

To resolve this issue, use one of the following methods. (The methods are listed in the order of preference.)

Method 1

Modify the compiler definition for the C# compiler to include the /nostdlib option. The /nostdlib option prevents the import of the mscorlib.dll assembly, which defines the entire System namespace.

To include the /nostdlib option in the C# compiler definition on a computer, follow these steps:
  1. Open the Machine.config file, and then locate the <compilers> section.
  2. In the <compiler> definition for C#, add the compilerOptions attribute with a value of /nostdlib. For example:
    <compiler language="c#;cs;csharp" 
             extension=".cs" 
             type="Microsoft.CSharp.CSharpCodeProvider, System, 
             Version=1.0.3300.0, 
             Culture=neutral, 
             PublicKeyToken=b77a5c561934e089" 
             warningLevel="1" 
             compilerOptions="/nostdlib" />
    					
Note The compilerOptions attribute is not additive. If you need to override this option in a Web.config file or on a given page, you must add the /nostdlib option in addition to your customizations.

Note You cannot use this method for applications that use the XmlSerializer class or Web services because the compiler invocation that XmlSerializer uses does not inherit these options.

Method 2

Grant List permissions to the process identity that is being used to run the ASP.NET worker process for every folder in the path of the mscorlib.dll assembly. Typically, this path is %WinDir%\Microsoft.NET\Framework\Version. This is generally the root of the volume where the account does not have permissions. For example, the root may be C:\.

Note Do not use this method if the following conditions are true:
  • You use the /nostdlib option.
  • You are not using Web services.

Method 3

Grant "List Folder/Read Data" permissions to one of the following accounts:
  • The ASPNET account, or the NetworkService account for applications that run on Microsoft Internet Information Services (IIS) 6.0
  • The group that includes the ASPNET account (or NetworkService account)

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

Web services use the C# compiler to compile their proxies, regardless of whether they are written in Visual Basic .NET or Visual C# .NET. Therefore, you may receive this error message even if you are working with a Visual Basic .NET project.

Note that you can also receive similar compiler error messages if you combine the src and the codebehind attributes in a single page. However, this is considered a developer error. If you are encountering the specific issue that is described in this article, the error message always specifies the mscorlib.dll assembly.

Default access control lists on a volume grant the Everyone and the Users groups permission to read and to list files. However, sometimes these permissions are removed to provide a more secure environment. When this occurs, Csc.exe cannot cannibalize path names. Because ASP.NET does not currently provide the /nostdlib option to the compiler, the compiler contains multiple instances of assemblies. This issue does not occur when you use the Visual Basic .NET compiler (Vbc.exe) to compile resources.

↑ Back to the top


References

For more information, visit the following Microsoft Developer Network (MSDN) Web site:

↑ Back to the top


Keywords: KB318274, kbsecurity, kbprb, kblangc, kbcompiler

↑ Back to the top

Article Info
Article ID : 318274
Revision : 10
Created on : 4/19/2007
Published on : 4/19/2007
Exists online : False
Views : 604