.net library class not updated in web page - asp.net

I just created a new web site in Visual Studio 2012. I also created a new Class Library. I added a class, another class inside that first class and then a method. I compiled the library and added as the reference in the bin folder for the web site.
In a aspx.cs page I can now see my new method. Great. I go to create a second method in the same location, go back in my aspx.cs page, can't see it. It says there is definition for this method.
I compile the class library just in case. Can't see it. I clean the solution, build the whole solution, still can't see it.
I actually have to remove the reference from the bin folder of the web site and add it back so that now I can see the second method.
I worked on another project where (I believe) things were set up the same way (web site + class library) and by typing the new method in the class and saving the file was enough to reach this method from an aspx page.
What can I change in my solution so that the new method in the class library can be seen directly?
ps: the aspx.cs page has using myLibrary; at the top;
Thanks

Make sure in your solution that you are using the References folder. Right-click it, choose "Add Reference" and then use the Solution tab to reference your class library project. Taking this approach, every time you update your class library the web project will automatically receive the update.
It sounds like you might be adding the binary to the BIN folder of the website project and then referencing it from there?

First of all check if build is going to debug folder or bin folder. If you are referencing project then make sure that build order is correct and dependency set accordingly. Also check for class library or project referred solution is not building on client profile, select targeted framework.

Related

References and external class use problems

Using Visual Studio 2015 on an ASP.NET project. Everything works fine except now I have a block of code (A common AD utility function) that I want all the pages to be able to access. The original language (inherited project) is VB.NET, but it should work just fine either way.
I created a class file, named it CommonADFunctions.vb. The file uses System.DirectoryServices, and there's a reference in the project to that assembly. However, there are two problems:
I can't reference the new class to call the functions from any of the page code files. This includes attempts to instantiate a new variable as the class type.
When I move the new .VB file into App_Code, the reference to System.DirectoryServices breaks, and it refuses to build.
This may seem like a trivial ask, but what am I missing?
Turns out this was a simple property on the file itself I created a new Class File, and somehow the Build Action got set to Content rather than Compile. Setting this to Compile allowed the object to be referenced and instantiated properly. It doesn't fix the IDE intelliSense from APP_Code for DirectoryServices references in the code, but it compiles and runs, which is what I needed.
EDIT: Received external help which pointed this out.
Without code and screenshots to illustrate I can only recommend a few things to try.
I can't reference the new class to call the functions from any of the page code files. This includes attempts to instantiate a new variable as the class type.
The methods in the class have Private or Friend scope.
Its a static class (a Module in VB.Net) and you do not need to instantiate it.
You are somehow referencing an old DLL which doesn't have the methods. Check the reference to this AD project and make sure its "Referenced" via Project.
When I move the new .VB file into App_Code, the reference to System.DirectoryServices breaks, and it refuses to build.
This sounds like a corrupt project file. Clean the solution, delete the .suo file, delete the obj & bin folders.
Then move the CommonADFunctions.vb to the App_Code folder and add the DLL reference to System.DirectoryServices. Or create the CommonADFunctions.vb file in App_Code to start with.

Copying/Moving App Code to New Project

Ok, I am in the process of breaking apart of intranet application (VS 2010 Web Site, ASP.NET Web Forms with VB code behind). During this process i'm trying to convert some of our our app_code files in to WCF rest service in a new project. However, when I copy or "add existing" vb files into the new "services" project. I get tons of errors including...
error BC30002: Type 'XXX' is not defined
warning BC40056: Namespace
or type specified in the Imports 'System.ServiceModel' doesn't
contain any public member or cannot be found. Make sure the
namespace or the type is defined and contains at least one public
member. Make sure the imported element name doesn't use any aliases.
From what i've read it may (or may not) have something to do with Assemblies and references that I just have very little knowledge on. I have added the namespaces from the current web.config to new project's web.config, and the files are identical. So there is something in the background that needs to be added to the new project I just don't know what its.
PLEASE HELP!!
THANKS
JOSH
UPDATE 1
So one of the errors i'm getting = "error BC30002: Type 'MailMessage' is not defined." Which is a namespace that is added to the web.config, which apparently isn't being picked up??? IDEAS?
I've come across a similar issue - not sure what the reasoning behind it is, but I got around it by creating a new .vb class with the same name as the one you want to copy, then copy and paste all the text from the old one to the new one. Save it, then it seems to like it - it didn't like me copying and pasting the actual file, nor did it like me adding existing files.
Hope this helps :/
This issue seems to be tied to the the differences between Web Application Projects versus Web Site Projects. Eventually I had to add different namespaces on the new project level.
Here is more info about WAP vs WSP....
http://msdn.microsoft.com/en-us/library/dd547590(v=vs.110).aspx

