You have to add a reference of the project you want to access to (right click on References in solution explorer, then select Add Reference, then select Browse tab and look for appropriate file in the project you want to access).
Then Add this reference on the top on the class you want to access from (using YourProjectname).
Then you should see the pulbic members of the class you access.
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
vshost file (in program/bin/debug)
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
This is what you have to do exactly:
1.
The first step is to make P2 reference P1 by doing the following:
Right Click on the project and select "Add Reference";
Go to the Projects Tab (or Browse Tab);
Look for P1, Select it and hit OK;
2.
Next you'll need to make sure that the classes in P1 are accessible to P2. The easiest way is to make them public:
public class MyType { ... }
3.
Now you should be able to use them in P2 via their fully qualified name.
Assuming the namespace of P1 is Project1 then the following would work:
Project1.MyType obj = new Project1.MyType();
4.
The preferred way though is to add a using for Project1 so you can use the types without qualification:
using Project1;
...
public void Example()
{
MyType obj = new MyType();
}
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
You can only reference in one way otherwise you get the error like you said. Just do this: delete the reference from your DAL to your BL and make a new one from your BL to your DAL!
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
I'm sorry I'm still a beginner at this. What are "DAL" and "BL?"
never mind, do it this way:
//assembly 1:
namespace Mar14_Part1
{
class Program
{
static void Main(string[] args)
{
}
}
public class MyClass
{
public string MyMethod()
{
return " some text from other assembly";
}
}
}
//assembly 2:
//add reference of assemby1 like I told you on top
then do:
using Mar14_Part1;
namespace Mar14_Part2
{
class Program
{
static void Main(string[] args)
{
MyClass mc = new MyClass();
string str = mc.MyMethod();
Console.WriteLine(str);
Console.ReadLine();
}
}
}
Mine example works!
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Question Answered as of 1 Year Ago by
Mitja Bonca