how to import dll in c# - c#

I have some .dll and .xml(e.g. FarsiLibrary.Resources.dll ,FarsiLibrary.Resources.xml) to use with Persian calender .
how do I import it in my project.
note: I'm using Visual Studio 2012.

"Right click on project -> Add Reference -> Browse..." for DLL.
Add existing file for XML.

You just need to do following
Right click on your project and choose Add Reference.
When the dialog comes up, choose the Browse tab and go find your dll
After adding the assembly include that reference in your class or
form where ever you are going to use
Or you looking for [DllImport("dll")]? More Here

Related

Call Forms from Two C# projects in a third Project

This is the first time I start with StackOverflow...
I think my question is a silly question!!
I need to call the forms and classes from two C# projects in a third project
I follow these steps:
From Solution Explorer in a third project, I have clicked the Add Reference
I click the Project Tab
I didn't find any add browsing to add these two projects. see the image
Create your multiple project in a single solution. then add project1 and project2 in your project3 reference using >> Add Reference >> Projects >> Solution.
here's how: https://msdn.microsoft.com/en-us/library/f3st0d45.aspx
Your Projects should be under same solution.
If in case you are building two projects differently not under same solution follow these steps
1.Create a winform project let say "Project1" go to project settings change the output type to class library and build it.
2.Create another winform project lets say "Project2" go to project setting change the output type to class library and build it
3.Create third project from where you want to call it. Go to Add reference. Browse for folders as below
debug folder of project1 select project1.dll and add reference.
debug folder of project2 select project2.dll and add reference.
4.Now create objects of Forms and call.
Alright. Visual Studio offers you the ability to add references you just created yourself. Those references could be (dynamic-link-)libraries DLL or executables EXE. So go ahead and create a project and add a new Form. This custom Form needs to be public so the other project is able to extract the code.
Now you are able to add and use a reference. Just be sure to include the namespace, if it doesn't match the one, in which you're going to use it.
The thing is called Project-to-project Reference

Merging Two Projects and accessing files from each other in Visual Studio

I have merged another project in my existing project by right-clicking on the project name and selecting Add->Existing project option. Now i wan't to access the files from my newly added project from the existing one in Visual Studio (Its a C# project) , how can i do this?
If I'm following your question, you had a solution with a project A. You then added an existing project B.
You now want to access a file from A in B. If that's the case, right click on the B -> References and add a reference to project A. Now you can use the files from that project.
Edit: From your comment, I'm not sure if you want to have a separate project / file. If you want them to be only 1, you shouldn't really add a new project, you should add to your project A the files you need from project B. If you want to keep it as a different module that is included, then the above holds, but you need to realize that usually you have one solution, with many projects inside of it.
I struggle with this until I found this the link is below:
If you want all windows application to run as one program rather then calling multiple .exe. Then change 'Out Put Type' of each project to 'Class Library'.
Step 1:
You can do that by right-clicking on each Project in solution -> Go to Properties -> Application -> Out Put Type... set it to Class Library
Once you have done that output of these will be generated as .DLL.
Step2:
Add a new Window Form application project, add reference of exiting projects in it so that they can be executed from here.. you can do that by.. right click on main project-> Add Reference->Projects select all existing projects from here.
Now on the main application, you can create 3 buttons to launch each project...
[Inventory]
[Accounts]
[Payroll]
Now in each button code will be something like that...
Inventory_click()
{
Inventory.MainForm frm=new Inventory.MainForm();
frm.show();
}
Credit goes to forum post

A project with an Output Type of Class Library cannot be started directly

