Namespace problem

Hi,

This looks very simple, but somehow Iam not able to solve it. Take a look at the code.

1) File MyAssembly.cs

namespace MyNamespace
{
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method,AllowMultiple=true,Inherited=false)]
public class MyAttribute : Attribute
{
......................
}
}
Now it is compiled into a .dll file MyAssembly.dll

2) File OtherAssembly.cs

namespace MyNamespace
{
[MyAssembly.MyAttribute("some value")]
public class Application
{
..................
}
}

Now, upon compiling OtherAssembly.cs, it complains that it cannot find neither the namesapce MyNamespace nor the class MyAttribute. I have tried the options - using MyNamespace; and using MyNamespace.MyAssembly. But it still doesn't work.

What went wrong with my code Please explain.

Thank you.


Answer this question

Namespace problem

  • Jeps


    Hi Johnson,
    Thanks for the reply. I didn't add a reference to MyAssembly.dll. That was the reason. After referencing this .dll file, we can use all the classes in that Assembly isn't I gave the code of what I have written. So the fully qualified name is MyNamespace.MyAttribue.

    One more thing, it is not necessary that the directory hierarchy should reflect the namespace hierarchy isn't It is compulsory in Java.

    Thank you.


  • Dariusdm

    I'm assuming that you've added a reference to MyAssembly.dll to the project containing OtherAssembly.cs

    I don't think that MyAssembly.MyAttribute is the correct reference. There typically isn't a reason to include an assembly name unless you're specifying the full name for a type.

    What you might want to do is to use the Object Browser on MyAssembly.dll from within the OtherAssembly project to see what the fully qualified name of MyAttribute is.



  • Namespace problem