Runtime Error in C# - c#

I have installed Async-CTP-v3 for using new feature of C# 5 but when I tried to run a console application using async keyword/await expression this error appeared:
"A Project with an output type of Class Library cannot be started directly.
In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project."
Is there anyone can help me?
Thanks.

Your project's output type is almost certainly set to "Class Library".
You can change the Project's Output type by right-clicking on your project in Solution Explorer and selecting properties in the context menu.
Here you can choose the Output type from a drop-down menu. Change your project's output type from "Class Library" to "Console Application"
If that does not work, double check your startup project and make sure it's the project you think it is (and should be).

Related

Added a project but it says its missing

So I added a project to my solution, it builds, but I can't seem to reference it, as it says its missing. I've looked and tried all the answers here:
The type or namespace name could not be found
but none worked for me. all projects are set to target .NET Framework 4.5, Site project is dependant on the reference project, they all have the same Configuration Properties (Debug, Any CPU, Build)...
Any other ideas?
I could be wrong but i think a depency is only used for build order.
Did you add the project as a reference via Project folder => References(Right click on it) and select Add Reference...
Then open Solution,Projects and check the project that holds the namespace you are using(in your case DataTables.mvc)
Images for clarity :

Code in C# for a console application project that consumes a dll from another project

I am using visual studio for this. I have test project which generates a dll and runs the different tests everytime I build the project. Now i want to write a console application which generates an exe that consumes the dll generated above. Can I do it using dllImport? If yes, please tell me how?
You just need to:
Add the test project in the same solution then,
add reference to project from your console application.
Now when you build the solution the library project will built first and its .dll will automatically be included in the bin directory of you console project. The advantage of doing this instead of referencing just the built .dll is you can modify and debug the source of your library project, e.g. step into it's methods.
However you can just do the second step and instead of adding a reference to your project browse to to the built .dll and add that as a reference.
You can either
Add the test project in the same solution then,
Add reference to project from your console application.
OR
Include a folder named Tests into your console app.
Add the test dll generated in it.
Add reference to project from your console application.
You can add reference :
In Solution Explorer, right-click the project node and click Add Reference.
In the Add Reference dialog box, select the tab indicating the type of component you want to reference.
Select the components you want to reference, and then click OK.

Convert a completed project to a DLL

How can I convert a completed C# project to a DLL, in order to use it in other projects?
I have Googled but lots of results say to open the Class Library, write your code there, then Build Solution and everything will be ok.
But my question is: how can I convert a completed project to a DLL? The project can include lots of Forms etc.
if your code is complete, you need to create a Class project out of it, if you already have a project then only transfer the useful code to the class project for reuse in other projects
or change the Output Type to class library, you can find that in your project properties under the tab application
If you are using VS2010, go to your solution in Visual Studio,
Click the 'Project' tab
Select 'Project Properties' down at the bottom of the menu
Now in the 'Properties' window click 'Application'. This should show you a menu
On this menu, select the 'Output type' as 'Class Library'
Now when you compile the project you will get your output as a DLL (.dll) in the relevant bin folder.
I hope this helps.

Copy C++ library to a C# project automatically on build? (Visual Studio 2010)

I have a library written in C++, and a wrapper for this library written in C#.
Both projects are under development, and the way it is now I have to manually copy the .dll from the C++ project to the C# project after each build.
So I was wondering if there was any way to make Visual Studio copy the .dll from the C++ project automatically when re-building?
You can use Build events in visual studio and place a dos command to copy the dll to the current project
Right click on the project in Solution explorer in Visual studio, select properties. There in Build events you can type:
copy c:\Cplusproject\yourproject.dll $(TargetDir)
You can use Post Build or Pre Build events based on your requirements
See this article: http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx
Use post build event for that. Just something like xcopy <yourDllFilePath> <destinationPath> and it will copy your dll file to wherever your want
if yr using that c++ dll as reference, then u might be able to add the c++ project as a project reference, and everything will be copied automaticly, and it also helps while debugging.
Click on references in yr c# project, then a dialog window opens and choose Projects and select yr c++ project
There are several approach to achieve what you request.
Here I suppose you are using Microsoft Visual C++, but on other platforms there will be analogous functionalities.
Right click on the icon representing the vc++ project on the Solution explorer
Click Properties
Select the Configuration Properties/Build Events/Post Build Event node
Write the Command Line required to copy the dll around
Remember you must do it for every Configuration and for every Platform supported from your project.
Alternatively you may ask the Linker to output directly on the location referenced by your C# project:
Right click on the icon representing the vc++ project on the Solution explorer
Click Properties
Select the Configuration Properties/Linker/General Event node
Set the Output File property to the location referenced by your C# project
That said, you may also get the dll from the c# project.

Rebuild Visual Studio Library Project Reference

I have a Visual Studio 2010 solution that contains multiple projects. One of these projects is a library, which I have added a method to. Within visual studio I can navigate from the method call in my main project to the method in the library, but when I attempt to build/run the solution it gives me a "does not contain a definition for 'My_Method'". What am I doing wrong?
Seems you are not rebuilding the library project and/or you are referencing the output binary (dll) directly. To solve this you can do one of the following
Make sure you rebuild the library project, and reference the updated binary/dll
Reference the project directly if it's part of your solution, this way, every time you rebuild the dependent project, it will rebuild the library project. The drawback to this is, if you have too many projects, it will slow you (re)builds
It looks as if the library project isnt being rebuilt on each run, assuming that the project reference is correctly added (right click on references -> add reference -> select your library project)
You should make sure that your library is being rebuilt when you run.
To do so :
Right click on your Solution
Click on Configuration manager (approximative translation)
Make sure that the build is checked, if not, check if for the library project

Categories