views:

23

answers:

2

I have defined this in the web.config of a subdirectory

<namespaces>
   <remove namespace="App"/>
   <add namespace="Tom"/>
</namespaces>

App is imported in the parent web.config file, Tom and App have classes with the same names.

To avoid errors resulting from ambiguous class names I removed the App namespace from the sub-directory where the Tom namespace is used.

However the namespace App is still imported on content pages that have a master page outside the Tom directory. This causes the aforementioned errors.

Here is my dir structure

-Root Directory 
--Default.master
--web.config (App is added in web.config)
--Tom Sub-diretory
---web.config (App is removed in web.config)
---Content page that uses Default.master (Here is the problem)
---Page without master (Works OK)

Any solutions?

A: 

Suppose you have the following in the root web.config:

<namespaces>
    <add namespace="App" />
    <add namespace="Tom" />
</namespaces>

And in your sub web.config:

<namespaces>
    <remove namespace="App" />
    <add namespace="Tom" />
</namespaces>

There will be no problem to use the class in .aspx pages in the sub-folder even if they derive from a master page in the root folder but you won't be able to use it in the master page. In the root master page you will need to fully qualify the type: <%= App.DuplicateType %> or <%= Tom.DuplicateType %>.

Darin Dimitrov
A: 

What about explicitly prefix the usages with the namespace? That should always work.

Mikael Svenson