2

I have two same project in which I have two classes under same namespace in one project. In the second project I have added reference to that project and have specified using statement in second project to use namespace (classes under that) of first project.

The problem is it allows me to use 1 class but doesn't allow me to use second class.

?????Why????

Here's the code:

Project 1

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

namespace LibraryProject
{
    public class test
    {
        public static string ErrorMessage = "";


        public test(string code)
        {
           ErrorMessage = code;

        } 


    }

    public class FirstClass
    {
        public static string ErrorMessage = "";

        public RFIDHW(string code)
        {
            ErrorMessage = code;

        }

    }
}

Second Project

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

using LibraryProject;

namespace Engine
{
    /*
     * Connect engine logic with back end DB and other library
     */
    public class BackEnd
    {

        //Return tag list from the connected reader as List<Tag>
        public string GetMessage()
        {
            FirstClass fc = new FirstClass();  //OK no problem

            test tt = new test(); // Error message

        }//End of GatTagList method

    }//End of BackEnd class
}//End of namespace

Error message that I am getting is

The type or namespace name "test" could not found (are you missing a using directive or an assembly reference?).

I have added reference to second project in first project.

I have tried same mechanism in new solution just by taking that piece of code and it worked. (unfortunately I can't move by whole project so have to fix this.)

Please help

Thanks a lot in advance

6 Answers 6

6

Not that I'm certain this is the cause of the error, but the first thing I notice is that your test constructor asks for a parameter:

    public test(string code)
    {
       ErrorMessage = code;

    } 

But you are calling the default (parameterless) constructor here:

test tt = new test();

That wouldn't work, because you created a constructor so the default constructor is no longer available. You need to pass in some string so that your declared constructor (test(string)) gets called.

Sign up to request clarification or add additional context in comments.

4 Comments

@leppie: That class only has a method called RFIDHW(). Doesn't define its own constructor.
@leppie: Grats on passing 30k by the way ;)
@BoltClock: Thanks, it felt like I was stuck for ages :)
Thanks, this was the one of the mistake (typo), but that didn't fix the issue.
2

Try building each assembly separately, sometimes there are build errors that are not shown on a build all command because of the build order.

You should also set the build order so the first project is always built before the second.

1 Comment

Thanks, It was the order in which it was building each assembly. I had different projects in my solution and it was compiling second project first (as per above code) and then first project and therefore when it tries to compile second project it won't find "FirstClass" as its not compiled/build yet. Thanks again, fix the issue Sorry, not able to vote your answer - don't have enough reputation.
1

You say: "I have added reference to second project in first project.", but it should be the other way around. You need to add a reference to the first project in the second project since you are using a class from the first project in the second project.

1 Comment

Thanks, sorry that was my mistake, I have actually added reference to LibraryProject into Engine project where I am using class from LibraryProject.
1

Cannot reproduce the compiler error you got, but a few other compile-time problems:

  1. class test has no parameterless constructor.
  2. method RFIDHW in FirstClass has no return type specified. if it is supposed to be a constructor then you forgot to rename it.

To get that error you got you'd have misreferenced somehow. Recheck that your Second assembly has refence to the first assembly (not vice versa as described in OP).

1 Comment

Thanks, sorry, it is a constructor. I jut forgot to rename it to FirstClass when copy code from actual project (which has name RFIDHW) excluding all these typos, main thing worries me is that, same piece of code works if I copy it into a new project.
0

I dont see any problem using this code, except RFIDHW() and parameters. Once you rectify this, you should be able to run it. If it does not, check your application if your Namespaces are conflicting typename, or if any library you are using has conflict with your class.

1 Comment

Thanks, I can't see any such conflict between typename.I have only one RFIDHW class inside RFIDHardWare namespace and I am getting same error even if I use full reference name RFIDHardWare.RFIDHW
0

I had a similar problem with a class that VS17 couldn't find (error was reference or assembly missing), and it was in the same namespace as the other class.

My problem, I think, was because i pulled some changes from GIT, cause I work on 2 different places. I had moved the "missing" File.cs to another folder and through .gitignore the VS17 didn't get the information that sth. changed.

The (not so great) solution was to create a new class with command ctrl + ., and after that VS17 will find both of your classes, then delete the unwanted one..

Hope no one will encounter that problem...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.