C# using <myowndll>, doesn't work (VS10 Express) - c#

Background: I am a novice in C#, and use Visual Studios 2010 Express.
I have a class (let's call it myclass) which I want to use in multiple projects. I used to add classes with Project->Add Existing Item... Which creates a copy of myclass.cs.
Now I just found out that when I build the original myclass.cs it creates a myclass.dll and places it in the release folder of my project.
But when I try to use this DLL, I get the following error:
The type or namespace name 'myclass' could not be found(are you
missing a using directive or an assembly refference?
Which is weird to me, because I already have referenced it (it is also in the Reference folder of my Solution Explorer). And I already have added this to my code:
using myclass;
So what am I doing wrong?
Update: When I tried my old method (add existing item -> myclass.cs) the error message goes away. So it's not a matter of spelling things correctly.

Add the dll first:
Click on references in your project-explorer in visual studio and add your dll then you can use it as you expected it.

Add the reference in your project and check that the target Framework version of that assembly fits the project.
Check the namespaces inside the assembly and then use them like:
using YourAssemblyNamespace.class

Okay so I found the answer myself. It turns out that when you use the using function, it automatically searches for all public classes in the namespace you want to use.
If it can't find a public class, it refuses to recognize the DLL.
Furthermore, not specifying a class makes it internal.
So:
class myclass // internal!
private class myclass // private!
public class myclass // only this makes it visible for others!
Everything was okay after changing class myclass into public class myclass.

Related

The Type does not Exist in the namespace. Are you missing an Assembly?

I have 2 C# projects first one name is "Advocar" and the second one is "Import".
There is a class in Advocar project which we need to access to that from Import project. So in Import project I added reference to Advocar.
The problem is from Import project I recognizes all the Advocar classes except the new class that I just created in the Advocar. and when I build it, it say "The Type or namespace does not exist in the Advocar.Data.Inventory namespace. Are you missing an assembly?", but the class is exist in that namespace.
I build Advocar project and re-add the assembly to the Import project and it did not help. Both project are in .NET 2.0.
Any Idea please?
Check the access level of new class added into the namespace.
Ok. I found the solution although I dont know what would cause that.
since 40% of all the classes that I have are the same code, so to create a new class I just copied and pasted one of the existing class and made changes on that one.
So to solve my issue, I deleted the new classes and I just Add New Item and create a blank class and past the code that I needed to the new class and it fixed that.
Its look like some kind of caching issue that although you rename a class and so on, but it still has some record from past.

VisualStudio.Net reference not working

I create a new solution called "WordpressAutomation"
I create a new project, a class library, called "WordpressAutomation" in this solution
I create a new project, a unit test project, called WordpressTests in this solution
I add a reference to the project WordpressAutomation in the project WordpressTests"
This should be ok, shouldn't it?
However, as can be seen from the screenshot, when adding this using line in a class in the project WordpressTests,
the reference doesn't work. Even though it is there, as can plainly be seen.
When entering "using", the class library "WordpressAutomation" doesn't appear among the alternatives.
And I get this error message when trying to run:
"The type or namespace "WordpressAutomation" could not be found (are you missing a using directive or an assembly reference?)"
Why is this happening? The reference is clearly there?
http://i.stack.imgur.com/L0g5R.png
Your project isn't actually including the .cs files to compile; they are only shown for information (they should appear as solid files with the C# logo):
Right click on these files and include them in the project. Then check what namespace they declare inside them. At the moment, your WordpressAutomation project simply doesn't contain any types.

Referenced class lib doesn't seem

I have a class lib and I referenced it to another windows project. I added its namespace to my Form.cs (using SaglikNetClassLib;). they are seem unknown when I want to access to classes. I can see their properties and methods. But the complier says "Error 7 The type or namespace name 'SaglikNetClassLib' could not be found (are you missing a using directive or an assembly reference?), Do you have any suggestion?
KR,
Çağın
Are you targeting the .net Client Framework? Visual Studio let's you add references to incompatible assemblies, but then gives exactly that error.
Check your project settings to make sure you're targeting the full .net framework.
Also, check that the Ilalcar class is public and not internal (which is the default if it's only declared as class without any modifier)
You probably need an using statement to put the class into scope.
using SaglikNetClassLib;
C# won't auto suggest it if the project has not been rebuild. Also make sure the class library project has been build before using it in code.
Intellisense seems to lag behind a bit at times. Simply pressing f5 (run) sometimes rebuilds the project completely and simply runs or gives a better error message.

C# asp.net - The type or namespace name 'Helper' could not be found (are you missing a using directive or an assembly reference?)

I'm reworking someone else's code, where they had a helper class with way to much code that shouldn't be there (data access, business logic, everything had slowly been shoved in there).
I've moved the relevant code into the appropriate pre-existing classes and created a separate, brand new helper class in the appropriate project, but all my references to this class simply don't work.
Here's a simple view of how my class looks (names slightly changed);
namespace Company.Web.Application.Reporting
{
public class ReportHelper
{
here I have a bunch of methods
}
}
and here is how it is being referenced;
using Company.Web.Application.Reporting;
namespace Company.Web.Application.App.Reports
{
public partial class PlansReports : PageBase
{
//This is the problem part
private ReportHelper Helper = new ReportHelper();
heaps of other code with no problems here...
}
}
My problem is that the I get the following error, everywhere that I try to access my new helper.
The type or namespace name
'ReportHelper' could not be found (are
you missing a using directive or an
assembly reference?)
All my using statements are there, I have the appropriate references in each relevant project, yet this still persists.
At this point I am totally stuck, I just need to get this referencing issue sorted out so I can ensure all my helper methods work correctly.
Any help is greatly appreciated,
Pat.
OK, I found the problem (actually a colleague did)
This original Helper class was contained in the app_code folder of my main project, which as I have just learned, handles compiling differently to all other folders in a project.
Code in here is compiled at run time, rather than during the build.
When I created my new classes, they were in the app_code folder because I used code rush to extract the class to a new file, which kept it in the same location...after which I moved them to their "sensible" location.
Unfortunately they still had the build action of "Content" inherited from their previous presence in the app_code folder.
So, on the new class file, I simply changed its build action to "Compile" and now all is well with the world.
Cheers,
Pat.
Is your ReportHelper in a separate project or DLL? If so have you added this project/dll as a reference? (In your solution explorer under References, check your project/dll is there.
Have you built Company.Web.Application.Reporting so that the type would be known? That would be my idea along with ensuring that the dependencies are set up properly.
It sounds like you know what you are doing and everything looks right, so it has to be something simple. Are you trying to access changes in ReportHelper that haven't been compiled into the dll? I would try rebuilding the reference assembly; every time you make changes to that assembly, it needs to be rebuilt.
Also verify you are adding the correct assembly (e.g. Debug vs. Release) to your project. It doesn't matter which type, but you don't want compile new changes into the Debug dll, and keep adding the old version of the Release dll.

VS 2008 C# : Class library is not accessible in another class library in same solution

I have a solution in VS 2008 which has one web project and 3 Class libraries as 3 different Projects. One project is for DataAccess and one is for BusinessLogic.
I have a class in DataAccessLayer. From there when I am trying to access the Class of BusinessLogic class library (project) it is not coming in the IntelliSense when I type. I used the same namespace in both projects. Still same results.
Do I need to to create DLLs for the first project and add as reference to second?
You need to add reference to this project in another project in your soultion.
Visual studio has an option to add project as a reference, so you don't have to add assembly files directly
You need to reference the library in the other projects.
To do that, right-click the references folder in the Solution Explorer, click Add Reference, go to the Projects tab, and select the library that you want to reference.
EDIT: Also, make sure that the class you are trying to use is declared as public (eg, public class MyClass).
If you leave out the public modifier (which is the default), the class will only be usable in its project. To expose classes and members to other projects, add the public modifier to their declaration
You'll need to add a reference to the project containing the BusinessLogic class in the DataAccess project. Otherwise, the compiler doesn't have anyway of finding the implementation of your BusinessLogic class, even if it does use the same namespace.
This may sound silly, but have you specified the class in question as Public or Friend? They'll need to be "shared" in that sense in order to be properly picked up and used within the other applications, even when the project reference is specified.

Categories

Resources