I can’t reproduce this issue in a simple .NET 4.0 console application:
static class Program { static void Main(string[] args) { var myDict = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } }; Console.ReadKey(); } }
Can you try to reproduce it in a simple Console application and go from there? It seems likely that you’re targeting .NET 2.0 (which doesn’t support it) or client profile framework, rather than a version of .NET that supports initialization syntax.
Related Posts:
- What is C# equivalent of
- What is the best way to iterate over a dictionary?
- Get dictionary value by key
- Collection was modified; enumeration operation may not execute
- Get single value from dictionary by key
- How do you sort a dictionary by value?
- How to update the value stored in Dictionary in C#?
- Get dictionary key by value
- C# Convert List
to Dictionary - C# Dictionary get item by index
- What is IP address ‘::1’?
- What is the yield keyword used for in C#?
- Join/Where with LINQ and Lambda
- C# compiler error: “not all code paths return a value”
- C# equivalent of C++ map
- How to convert byte array to string [duplicate]
- C# Java HashMap equivalent
- The page was not displayed because the request entity is too large on IIS
- Configuration System Failed to Initialize
- Export Pervasive to MySQL (C#)
- Why use the params keyword?
- What does plus equals(+=) operator means here?
- The request was aborted: Could not create SSL/TLS secure channel
- finding the maximum length of lists in c#
- The located assembly’s manifest definition does not match the assembly reference
- OnTriggerEnter not working at Unity3D
- The requested resource does not support HTTP method ‘GET’
- Rename a file in C#
- What does mscorlib stand for?
- XAML Binding Groups
- Does not contain a static ‘main’ method suitable for an entry point
- Add new item in existing array in c#.net
- How to fix file format and extension don’t match?
- Invalid length for a Base-64 char array
- The HTTP request was forbidden with client authentication scheme ‘Anonymous’. The remote server returned an error: (403) Forbidden
- Why am I getting a “Could not find a part of the path” exception?
- How to move 2D Object with WASD in Unity
- The Object you want to instantiate is null. Unity 3D
- Convert date yyyyMMdd to system.datetime format
- How to bind a model to a kendo Combobox in order to use the models validatation?
- HttpWebRequest-The remote server returned an error: (400) Bad Request
- MSHTML DLL on Windows 10
- Adding values to a C# array
- C#: how to get first char of a string?
- how to convert C# to C++
- Reading settings from app.config or web.config in .NET
- How to initialize a list of strings (List
) with many string values - Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on
- Unity – Gameobject look at mouse
- What does the @ symbol before a variable name mean in C#?
- What is the C# version of VB.net’s InputDialog?
- How to add comments into a Xaml file in WPF?
- How to easily initialize a list of Tuples?
- How do I target @Model within a src of an image tag?
- How to round up in c#
- Converting from IEnumerable to List
- Escape double quotes in a string
- Specified cast is not valid?
- Get int value from enum in C#
- How to do constructor chaining in C#
- “Too many characters in character literal error”
- Is dependency injection useful in C++
- What represents a double in sql server?
- How do you get the index of the current iteration of a foreach loop?
- Expression denotes a `type’, where a `variable’, `value’ or `method group’ was expected UNITY3D
- How do I restart my C# WinForm Application?
- WSACancelBlockingCall exception
- Padding is invalid and cannot be removed?
- Why is it that “No HTTP resource was found that matches the request URI” here?
- Best way to reverse a string
- C# Foreach statement does not contain public definition for GetEnumerator
- C# Passing Function as Argument
- “Invalid JSON primitive” in Ajax processing
- I got error “The DELETE statement conflicted with the REFERENCE constraint”
- Non-invocable member cannot be used like a method?
- How do I exit a foreach loop in C#?
- Fastest way to remove first char in a String
- How to convert datetime format to date format in crystal report using C#?
- Most efficient way to remove special characters from string
- When do we use ANTLR
- How to convert UTF-8 byte[] to string
- How would you count occurrences of a string (actually a char) within a string?
- Socket.Select returns error “An operation was attempted on something that is not a socket”
- Rotate object in Unity 3D
- C# equivalent to Java’s charAt()?
- How to play a sound in C#, .NET
- Convert SQL to LINQ Query
- How to resolve file being used by another process?
- How to crop an image using C#?
- How do you wait for input on the same Console.WriteLine() line?
- Why doesn’t C# have header files? Will the namespace take care of everything?
- How to avoid a System.Runtime.InteropServices.COMException?
- Define: What is a HashSet?
- Convert string to decimal, keeping fractions
- “A namespace cannot directly contain members such as fields or methods”
- Format of the initialization string does not conform to specification starting at index 0
- How can I generate random alphanumeric strings?
- How do you do a deep copy of an object in .NET?
- Cannot declare instance members in a static class in C#
- How to convert HTML to PDF using iTextSharp