I have two classes in separate files in a project I'm working on. Windows forms classes specifically. When I try to use one class from the .cs file, Visual Studio cannot find it. It underlines the line of code and asks if I'm missing a directive or assembly reference. I have no idea why it isn't seeing the other class, as both .cs files are in the same directory. Does anyone have any ideas as to why this would be happening and how to fix it?
Also, one of the .cs files is copied from a separate project, so I don't know if that caused a problem somehow.
Also, one of the .cs files is copied from a separate project, so I don't know if that caused a problem somehow.
You should check the namespaces involved. My guess is that the one from the other project is in a different namespace. So, if you've got:
namespace FirstNamespace
{
class Foo
{
private Bar bar = null;
}
}
and
namespace SecondNamespace
{
class Bar
{
}
}
Then in the first class you need:
using SecondNamespace;
to allow you to use Bar
without any qualification.
Or - possibly better - you could just change them so they're both in the same namespace.
Better yet, you could avoid copying anything from a different project, and instead use class libraries for code sharing.
In my case namespace was fixed but still visual studio did not recognized classes. I solve it by right click on the class file and click 'Include In Project'.
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