I Can't access my class library in a web application - c#

I have added Class Library in my web Project through Add reference option, but i am facing an error
Error 2 The type or namespace name 'UserDetailsDll' could not be
found (are you missing a using directive or an assembly reference?)*
I hope some one will help me.
Thanks in Advance.

There are a few possibilities as to why that is happening:
You're missing a using statement. Try using the whole name of the class (namespace, then class name) you're trying to use.
Your DLL is targeting a different processor architecture. Check the properties of your web application and your DLL and see if they are both targeting the same CPU.
Your DLL is for a different .NET framework than your web application. Check the target framework in the project properties.
Finally, check the references in Visual Studio for a little yellow warning icon next to your referenced DLL. It's presence indicates that the DLL couldn't be found / referenced in the first place.

You need to either add a using in your code file or specify the full name to the class you want to use.
Both solutions can be autogenerated. Rightclick on the class that won't get resolved and click on Resolve -> using XXXX

Related

The type or namespace name 'X' could not be found

I have a CustomerOrderContext class in CustomerOrder.Data project in my solution. In another project, CustomerOrder.App, I have CustomerVM class. In this class I'm creating a CustomerOrderContext instance. But I get this following error:
Error 2 The type or namespace name 'CustomerOrderContext' could not
be found (are you missing a using directive or an assembly
reference?)
I have changed Build Actions of both projects to Page and then back to None and I have started to get this error. I have this line in CustomerVM:
using CustomerOrder.Data;
so I guess I shouldn't get this error. CustomerOrder.Data is also in References list of CustomerOrder.App. Can you tell me how I can fix this problem?
Thanks.
The issue is solved when I created new project, copied & pasted all classes.
be sure that CurstomerOrderContext class is marked as Public and not Internal.
Can you check if the framework versions are compatible? See https://stackoverflow.com/a/4286625/2478357.
Also, if you use Entity Framework (and CustomerOrder.Data uses EF), check if your CustomerOrder.App has a reference to the Entity framework dll. (This also applies to other imported dll's..)
you need to add Reference of that project (.dll) in your project.
You will find it when you right click your solution and add the (.dll) of other project in debug folder.
To access the class you must have same namespace
and
Check that both projects follow the same .Net Framework

ASP.Net MVC Controller cannot see another namespace

I have an MVC Controller that cannot see another namespace in the using statement.
Specifically this line of code:
using TRN.Website.Tools;
Errors with:
The type or namespace name 'Tools' does not exist in the namespace
'TRN.Website' (are you missing an assembly reference?)
Other parts of my project can see the TRN.Website.Tools namespace however.
I tried adding the namespace to web.config but this had no effect.
EDIT: Sorry all I have missed out a vital bit of information. TRN.Website.Tools is just a folder with the namespace TRN.Website.Tools in the same project. It is not a separate project or a dll.
My guess: You have multiple projects in you solution and you have multiple libraries (dlls) that their names starts with TRN.Website and you added reference to one of these dlls in your MVC project. you have to add reference to the other one too.
Solved but in a really strange way.
I added another class in the Tools folder and after that the error disappeared.
Very very odd.
Check your Build Action of your class in properties window. It must be 'Compile'.
Your ASP.NET MVC project does not contain a reference to the assembly that contains the TRN.Website.Tools namespace. You have to reference that from your ASP.NET MVC project in order to use it.
If TRN.Website.Tools is a project in your Solution, you can just add a Project reference to it.
If it isn't a project in your Solution, you'll have to add a reference to the compiled DLL to your ASP.NET MVC project.
In my case, I had not checked in the "X.csproj" file to TFS, so the new controller I created was not being found in my testing environments as a valid controller.

Can't create valid reference to class library

IMPORTANT! I was confusing myself, being in another project/assembly than I expected. Things work ok, when I'm in the right place. Thanks for all help anyway, spend no more time on this one!
I have an MVC3 project, which uses an ClassLibrary-assembly. I would like to create instances from types in that class library from a console application (in the same solution).
I have made sure that I use the fully qualified name, since it's a different assembly than the console app. In my case, the type name is:
KIBS.DykrapportDomain.Model.DykRapport_Utrustning, DykrapportDomain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
I've added a reference to the class library project from the console project, it seems fine when I open it in the Object Browser, I can see everything inside. I have also made sure that the target framework is .NET 4 (not client profile) for either of the projects.
Still, when I add the following statement:
using KIBS.DykrapportDomain.Model;
I get an The type or namespace name 'KIBS' could not be found (are you missing a using directive or an assembly reference?)
What am I missing!?
Check your console application and make sure it targets the full .Net framework and not the the client Profile version.
Check the name space of the class which you want to create the inside the console application and if KIBS.DykrapportDomain.Model then it should work other wise use the namespace that is inside the class

Class Library Intellisense not showing up after adding the dll to the references

In C#, I made a ClassLibrary that has one Namespace and one Class.
I saved it and build it.
in other Projects, when i use it, I add it to my references by browsing to the .dll location.
But The Problem is that its name is not showing up in the Intellisense.
i.e when I: using ... my dll doesn't show ..
I'm Importing the library to a ConsoleApp.
both of the App and the library target Framework is .NET Framework 4.0
and I made their Assembly Version 4.0.0.0 so they're the exact same.
is there a setting or something that I'm missing ?
how can i make it pop up ?
I'm using VS2010 Professional
Thank you for your help
Maybe this be usefull, I was having a similar issue, I have a Web project, add the reference to a Class Library by selecting the project, but if I made a change on the class library, I canĀ“t see that change on the intellisense of the Web Project, after try many things, I see that in the recently added reference, the value of the option "Local Copy" was set "True", then I change it to false and everething works!
I had a similar issue but in my case it was a property on the class. If you go to the file properties and look for a Build Action. Somehow mine was set to Content it had to be set to Compile.
I am using Visual Studio 2013. I hope this helps someone else.
Is the namespace for your assembly different than the namespace for your currently open project? I've had times when the current project and an assembly share the same namespace path the intellisense can mess up.
In general, Visual Studio is pretty good about intellisense generation, especially for C#. But sometimes there are some interesting conditions regarding ambiguities, and especially mixing project types where it just doesn't quite work.
Placing your content in the same namespace makes me wonder if you've actually fixed the problem (it may just be autocompleting the namespace in the currently loaded project rather than the assembly), but if it allows you to continue working, then go with it!
Right click on project on which you add reference of your dll/project select menu project dependancies and select/MarkCheckBox for reference project/dll. then it will work fine.
If the class library project had its name changed after creation, then intellisense may fail finding it due to directory issues, I believe.
I created my class with the generic "ClassLibrary1" or whatever, and then later changed the default namespace, class name, and project name inside of VS2017. I closed VS2017 and changed the directory name to match my default namespace, and then re-associated the project file in VS2017, and then re-added the reference in my main project file.
All seems to be fixed now.

migration problem VS2005 -> VS2010 - missing assembly reference error

I recently migrated a solution from VS2005 to VS2010.
The solution is composed by about 20 project. One of them is in VB.net, the others are C#.
In VS2005 everything was fine, that is I was able to reference the VB.net project into the C Sharp projects. Now I cannot anymore.
The strange thing is that when I open in the editor a C# class referencing the VB.net dll, I get a compile error that sounds more or less like this:
"he type or namespace name 'VB.netProject' does not exist in the namespace 'Solution Namespace' (are you missing an assembly reference?)"
... and no, the assembly reference is there indeed!
However, when I close the files in the editor and try to compile again, the operation succeeds and the executable that I get works perfectly like it did in VS2005.
Is there a way I can manage to see the VB.net component in the editor? I am sure I am missing something, but I don't know what! :-)
Many thanks in advance for your help,
John
Unfortunately the visual studio sets (after the migration) the target framework to .NET Framework 4 Client Profile. If this target framework is set, some namespace could not be found (=> because the client profile doesn't contain this classes). Please verify, if your project has set this target framework. You will find this setting under the project properties.
Kind regards, patrick

Categories