I have two projects in Microsoft Visual Studio 2008, but I can't access the objects/namespace from one with the other.

here is an example from my GCController project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; 

namespace GCController
{
    [Guid("9949f4f1-92e6-4709-85a8-12c816b6ceb4")]
    public interface IGCController
    {
         // ... //
    }
}

I try to access it using:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GC7890ConsoleAplication
{
    class Program
    {
        static void Main(string[] args)
        {
	    GCController.IGCController c;
        }
    }
}

but I get "type or namespace "GCController" could not be found"

Can anyone help?

Thanks

Recommended Answers

All 4 Replies

Sometimes the obvious answers are the ones we overlook. Since I can't see your solution, did you include both of your projects in your current solution? The compiler will not know where to look unless both are listed in the current solution.

TimApe


I have two projects in Microsoft Visual Studio 2008, but I can't access the objects/namespace from one with the other.

here is an example from my GCController project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; 

namespace GCController
{
    [Guid("9949f4f1-92e6-4709-85a8-12c816b6ceb4")]
    public interface IGCController
    {
         // ... //
    }
}

I try to access it using:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GC7890ConsoleAplication
{
    class Program
    {
        static void Main(string[] args)
        {
	    GCController.IGCController c;
        }
    }
}

but I get "type or namespace "GCController" could not be found"

Can anyone help?

Thanks

Take a look at this example, how you access to some other namespace:

namespace Maj16Test1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            NewNameSpace.NewClass class1 = new NewNameSpace.NewClass();
            class1.NewMethod();
        }
    }
}

namespace NewNameSpace
{
    public class NewClass
    {
        public NewClass()
        {
            MessageBox.Show("Message in the new namespace`s constructor is showing.");
        }

        public void NewMethod()
        {
            MessageBox.Show("Message in the new namespace`s method is showing.");
        }
    }
}

Explanation to your problem:
You should add reference from Project1 to Project2 to be able to write using namespace MainProject.Project2; To add reference, from Project1 solution explorer references->add reference->browse to locate the project2 assembly or projects tab to get all assembles in all solution including project2 assembly.

Take a look at this example, how you access to some other namespace:

namespace Maj16Test1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            NewNameSpace.NewClass class1 = new NewNameSpace.NewClass();
            class1.NewMethod();
        }
    }
}

namespace NewNameSpace
{
    public class NewClass
    {
        public NewClass()
        {
            MessageBox.Show("Message in the new namespace`s constructor is showing.");
        }

        public void NewMethod()
        {
            MessageBox.Show("Message in the new namespace`s method is showing.");
        }
    }
}

Explanation to your problem:
You should add reference from Project1 to Project2 to be able to write using namespace MainProject.Project2; To add reference, from Project1 solution explorer references->add reference->browse to locate the project2 assembly or projects tab to get all assembles in all solution including project2 assembly.

Thanks, that's exactly what I needed to do!

You are welcome! :)
bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.