Welcome to ASP.NET Guild

Be sure to come back often and tell others. If you have any tips, tricks, examples, please email them to me at chris.williams@techguilds.com and I will post them. Check out our ASP.NET QuickStart and C# QuckStart Libraries. Below is my latest articles.

Friday, June 30, 2006

Multiple pages accessing the same codebehind file in ASP.NET 2.0

In ASP.NET 1.1 you may have had multiple pages access the same codebehind page, but in ASP.NET 2.0 you get the following ugly message when you try to publish

The type 'xxxx' exists in both '...\v2.0.50727\Temporary\....xxx.dll' and '...\v2.0.50727\Temporary\...yyy.dll'

Rick Strahl's solution to this problem is to do a page reference instead of pointing both to the same source file. Eg. <%@ Reference Page="~/UploadItemPicture.aspx" %>

You can check out the full solution at:

http://odetocode.com/Blogs/scott/archive/2005/09/12/2186.aspx or

Please note that there are other causes of this error message, such as conflicting object names in the same namespace.

This error occurs, if you have declared a class twice in your application (in a referenced assembly, somewhere in your app_code directory, or anywhere else in your app).
In my case I had a prior
compiled version (a dll) of the web app itself in the bin directory, which is
not allowed any more. -> delete all compiled versions of all web applications
(the app itself and referenced web apps) from the bin directory !!If you have to
have the same
classname multiple times within your application (e.g a class
within each module subfolder in the app_code directory, you
could do the
following:1) Give each class a different namespace (e.g.
MODULENAME.DataAccess)2) Mark the classes as partial classes (!! this does not
work if the partial classes are spread accross different subfolders of the
app_code dir which are marked as codeSubDirectory in the web.config. The reason
is, that in this case, each subfolder results in a different assembly and
partial classes over multiple assemblies are not allowed. Also see my blog
for creating multiple assemblies from the app_code directory
Check out the full posting at http://www.cubido.net/Blog/tabid/176/EntryID/49/Default.aspx

If you have any tips you would like to share please email them to me at chrisw_88@hotmail.com

Be one of the first to try Windows Live Mail. Windows Live Mail.

Are you a .NET Developer or Contractor interested in working with Sitecore or Dynamics CRM?

Apply for our Mentorship Program. If accepted, we will mentor you on Sitecore and provide you with project to help you build your skills and make some money at the same time. If you are interested send your resume with details on why you want to work with Sitecore or Dynamics CRM to: Chris Williams - chris.williams@techguilds.com or Dennis Augustine - dennis.augustine@techguilds.com We look forward to working with you to achieve your goals.