Can I compile only one class files and use it?

I have a asp.net application, in which I have App_code folder with different classes.
Whenever I publish my application it creates single App_Code.dll for all classes, which is fine, but now I have to add one more class but I want to publish only that class file.
Is it possible??
Try with adding new project (Class library ) in solution, add your class file in that project .
And use it by adding reference it to in another project.
Then you shouldn't publish, place the code as is and it gets compiled on first user's request. And whenever new class is added, AppPool gets restarted. Of course, this comes with slowness for first user and after that it is similar to what is done with publish.

Convert Class to Class Library

I'm trying to follow along with Paul Sheriff's e-book "Fundamentals of N-tier" which is really good so far.
At the end of chapter 2 he says we should break the classes we have created into separate class libraries and that these libraries(dlls) can then be used from any application. The book doesn't explain how to do this.
I have the classes built, but I don't know how to convert them to Class Libraries and reference them in my project.
===========================================================
Thanks for everyone's help I really appreciate it.
I've created the class library in the same project and added a reference to it.
DataCommon is the name of the Class Library
DataLayer is the class
GetDataTable is a method in the class
how do I access this method from the web project.
I added a "using DataCommon;" statement at the top of the class that I'm trying to access the class library in. I get a "the type or namespace could not be found" message
Start by adding a new project to your solution of type Class Library.
(source: c-sharpcorner.com)
Then move those classes to this project.
Finally reference the project in the ASP.NET site.
Just cut out the code you want to reuse and copy into a new dll project. Then reference that dll project from your application and include the namespace anywhere you want to use those classes. There isn't any other magic involved. Just cut from one project and put in another.
Create a new "class library", a project type when creating new project. Then just copy the class into the project, ensuring you are changing the namespace to the appropriate namespace.
I have the classes built, but I don't
know how to convert them to Class
Libraries and reference them in my
project.
Create a new project of type "Class Library" and add your class files to that.
To reference them from your project, you just right click the project in solution explorer and "Add Reference". If the you've got both projects in the same solution, you can then click the Project tab and make your selection. If not, then click the Browse tab and navigate to the bin/debug or bin/release folder from your class library project which contains the compiled dll. (you must have built your class library project for the compiled dll to exist, of course)

Problem Converting Web To Web Project In VS2008

I have converted my old VS2008 Website to Web Application, now everything was working before I tried to convert it. But now I don't seem to be able to reference my Classes? For example I have a BasePage class that every .aspx page inherits like so
public partial class SomePageName : BasePage
{
}
But now I get this message? And the same for all the other classes?
The type or namespace name 'BasePage' could not be found (are you missing a using directive or an assembly reference?)
How do I find out which 'using' directive I am missing and whats an assembly reference?
The conversion namespaced your classes. Perhaps it should be NewlyAddedNamespace.BasePage?
Locate the class BasePage in your project using the object explorer.
In object explorer you will be able to see the complete name Something.Somethingelse.BasepAge
Do mass search and replace to the complete name.
In Solution Explorer (available on the View menu if you can't see it), you will see that your web application contains a node marked "References". Right click on this and choose "Add reference", and when the dialog box appears, on the Project tab you be able to add a reference to the other project which defines this BasePage class. This then becomes an assembly reference when compiled.
You probably already have the using statement you need from before. Previously, this would have been picked up by the presence of the necessary DLL in the bin folder of the web project. It works differently for a web application.
How to convert in a Web Site Project - will get you started - it is for VS2005 but will still be applicable for Visual Studio 2008.
You might want to take a look at the difference between the 2 types of projects. That said, website projects generally are not created with namespaces, I would guess that "BasePage" was in you appCode folder and has now been converted into a different namespace. You just need to line you your namespaces and everything should work correctly.
What you could try is "Convert to Web Application" in Visual Studio. It is available in the context menu of the new Web Application project in Visual Studio.
There's another possible issue. You might need to set the "Build Action" to "Compile instead of Content. Right-click the .cs file, bring up the properties and make sure the Build Action is compile.

Resources