Error missing namespace or assembly reference

Viewed 22618

I am writing the code right, but getting error - missing namespace or assembly reference.Is there something wrong with the code or I am missing something?

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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            int sum = 0;
            int[] arr = new int[] { 1, 2 };

            do
            {
                {
                    sum += arr[1];
                    Console.WriteLine("Wow");
                    i++;
                }
            }
            while (i < 3);
        }
    }
}

Error is : Error Cannot initialize type 'int' with a collection initializer because it does not implement 'System.Collections.IEnumerable

7 Answers

I faced a similar problem. The namespace name I used ended with .Console, so there was a conflict with System.Console

using System;

namespace Test.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

I changed Test.Console to Test.ConsoleApp, and problem fixed for me

using System;

namespace Test.ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Using a namespace of Myproject.App also causes problems, in the same way as MyProject.Console (as per contactmatt's answer, above).

Related