Convert Class to Class Library - asp.net

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)

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.

Reference problems when using custom controls within Exrin

Using the base Exrin template, I am unable to use custom controls.
As it stands now, the Droid/iOS projects reference the App/Bootstrapper project, so that seems like the correct place to put them, but when creating a new page or BaseView, I am not able to access the custom control's namespace because the View project does not reference the App/Bootstrapper project.
The Tesla sample app does not have this problem in its current implementation since there is no separation of the App/Bootstrapper and the View projects.
(1) Should a reference to the App/Bootstrapper be placed in the View project or (2) should a reference to the View project be placed in the Android/iOS/etc projects? Or is there a better solution than either of these two?
Edit:
(1) does not work because a reference to the App project from the View would create a circular dependency.
(2) should work (I think), but I'm having trouble getting the Application.Droid project to access the Application.View project namespace because when I add using Application.View;, the namespace isn't found in the Application namespace. Visual Studio attempts to fill in other Application namespaces (.Container, .Logic, .Droid, .Proxy) when I type in using Application.
The native project can have a reference to the View. It already does in a way, because it references the App library, which then references the View. Hence you aren't really adding any further dependencies by doing this, just allowing access further up the chain.
If you are having trouble the namespace, I suggest you start out with
global::Application.
That way it starts from the top, if its getting mixed up with project namespaces.

.net library class not updated in web page

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.

Can't call static class from different class library?

I'm using the .NET 4 framework, and I have a static class with static functions in an asp.net web application.
I have a second class library project. The class library project wants to call the static method in the web application. Intellisense works, but then the compiler reports that
"The name [MyClassName] does not exist in the current context".
Can I make this call, or this not allowed?
PS, the static class is in the /App_Code folder.
Thanks!
Is it not possible to refactor the class out of the web project? Referencing a web project from a class library sounds awkward. If your class does not contain web-specific code then you could pop it into that other class library you mention or create a new one. Should it reference web-specific libraries something like MyProject.MyLib.Web could do the trick.
You need to add a reference to the project containing the class you want to access.
You need to ensure that you are using the full name of the class (including the namespace).
Alternatively add a using directive with the namespace to your code file.
If your target framework is .Net Framework 4.0 Client Profile change it to .NET Framework 4 and rebuild the solution.

How to create a DLL from a WSDL for use in DNN Module

I'm creating a DNN 4.9.5 module and need to create a DLL from a WSDL (Doba API). I've created a separate Class Library project in my DNN solution with Class1.vb in it. What do I need to include in my class from the WSDL file? Obviously, I won't be going with Class1.vb, but just need a gentle push as to how to get this going.
Thanks much for your guidance.
This is not a problem. Simply create your class library and then use "Add Service Reference" to point to the WSDL.
Do not use "Add Web Reference" unless you have to. Microsoft considers that to be "legacy technology".
Why do you want to create a dll to access the webservice? If you just want to use it (assumung that you are using ms-visualStudio) you need to add a webservice reference to your separate Class Library project .
That will create the sourcecode for a wrapper class to call the webservice described by wsdl.
See msdn:How to: Add and Remove Web References

Resources