Please can someone could explain why I get this error and what to do to fix it (or what I'm doing wrong!). The steps I have taken are
Download Source code from http://www.codeproject.com/Articles/16859/AForge-NET-open-source-framework
Opening in VS2010 shows the references cannot be found
Re-Add all 3 references from PlayingCardRecognition\bin\Release so no further warnings
When I try and build or Run I get the following message
To fix this issue, do these steps:
Right click the Project name in Solution Explorer of Visual Studio
Select Set as StartUp Project from the menu
Re-run your project
It should work!
If it did not work, be sure that you have set your start page. If your project is C# Windows Application or C# Console Application, try this:
Right click the Project name in Solution Explorer of Visual Studio
Select Properties
Select the Application tab
In the Output Type drop box
Select the correct application type of your project
Re-run your project and let me know if it won’t work.
The project type set as the Start-up project in that solution is of type ClassLibrary. DUe to that, the output is a dll not an executable and so, you cannot start it.
If this is an error then you can do this:
A quick and dirty fix for this, if that is the only csproj in the solution is to open the .csproj file in a text editor and change the value of the node <ProjectGuid> to the Guid corresponding to a WinForms C# project. (That you may obtain from a google search or by creating a new project and opening the .csproj file generated by Visual Studio to find out what the GUID for that type is). (Enjoy - not many people know about this sneaky trick)
BUT: the project might be a class library rightfully and then you should reference it in another project and use it that way.
.Exe's and .dll's are both assemblies. The key difference is that executeables define an entry point Main which can be invoked by the runtime. The error
"Class library cannot be started directly"
is due to the fact that said .dll's do not have a Main. To fix this issue, change the project type to a Windows application/Console application and define an entry point. Or, add a new project that is of type Windows application/Console application and reference said .dll.
The project is a class library. It cannot be run or debugged without an executable project (F5 doesn't work!!!). You can only build the project (Ctrl+Shift+B).
If you want to debug the code add a console application project (set it as the start up project) to the solution and add the reference to the library.
The project you downloaded is a class library. Which can't be started.
Add a new project which can be started (console app, win forms, what ever you want) and add a reference to the class library project to be able to "play with it".
And set this new project as "Startup project"
The project you've downloaded is a class library, not an executable assembly. This means you need to import that library into your own project instead of trying to run it directly.
Your project type is a class library one would suspect, add a ConsoleApplication or WindowsApplication and use that as your startup object. Reference this project and then access the code.
If you convert the WPF application to Class library for get the projects .dll file.After that convert the same project to the WPF application you get the following error.
Error:".exe does not contain a static main method suitable for an entry point".
Steps to troubleshoot:
1.Include the App.xaml file in the respective project.
2.Right Click on App.xaml file change the build action to Application Definition
3.Now Build your project
Goto the Solution properties -> on Build right side you see the startup project type. here you need to select the console appication/windows appication.
If you got this issue (got it in Visual Studio 2017 RC), and you don't get any of the things listed by Mak post from step 3 onward "4 In the Output Type drop box....", it is because you made a Class Library app when you want to create a cross platform app, so here is the solution :
1 Start a new project
2 select Visual C# and cross-platform app.
3 select cross-platform app (Xamarin and native app)
4 select blank form.
From then , right click, select as startup project and build as mentioned by Mak, and it should work.
If you can afford to start from scratch, it could do the trick as it did for me.
This could do the trick for the main issue as well, but must be adapted to your current version of Visual Studio ("Xamarin.forms portable" for visual studio 2015 for example).
Bye!
VS -> Debug -> Attach unity debugger -> double click project
Set your api project to a startup project:
Right click the api Project than choose Set as startup Project.
Just right click on the Project Solution A window pops up. Expand the common Properties. Select Start Up Project
In there on right hand side Select radio button with Single Startup Project Select your Project in there and apply.
That's it. Now save and build your project. Run the project to see the output.
_Sarath#F1
To fix this issue, do these steps:
Right click the Project name in Solution Explorer of Visual Studio
Select Set as StartUp Project from the menu
Re-run your project It should work!

Using .dll file in asp.net application

I'm working on asp.net (web application). I have to use time picker control in my page. Hence i downloaded 'time picker.dll' file from some website. I need to integrate this 'dll' file into my project. can anyone pls guide me in the same?
You would add it as a reference in the project. Right click on VS and add reference and browse to it.
In your file include a using statement for the namespace of the DLL and then you should be able to instantiate a new object.
Copy the "time picker.dll" into the Bin folder of your web-app and add <%#Register %> directive into your web-page to use that control.
Assuming dll package the typical ASP.NET server control, you have to add reference to the dll (VS Studio Project -> References -> Right-Click & Add Reference, Browse the dll file).
Next thing to do is to add the control on tool box by right clicking on the toolbox and selecting the control. Now you can drag the control on the ASP.NET Design surface. Alternatively, you can use the object browser to check the control name and use the register directive.

Project reference problem

My project has some references. One of them has no path. I can't view it in object browser. When i want to remove it, my project closed.
I can't remove or change this reference. What can i do?
Thanks in advance.
Edit your project file with notepad and check the problem. (.csproj in case of C# project)
Visual Studio has a specific editor for project files, if you can open the solution which contains your project then if the project icon is grayed out just right click on it and select edit, you will have the project file opened in the text editor with xml schema validation and intellisense.

Categories

Resources