1

I've been tackling some odd behaviour I have with my Visual Studio. I am generating pakage with simple Silo.Configuration namespace in it having two types in one file.

  1. Contents of the file:
namespace Silo.Configuration
{
    public enum ClusteringType
    {
        Local,
        Zookeeper
    }

    public class SiloConfig
    {
        public string URL { get; set; }

        public string ClusterId { get; set; }

        public string ServiceId { get; set; }

        public ClusteringType ClusteringType { get; set; }

        public int GatewayPort { get; set; }

        public int SiloPort { get; set; }
    }

}
  1. Silo.Configuration is the default namespace and assembly name for the package I create via Visual Studio with <GeneratePackageOnBuild>true</GeneratePackageOnBuild> option.

So far so good, but when I try to use this package in other project nested inside other namespace I get CS0234. Weird thing comes when I move Silo.Configuration in global namespace or add using global:: this fixes the error and type is resolved.

Question is what is this behaviour and how can I fix it? Before you answer I noticed when I was able to resolve SiloConfig from the other project I wanted it to be included it was looking like that

using Silo.Configuration; // <-- notice this?

namespace Silo.Configuration
{
    public class SiloConfig
    {
        public SiloConfig();

        public string URL { get; set; }
        public string ClusterId { get; set; }
        public string ServiceId { get; set; }
        public ClusteringType ClusteringType { get; set; }
        public int GatewayPort { get; set; }
        public int SiloPort { get; set; }
    }
}

What does generate this using above the SiloConfig type if the namespace is the same?

kuskmen
  • 3,648
  • 4
  • 27
  • 54

1 Answers1

0

When you use the package, you need to import the package from the local first.

Is this error CS0234 that you did not import it?

About the usefulness of global::, you can refer to this link: What is global::?, In the case of the same namespace, the code is more readable by aliasing the classes in the namespace.

Here is the example: using newname=global::Silo.Configuration; If you want to use the class with the same name in the namespace with the same name, this will cause the class in the imported package to conflict with the class in the currently used project.

The imported class has no effect, so you can only change the class name in the current project. So that both classes can be used.

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27
  • I am using it locally and I knew what global:: is used for question is why visual studi thinks it is needed if this is the only namespace and type named likeso – kuskmen Jul 06 '20 at 06:24