I have two identical classes with different properties and in different libraries. I reference these two libraries in my project and when I try to access properties of second library I get error "Cannot resolve symbol". If one of classes Settings are renamed to something else everything works fine. It seems that compiler search for properties in first class and ignore the second class with the same name. I tried to decorate class with partial attribute to merge class into one but it seems this works only when classes are in the same library. Any suggestion?
Lib1.dll
namespace caLibServer
{
public partial class Settings
{
public static string MyProperty1
//skip code
}
}
Lib2.dll
namespace caLibClient
{
public partial class Settings
{
public static string MyProperty2
//skip code
}
}
You need to use the namespace to access the second one:
caLibClient.Settings.MyProperty2
The partial keyword you are using is useless, because these are two distinct classes that just happen to have the same name. They are not related.
If you want to have one class having all the properties instead of two distinct classes you could use inheritance to do so.
eg.
namespace caLibServer
{
public class Settings
{
public virtual static string MyProperty1
//skip code
}
}
namespace caLibClient
{
public class Settings : caLibServer.Settings
{
public static string MyProperty2
//skip code
}
}
And now you can have:
using caLibClient;
Settings.MyProperty1;
Settings.MyProperty2;
Otherwise you can use the full path to the class to specify which one you mean.
eg.
caLibServer.Settings.MyProperty1;
caLibClient.Settings.MyProperty2;
It depends on what you are trying to accomplish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With