Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console unavailable in class library c#

This question here seems contrary to what I have experienced. I cannot access the console from within a new class library. I have using System; at the top. I am using visual studio 11 on windows 8. I doubt that this has been lost in the update, so that means that I am doing something wrong.

Also, once this is working, is the console available in a portable class library?

EDIT

here is just a test file I made

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdamLib.util.ConsoleSupport
{
    class SafeRead
    {
        private void test()
        {
            System.Console.Writeline("test"); //Console is not found in system
        }
    }
}

This is in the class library.

RESOLVED

Like I thought, it was my fault.

Thanks to @DarinDimitrov, who pointed out that with VS 11 and metro, Console support has been removed for use with metro. So to resolve this I needed to create a new project with the second kind of class library. There are two listed and I used the one with the description that includes metro. To resolve the issue, I had to use the other type without metro in the description.

Thanks again to all that helped.

like image 267
Adam Schiavone Avatar asked Mar 12 '12 22:03

Adam Schiavone


People also ask

How do I change the output type to a class library?

In the Solutions Explorer window, right-click the exe project and then select Properties in the popup. Then change the Output type from Windows Application to Class Library.

How do you fix project with an output type of class library Cannot be started directly?

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 Console a class in C#?

In C#, the Console class is used to represent the standard input, output, and error streams for the console applications. You are not allowed to inherit Console class. This class is defined under System namespace. This class does not contain any constructor.

How do I add a class to my Console application?

Add a New Class to the ApplicationChoose 'Add Class...' from the Project menu of Visual Studio or Microsoft C# Express Edition. You will be asked for a name for the new class. Type 'Vehicle' and click the Add button. A new class file is generated with the definition of the class already added.


1 Answers

If you created a Metro style application, there's no Console in WinRT. Don't search for it as you won't find any. This is explained in this article:

The subset of managed types and members was designed with a clear focus on Metro style app development. As a result, it omits the following:

  • Types and members that are not applicable to developing Metro style apps (such as console and ASP.NET types).

  • Obsolete and legacy types.

  • Types that overlap with Windows Runtime types.

  • Types and members that wrap operating system functionality (such as System.Diagnostics.EventLog and performance counters).

  • Members that cause confusion (such as the Close method on I/O types).

You could use the debugging API or logging framework.

like image 113
Darin Dimitrov Avatar answered Sep 20 '22 18:09

Darin Dimitrov