M
Michael Lang
This occurs with both Visual Studio 2002 and 2003, framework versions 1.0
and 1.1 respectively.
I have a DLL containing a class such as:
============== CODE ===================
namespace MiddleDLL
{
public class MyClass
{
private OtherDLL.SupportClass _cls;
public MyClass(string name)
{
_cls = new OtherDLL.SupportClass();
}
internal MyClass(OtherDLL.SupportClass cls)
{
_cls = cls;
}
... class utility code here ...
}
}
============== End CODE ================
.... where OtherDLL.SupportClass is defined in a separate DLL referenced by
the DLL containing MyClass (Lets refer to that as "MiddleDLL").
In a 3rd DLL (refer to it as "FinalDLL") I referencing only MiddleDLL, and
not OtherDLL, in which contains the following code:
============== CODE ===================
namespace FinalDLL
{
// used by NUnit for testing...
public void SomeFunc()
{
MiddleDLL.MyClass inst = new MiddleDLL.MyClass("someName");
inst.SomeMethod();
}
}
============== End CODE ================
Am I doing something wrong at this point? Besides my naming convention....
The error I get during compilation of FinalDLL is:
"error CS0012: The type 'OtherDLL.SupportClass' is defined in an assembly
that is not referenced. You must add a reference to assembly
'OtherDLL.Interop'."
No public methods or properties contain any types contained in OtherDLL.
Only internal members reference types in OtherDLL. So why would the
FinalDLL require a reference to OtherDLL? I have not tried this in an
instance where OtherDLL was not a COM interop DLL. Would that make a
difference?
If I do not use the constructor, I am still able to use a class instance
without OtherDLL referenced. This is why I'm guessing it is a bug in the
compiler.
============== CODE ===================
namespace FinalDLL
{
// used by NUnit for testing...
public void SomeFunc(MiddleDLL.MyClass inst)
{
inst.SomeMethod(); //this compiles fine.
}
}
============== End CODE ================
Also, if I make the following changes it will compile and run properly:
============== CODE ===================
namespace MiddleDLL
{
public class MyClass
{
private OtherDLL.SupportClass _cls;
public static MyClass Create(string name)
{
return new MyClass(name);
}
public MyClass(string name){...} //unchanged
internal MyClass(OtherDLL.SupportClass cls){...} //unchanged
... class utility code here ...
}
.... next namespace (FinalDLL) in separate dll...
}
namespace FinalDLL
{
// used by NUnit for testing...
public void SomeFunc()
{
MiddleDLL.MyClass inst = new MiddleDLL.MyClass("someName");
inst.SomeMethod();
}
}
============== End CODE ================
So, is this a bug? or do I need to change how I structure code? If it is
wrong, then why? Creating a static method for all the public constructors
just seems wrong!
If anyone confirms this sounds like a bug, then I'll report it to MS. If
you see this MS personnel, please let me know If you are submitting it as a
bug for me.
Michael Lang
and 1.1 respectively.
I have a DLL containing a class such as:
============== CODE ===================
namespace MiddleDLL
{
public class MyClass
{
private OtherDLL.SupportClass _cls;
public MyClass(string name)
{
_cls = new OtherDLL.SupportClass();
}
internal MyClass(OtherDLL.SupportClass cls)
{
_cls = cls;
}
... class utility code here ...
}
}
============== End CODE ================
.... where OtherDLL.SupportClass is defined in a separate DLL referenced by
the DLL containing MyClass (Lets refer to that as "MiddleDLL").
In a 3rd DLL (refer to it as "FinalDLL") I referencing only MiddleDLL, and
not OtherDLL, in which contains the following code:
============== CODE ===================
namespace FinalDLL
{
// used by NUnit for testing...
public void SomeFunc()
{
MiddleDLL.MyClass inst = new MiddleDLL.MyClass("someName");
inst.SomeMethod();
}
}
============== End CODE ================
Am I doing something wrong at this point? Besides my naming convention....
The error I get during compilation of FinalDLL is:
"error CS0012: The type 'OtherDLL.SupportClass' is defined in an assembly
that is not referenced. You must add a reference to assembly
'OtherDLL.Interop'."
No public methods or properties contain any types contained in OtherDLL.
Only internal members reference types in OtherDLL. So why would the
FinalDLL require a reference to OtherDLL? I have not tried this in an
instance where OtherDLL was not a COM interop DLL. Would that make a
difference?
If I do not use the constructor, I am still able to use a class instance
without OtherDLL referenced. This is why I'm guessing it is a bug in the
compiler.
============== CODE ===================
namespace FinalDLL
{
// used by NUnit for testing...
public void SomeFunc(MiddleDLL.MyClass inst)
{
inst.SomeMethod(); //this compiles fine.
}
}
============== End CODE ================
Also, if I make the following changes it will compile and run properly:
============== CODE ===================
namespace MiddleDLL
{
public class MyClass
{
private OtherDLL.SupportClass _cls;
public static MyClass Create(string name)
{
return new MyClass(name);
}
public MyClass(string name){...} //unchanged
internal MyClass(OtherDLL.SupportClass cls){...} //unchanged
... class utility code here ...
}
.... next namespace (FinalDLL) in separate dll...
}
namespace FinalDLL
{
// used by NUnit for testing...
public void SomeFunc()
{
MiddleDLL.MyClass inst = new MiddleDLL.MyClass("someName");
inst.SomeMethod();
}
}
============== End CODE ================
So, is this a bug? or do I need to change how I structure code? If it is
wrong, then why? Creating a static method for all the public constructors
just seems wrong!
If anyone confirms this sounds like a bug, then I'll report it to MS. If
you see this MS personnel, please let me know If you are submitting it as a
bug for me.
Michael Lang