user1330271
user1330271

Reputation: 2691

namespace conflict

I got:

using System.Diagnostics;
using System.Reflection;

namespace Site
{
    public abstract class General
    {

        private static string _version;

        public static string Version { get { return _version; } }

        static General()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
            _version = fileVersionInfo.ProductVersion;
        }

    }
}

The code works fine and I can get the version anywhere I need accessing Site.General.Version. Now I'm trying to use the inline tag <% = Site.General.Version %> but I'm getting a error message saying System.ComponentModel.ISite does not contain a definition or 'General'.... I think there's a namespace conflict because of the interface ISite.

How can I solve this?

Upvotes: 0

Views: 273

Answers (2)

Claudio Redi
Claudio Redi

Reputation: 68400

Try adding this to the top of your aspx

 <%@ Import Namespace="Site" %> 

And change your code like this

 <%= General.Version %>

EDIT

This is the syntax to do it for all pages on web.config

<system.web>
      <pages>
           <namespaces>
                <add namespace="Site" />
           </namespaces>
      </pages>
</system.web>

Upvotes: 3

Erick T
Erick T

Reputation: 7429

I would highly recommend changing the name of either the namespace or the class. You can sometimes get it to work, but this will come back and bite you. And the compiler errors are very unhelpful, which is especially bad as this bites you on refactoring, which are often done a different time than when the code was written. I speak from experience - bad idea.

Upvotes: 4

Related Questions