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.

You receive a "Compiler Error Message: CS1595" error message when you use the Src attribute in an ASP.NET application


View products that this article applies to.

Symptoms

When you compile your Microsoft ASP.NET application in Microsoft Visual Studio .NET and then you try to apply the Compile on Demand approach by using the Src attribute to reference the code-behind class file, you receive the following compiler error message when you view the Web page in the ASP.NET application in your Web browser:

Compiler Error Message: CS1595: 'MyWebApp.WebForm1' is defined in multiple places; using definition from '%windir%:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\mywebapp\877759ce\3fb79741\assembly\dl2\6a29f2d8\00f82a8d_5c32c401\MyWebApp.DLL'
Note MyWebApp is a placeholder for the name of your project.

↑ Back to the top


Cause

When you compile your ASP.NET application by using Visual Studio .NET, the code-behind file is compiled and the MyWebApp .dll file is created in the Bin folder. However, when you use the Src attribute, the code-behind file is again compiled on demand or Just In Time (JIT)-compiled. This behavior creates two assemblies with the same type definition. Therefore, you receive the compiler error message that is mentioned in the "Symptoms" section.

↑ Back to the top


Resolution

To resolve this problem, you must delete the Global.asax file and the MyWebApp.dll file from your project, and then open the page in Microsoft Internet Explorer. To do this, follow these steps:
  1. In Visual Studio .NET, click Show All Files on the Project menu.
  2. In Solution Explorer, expand bin. Right-click MyWebApp.dll, and then click Delete.
  3. In the Microsoft Development Environment dialog box, click OK.
  4. In Solution Explorer, right-click Global.asax, and then click Delete.
  5. In the Microsoft Development Environment dialog box, click OK.
  6. On the File menu, click Save All to save the Web Form and other associated project files.
  7. Start Internet Explorer.
  8. In the Address box, type http://yourservername/MyWebApp/WebForm1.aspx, and then press ENTER. The WebForm1.aspx page opens.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

Steps to reproduce the behavior

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
  3. Under Project Types, click Visual C# Projects, and under Templates, click ASP.NET Web Application.
  4. In the Location box, type http://YourServerName/MyWebApp, and then click OK. By default, a form that is named WebForm1 form is created.
  5. Add a Literal control to the WebForm1 form.
  6. In Solution Explorer, right-click WebForm1.aspx, and then click View Code.
  7. Add the following code to the Page_Load procedure:
    Literal1.Text = "This is a test page";
  8. On the Build menu, click Build Solution.
  9. On the Debug menu, click Start. The WebForm1.aspx page appears.
  10. Close the WebForm1.aspx page.
  11. In Solution Explorer, right-click WebForm1.aspx, and then click View Designer.
  12. Switch to the HTML view of the WebForm1 form.
  13. In the HTML view of the WebForm1 form, locate the following code:
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="MyWebApp.WebForm1" %>
  14. Replace the code that was located in step 13 with the following code:
    <%@ Page language="c#" Src="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="MyWebApp.WebForm1" %>
  15. On the Build menu, click Build Solution.
  16. On the Debug menu, click Start. You receive the error that is mentioned in the "Symptoms" section.

↑ Back to the top


References

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

↑ Back to the top


Keywords: kberrmsg, kbdll, kbcompiler, kbwebforms, kbwebbrowser, kbprb, KB833268

↑ Back to the top

Article Info
Article ID : 833268
Revision : 6
Created on : 4/29/2007
Published on : 4/29/2007
Exists online : False
Views : 404