Microsoft Knowledge Base Email Alertz

(833268) - Explains the Compiler Error Message: CS1595 error message that you receive when you view a Web page in a precompiled ASP.NET application that uses a Src attribute to reference the code-behind files.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 833268 - Last Review: April 29, 2007 - Revision: 1.5

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

On This Page

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.

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.

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.

STATUS

This behavior is by design.

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.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:
@ Page
http://msdn2.microsoft.com/en-us/library/ydy4x04a(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/ydy4x04a(vs.71).aspx)


APPLIES TO
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
Keywords: 
kberrmsg kbdll kbcompiler kbwebforms kbwebbrowser kbprb KB833268
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Ian Gooding - iang NOSPAM-AT-NOSPAM scriptureunion.org.uk Reported as Irrelevant  
Written: 5/28/2004 4:29 AM
I've been searching for this solution for two weeks now - and worked it out yesterday. It's nice to have it confirmed though.

Bala Report As Irrelevant  
Written: 10/23/2004 12:58 AM
I am a newbie to ASP.NET programming. I got this error and search in support.microsoft.com provided some explanation that was not easy to follow. Even when I followed all those steps, I still got other errors. This solution solved my issue and it is easy to follow. Thanks Scott. You are very helpful.

Geoff Bennett Report As Irrelevant  
Written: 11/25/2004 8:03 PM
This can also happen if you have renamed your output assembly after already deploying it. Because it doesn't overwrite the other assembly, ASP.NET will find two versions of each class and won't know which one to reference. Check your bin folder in your deployed project and delete the old assembly.

Alex Szeremeta - alexszeremeta NOSPAM-AT-NOSPAM hotmail.com Report As Irrelevant  
Written: 3/4/2005 6:13 AM
Scott Cate, Sir. You are a genius, thank you for putting up a simple solution, (to what now seems like) a simple problem. The problem with Microsoft? they go on and on and on, when a simple solution (like this) is what most developers want to get on their feet. Again, THANK YOU.

PC Report As Irrelevant  
Written: 6/24/2005 9:43 AM
Thanks Geoff..it really worked...searching for the solution from quite a while

Jianke Report As Irrelevant  
Written: 7/20/2005 9:02 PM
Thanks a lot for ypur input. It really helped many people I believe. Why Microsoft site give us some wrong directions? ...

Newbie Report As Irrelevant  
Written: 7/29/2005 3:46 AM
The explaination you have given is excellent.As everyone have mentioned, U r simply GENIUS. Thanx a lot.

Snake - snake_unknown NOSPAM-AT-NOSPAM yahoo.com Report As Irrelevant  
Written: 11/26/2005 5:14 AM
hey guys, this could be appear when you're using NTFS file system and you'd removed 'everyone' access permission... cool Microsoft!

Anupam - anupam NOSPAM-AT-NOSPAM hotmail.com Report As Irrelevant  
Written: 11/28/2005 12:01 AM
Thanks For this help,

muthkats - amkumaran NOSPAM-AT-NOSPAM rediffmail.com Report As Irrelevant  
Written: 1/11/2006 1:04 AM
good solution. reproducing the error was much great

PsychoButtzi Report As Irrelevant  
Written: 2/17/2006 10:16 PM
Thnx 4 da advice.......It was a gr8 relife 4 me.....Thnx a lot.........

Avanika Report As Irrelevant  
Written: 12/7/2006 3:23 AM
Thanks for such an easy solution to the problem which was appearing very big..

kumar - kumaramca.007 NOSPAM-AT-NOSPAM gmail.com Report As Irrelevant  
Written: 6/7/2008 12:05 AM
A local variable named 'objSA' is already defined in this scope