Console unavailable in class library c#

Adam Schiavone picture Adam Schiavone · Mar 12, 2012 · Viewed 27.2k times · Source

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.

Answer

Darin Dimitrov picture Darin Dimitrov · Mar 12, 2012

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.