Microsoft KB Archive/318274

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

Article ID: 318274

Article Last Modified on 4/19/2007

-

APPLIES TO


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

-



This article was previously published under Q318274



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.



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



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:  Open the Machine.config file, and then locate the   section.  In the   definition for C#, add the compilerOptions attribute with a value of /nostdlib. For example:  

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\. 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 &quot;List Folder/Read Data&quot; 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)



STATUS
This behavior is by design.



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.

