diff --git a/.localization-config b/.localization-config new file mode 100644 index 0000000000000..cf26e2c8bcce5 --- /dev/null +++ b/.localization-config @@ -0,0 +1,34 @@ +{ + "Filters": [ + { + "Files": [ + "**/*.md" + ], + "Priorities": [ + { + "Priority": "ht", + "Locales": [ + "cs-cz", + "de-de", + "es-es", + "fr-fr", + "it-it", + "ja-jp", + "ko-kr", + "pl-pl", + "pt-br", + "ru-ru", + "tr-tr", + "zh-cn", + "zh-tw" + ], + "Type": "ht" + } + ] + } + ], + "IncludeDependencies": true, + "AutoPush": true, + "XliffVersion": "1.2", + "UseJavascriptMarkdownTransformer": true +} \ No newline at end of file diff --git a/_zip/msdn.4.5.2.zip b/_zip/msdn.4.5.2.zip new file mode 100644 index 0000000000000..65a3dae3b1317 Binary files /dev/null and b/_zip/msdn.4.5.2.zip differ diff --git a/_zip/namespaces.4.5.2.zip b/_zip/namespaces.4.5.2.zip new file mode 100644 index 0000000000000..2ed7c4c711212 Binary files /dev/null and b/_zip/namespaces.4.5.2.zip differ diff --git a/_zip/office15.zip b/_zip/office15.zip new file mode 100644 index 0000000000000..268b785c831bc Binary files /dev/null and b/_zip/office15.zip differ diff --git a/_zip/vs.110.zip b/_zip/vs.110.zip new file mode 100644 index 0000000000000..75d6e538f97fb Binary files /dev/null and b/_zip/vs.110.zip differ diff --git a/_zip/vs.140.zip b/_zip/vs.140.zip new file mode 100644 index 0000000000000..97b2d3677f9a0 Binary files /dev/null and b/_zip/vs.140.zip differ diff --git a/api/index.md b/api/index.md index 771fe77bfd197..12f392ced9f28 100644 --- a/api/index.md +++ b/api/index.md @@ -488,7 +488,7 @@ The following is a list of namespaces in the .NET Core class library. Each names @System.Threading - Provides types that enable multithreaded programming. In addition to classes for synchronizing thread activities and access to data (such as @System.Threading.Mutex, @System.Threading.Monitor, @System.Threading.Interlocked, and @System.Threading.AutoResetEvent), this namespace includes a @System.Threading.ThreadPool class that allows you to use a pool of system-supplied threads, and a @System.Threading.Timer class that executes callback methods on thread pool threads. + Provides types that enable multithreaded programming. In addition to classes for synchronizing thread activities and access to data (such as @System.Threading.Mutex, @System.Threading.Monitor, @System.Threading.Interlocked, and [AutoResetEvent](xref:System.Threading.AutoResetEvent)), this namespace includes a @System.Threading.ThreadPool class that allows you to use a pool of system-supplied threads, and a @System.Threading.Timer class that executes callback methods on thread pool threads. diff --git a/docfx.json b/docfx.json index 2f5caec3cbeba..4d9ffbfc82235 100644 --- a/docfx.json +++ b/docfx.json @@ -79,6 +79,7 @@ "author": "dotnet-bot" }, "dest": "_site", - "template": [ "docs.html" ] + "template": [ "docs.html" ], + "xref": ["_zip/msdn.4.5.2.zip", "_zip/namespaces.4.5.2.zip", "_zip/vs.110.zip", "_zip/vs.140.zip", "_zip/office15.zip"] } -} +} \ No newline at end of file diff --git a/docs/csharp/concepts.md b/docs/csharp/concepts.md index 097dadfad46ea..c0e7ed97a0de0 100644 --- a/docs/csharp/concepts.md +++ b/docs/csharp/concepts.md @@ -12,7 +12,7 @@ ms.devlang: dotnet ms.assetid: 809148dd-b231-4f2c-bb81-f5bfc426378d --- -# 🔧 C# Concepts +# C# Concepts > **Note** @@ -22,4 +22,4 @@ ms.assetid: 809148dd-b231-4f2c-bb81-f5bfc426378d > > If you would like to review early drafts and outlines of this topic, please leave a note with your contact information in the issue. > -> Learn more about how you can contribute on GitHub. \ No newline at end of file +> Learn more about how you can contribute on GitHub. diff --git a/docs/csharp/csharp.md b/docs/csharp/csharp.md new file mode 100644 index 0000000000000..dc01cc7fb85f0 --- /dev/null +++ b/docs/csharp/csharp.md @@ -0,0 +1,70 @@ +--- +title: "C# | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "article" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "documentation [C#]" + - "Help, Visual C# documentation" + - "C# language" + - "Visual C#" +ms.assetid: 7f4f8103-7068-4f1d-92c7-3c4519b6edbc +caps.latest.revision: 47 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# C# +C# (pronounced "C sharp") is a programming language that is designed for building a variety of applications that run on the .NET Framework. C# is simple, powerful, type-safe, and object-oriented. The many innovations in C# enable rapid application development while retaining the expressiveness and elegance of C-style languages. + + If you don't already have C#, you can acquire a version of Visual Studio that includes C# for free from the [Visual Studio](https://www.visualstudio.com/products/free-developer-offers-vs) site. + +## In This Section + [Getting Started with C#](../csharp/getting-started/getting-started-with-csharp.md) + Introduces the features of C# for programmers who are new to the language or are new to [!INCLUDE[vsprvs](../csharp/includes/vsprvs_md.md)], and provides a roadmap for finding Help about [!INCLUDE[vsprvs](../csharp/includes/vsprvs_md.md)]. + + [Using the Visual Studio Development Environment for C#](/visualstudio/csharp-ide/using-the-visual-studio-development-environment-for-csharp) + Introduces the [!INCLUDE[csprcs](../csharp/includes/csprcs_md.md)] development environment. + + [C# Programming Guide](../csharp/programming-guide/index.md) + Provides information and practical examples about how to use C# language constructs. + + [C# Reference](../csharp/language-reference/index.md) + Provides detailed reference information about C# programming concepts, keywords, types, operators, attributes, preprocessor directives, compiler switches, compiler errors, and compiler warnings. + + [C# Samples](http://code.msdn.microsoft.com/site/search?f%5B0%5D.Type=ProgrammingLanguage&f%5B0%5D.Value=C%23&f%5B0%5D.Text=C%23) + MSDN Code Gallery filtered for C#. + + [Walkthroughs](../csharp/walkthroughs.md) + Provides links to programming walkthroughs that use C# and a brief description of each walkthrough. + +## Related Sections + [C# Language Specification](../csharp/language-reference/language-specification.md) + Links to the latest version of the C# Specifications in Microsoft Word format. + +## See Also + [Getting Started with Visual C# and Visual Basic](/visualstudio/ide/getting-started-with-visual-csharp-and-visual-basic) + [.NET Development](https://msdn.microsoft.com/library/ff361664) \ No newline at end of file diff --git a/docs/csharp/getting-started/additional-resources.md b/docs/csharp/getting-started/additional-resources.md new file mode 100644 index 0000000000000..0ceb8b1c1ff1d --- /dev/null +++ b/docs/csharp/getting-started/additional-resources.md @@ -0,0 +1,93 @@ +--- +title: "Additional Resources for Visual C# Programmers | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "article" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "newsgroups [C#]" + - "Help, C# resources" + - "Visual C#, further information" + - "C# language, further information" + - "forums [C#]" + - "Visual C#, additional resources" +ms.assetid: cdec0df0-89ef-4ff1-8ccf-26fef47e61cb +caps.latest.revision: 27 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Additional Resources for Visual C# Programmers +The following sites can help you find answers to common problems. + +## Microsoft Resources + +### On the Web + [Microsoft Visual C# Developer Center](http://go.microsoft.com/fwlink/?LinkId=47811) + Provides code samples, upgrade information, downloads, and technical content. + + [Microsoft Help and Support](http://go.microsoft.com/fwlink/?LinkID=108287) + Provides access to Knowledge Base (KB) articles, downloads and updates, support Webcasts, and other services. + + [CodePlex](http://go.microsoft.com/fwlink/?LinkId=137330) + Hosts open source software projects. You can use CodePlex to create new projects to share with the world or join others who have already started their own projects. + +### Forums + [Visual C# Language](http://go.microsoft.com/fwlink/?LinkId=165947) + Provides a forum for questions about and general discussions of the C# language and compiler. + + [Visual C# General](http://go.microsoft.com/fwlink/?LinkId=165948) + Provides a forum for general discussion and questions regarding Visual C#. + + [Visual C# IDE](http://go.microsoft.com/fwlink/?LinkId=165951) + Provides a forum for discussions about the C# IDE. + + [MSDN Forums](http://go.microsoft.com/fwlink/?LinkId=157697) + Provides information about forums in which you can post questions and answers, and also view and search existing user-generated Help content. You can also access the MSDN forums by clicking **MSDN Forums** on the **Help** menu. + +### Chats and Discussion Groups + [MSDN Discussion Groups](http://go.microsoft.com/fwlink/?LinkId=145961) + Provides a newsgroup experience, enabling you to connect as a community with experts from around the world. + + [MSDN Chats](http://go.microsoft.com/fwlink/?LinkId=145962) + Provides discussions about Microsoft products and technologies. Each chat is hosted by one or more Microsoft experts. Transcripts are available for completed chats. + +### Videos and Webcasts + [Channel9](http://go.microsoft.com/fwlink/?LinkID=123827) + Provides a community through videos, Wikis, and forums. + +### Support + [File Bugs or Make Suggestions](http://go.microsoft.com/fwlink/?LinkID=79804) + Enables you to file bugs or provide suggestions to Microsoft about Visual Studio. You can also report a bug by clicking **Report a Bug** on the **Help** menu. + +## Third-Party Resources + MSDN's Web site provides information about current third-party sites and newsgroups of interest. For the most current list of resources available, see the [MSDN C# Community Web site](http://go.microsoft.com/fwlink/?LinkId=165945). + +## See Also + [C#](../../csharp/csharp.md) + [Getting Started with C#](../../csharp/getting-started/getting-started-with-csharp.md) + [Customizing the Editor](/visualstudio/ide/customizing-the-editor) + [How to: Get Involved in the Developer Community](http://msdn.microsoft.com/library/f1503d98-7a64-41b6-a6c7-0e42a533e9c5) + [How to: Send Feedback](http://msdn.microsoft.com/library/c9f1dd8f-bcb6-40ac-b896-1e9eca0bb209) + [Talk to Us](/visualstudio/ide/talk-to-us) \ No newline at end of file diff --git a/docs/csharp/getting-started/breaking-changes-in-visual-studio-2013.md b/docs/csharp/getting-started/breaking-changes-in-visual-studio-2013.md new file mode 100644 index 0000000000000..d9cf84c3be12e --- /dev/null +++ b/docs/csharp/getting-started/breaking-changes-in-visual-studio-2013.md @@ -0,0 +1,46 @@ +--- +title: "Visual C# Breaking Changes in Visual Studio 2013 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "article" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "breaking changes [C#]" +ms.assetid: 399802e7-dd13-4bb6-9b41-8ab1446a322c +caps.latest.revision: 34 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Visual C# Breaking Changes in Visual Studio 2013 +No changes in Visual C# in [!INCLUDE[vs_dev12](../../csharp/getting-started/includes/vs_dev12_md.md)] will prevent an application that was created in Visual C# in Visual Studio 2012 from compiling or change the run-time behavior of such an application. + +## See Also + [Getting Started with C#](../../csharp/getting-started/getting-started-with-csharp.md) + [Lambda Expressions](../../csharp/programming-guide/statements-expressions-operators/lambda-expressions.md) + [Named and Optional Arguments](../../csharp/programming-guide/classes-and-structs/named-and-optional-arguments.md) + [params](../../csharp/language-reference/keywords/params.md) + [dynamic](../../csharp/language-reference/keywords/dynamic.md) + [When is a non-breaking language fix breaking?](http://go.microsoft.com/fwlink/?LinkId=259542) \ No newline at end of file diff --git a/docs/csharp/getting-started/getting-started-with-csharp.md b/docs/csharp/getting-started/getting-started-with-csharp.md new file mode 100644 index 0000000000000..549dd3cf5daa7 --- /dev/null +++ b/docs/csharp/getting-started/getting-started-with-csharp.md @@ -0,0 +1,69 @@ +--- +title: "Getting Started with C# | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "article" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "Visual C#, getting started" + - "getting started, Visual C#" +ms.assetid: d6ec050f-3956-4737-8030-a4fa3521d29f +caps.latest.revision: 50 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Getting Started with C# +The following topics help you start developing applications by using C#. These topics will also introduce you to the many new features in Visual Studio and the C# language. + +## In This Section + [Visual C# Breaking Changes in Visual Studio 2013](../../csharp/getting-started/breaking-changes-in-visual-studio-2013.md) + Lists breaking changes in the C# compiler since the previous version. + + [Introduction to the C# Language and the .NET Framework](../../csharp/getting-started/introduction-to-the-csharp-language-and-the-net-framework.md) + Provides an overview of the C# language and the .NET platform. + + [Additional Resources for Visual C# Programmers](../../csharp/getting-started/additional-resources.md) + Provides links to Web sites and newsgroups that can help you find answers to common problems. + +## Related Sections + [Using the Visual Studio Development Environment for C#](/visualstudio/csharp-ide/using-the-visual-studio-development-environment-for-csharp) + Provides a guide to using the [!INCLUDE[csprcs](../../csharp/includes/csprcs_md.md)] integrated development environment. + + [C# Programming Guide](../../csharp/programming-guide/index.md) + Provides information about C# programming concepts, and describes how to perform various tasks in C#. + + [C# Reference](../../csharp/language-reference/index.md) + Provides detailed reference information about C# keywords, operators, preprocessor directives, compiler options, and compiler errors and warnings. + + [Visual Studio Samples](/visualstudio/ide/visual-studio-samples) + Provides information about how you can access online samples. + + [Walkthroughs](../../csharp/walkthroughs.md) + Provides links to programming walkthroughs that use C# and a brief description of each walkthrough. + +## See Also + [Getting Started with Visual C# and Visual Basic](/visualstudio/ide/getting-started-with-visual-csharp-and-visual-basic) + [Beginner Developer Learning Center](http://go.microsoft.com/fwlink/?LinkId=123826) \ No newline at end of file diff --git a/docs/csharp/getting-started/includes/csprcsxpr_md.md b/docs/csharp/getting-started/includes/csprcsxpr_md.md new file mode 100644 index 0000000000000..3c8c7d32df23f --- /dev/null +++ b/docs/csharp/getting-started/includes/csprcsxpr_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +Visual C# Express \ No newline at end of file diff --git a/docs/csharp/getting-started/includes/dnprdnshort_md.md b/docs/csharp/getting-started/includes/dnprdnshort_md.md new file mode 100644 index 0000000000000..5edf6f3463fd0 --- /dev/null +++ b/docs/csharp/getting-started/includes/dnprdnshort_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +.NET Framework \ No newline at end of file diff --git a/docs/csharp/getting-started/includes/vbteclinqext_md.md b/docs/csharp/getting-started/includes/vbteclinqext_md.md new file mode 100644 index 0000000000000..b77a9c278762b --- /dev/null +++ b/docs/csharp/getting-started/includes/vbteclinqext_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +Language-Integrated Query (LINQ) \ No newline at end of file diff --git a/docs/csharp/getting-started/includes/vs_dev12_md.md b/docs/csharp/getting-started/includes/vs_dev12_md.md new file mode 100644 index 0000000000000..efa421ccc6dda --- /dev/null +++ b/docs/csharp/getting-started/includes/vs_dev12_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +Visual Studio 2013 \ No newline at end of file diff --git a/docs/csharp/getting-started/index.md b/docs/csharp/getting-started/index.md index c2af200cc38ec..c7e85bca2467a 100644 --- a/docs/csharp/getting-started/index.md +++ b/docs/csharp/getting-started/index.md @@ -13,7 +13,7 @@ ms.assetid: b77c7263-7cbf-4729-9626-8fbc3f5f14d9 --- -# 🔧 Getting started +# Getting started > **Note** > diff --git a/docs/csharp/getting-started/introduction-to-the-csharp-language-and-the-net-framework.md b/docs/csharp/getting-started/introduction-to-the-csharp-language-and-the-net-framework.md new file mode 100644 index 0000000000000..c8d4827f69338 --- /dev/null +++ b/docs/csharp/getting-started/introduction-to-the-csharp-language-and-the-net-framework.md @@ -0,0 +1,100 @@ +--- +title: "Introduction to the C# Language and the .NET Framework | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "article" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "C# language, about C# language" + - "Visual C#, about" +ms.assetid: 0a2dff4e-cd84-42ff-8141-e89889b24081 +caps.latest.revision: 32 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Introduction to the C# Language and the .NET Framework +C# is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the [!INCLUDE[dnprdnshort](../../csharp/getting-started/includes/dnprdnshort_md.md)]. You can use C# to create Windows client applications, XML Web services, distributed components, client-server applications, database applications, and much, much more. Visual C# provides an advanced code editor, convenient user interface designers, integrated debugger, and many other tools to make it easier to develop applications based on the C# language and the [!INCLUDE[dnprdnshort](../../csharp/getting-started/includes/dnprdnshort_md.md)]. + +> [!NOTE] +> The [!INCLUDE[csprcs](../../csharp/includes/csprcs_md.md)] documentation assumes that you have an understanding of basic programming concepts. If you are a complete beginner, you might want to explore [!INCLUDE[csprcsxpr](../../csharp/getting-started/includes/csprcsxpr_md.md)], which is available on the Web. You can also take advantage of books and Web resources about C# to learn practical programming skills. + +## C# Language + C# syntax is highly expressive, yet it is also simple and easy to learn. The curly-brace syntax of C# will be instantly recognizable to anyone familiar with C, C++ or Java. Developers who know any of these languages are typically able to begin to work productively in C# within a very short time. C# syntax simplifies many of the complexities of C++ and provides powerful features such as nullable value types, enumerations, delegates, lambda expressions and direct memory access, which are not found in Java. C# supports generic methods and types, which provide increased type safety and performance, and iterators, which enable implementers of collection classes to define custom iteration behaviors that are simple to use by client code. [!INCLUDE[vbteclinqext](../../csharp/getting-started/includes/vbteclinqext_md.md)] expressions make the strongly-typed query a first-class language construct. + + As an object-oriented language, C# supports the concepts of encapsulation, inheritance, and polymorphism. All variables and methods, including the `Main` method, the application's entry point, are encapsulated within class definitions. A class may inherit directly from one parent class, but it may implement any number of interfaces. Methods that override virtual methods in a parent class require the `override` keyword as a way to avoid accidental redefinition. In C#, a struct is like a lightweight class; it is a stack-allocated type that can implement interfaces but does not support inheritance. + + In addition to these basic object-oriented principles, C# makes it easy to develop software components through several innovative language constructs, including the following: + +- Encapsulated method signatures called *delegates*, which enable type-safe event notifications. + +- Properties, which serve as accessors for private member variables. + +- Attributes, which provide declarative metadata about types at run time. + +- Inline XML documentation comments. + +- [!INCLUDE[vbteclinqext](../../csharp/getting-started/includes/vbteclinqext_md.md)] which provides built-in query capabilities across a variety of data sources. + + If you have to interact with other Windows software such as COM objects or native Win32 DLLs, you can do this in C# through a process called "Interop." Interop enables C# programs to do almost anything that a native C++ application can do. C# even supports pointers and the concept of "unsafe" code for those cases in which direct memory access is absolutely critical. + + The C# build process is simple compared to C and C++ and more flexible than in Java. There are no separate header files, and no requirement that methods and types be declared in a particular order. A C# source file may define any number of classes, structs, interfaces, and events. + + The following are additional C# resources: + +- For a good general introduction to the language, see Chapter 1 of the [C# Language Specification](../../csharp/language-reference/language-specification.md). + +- For detailed information about specific aspects of the C# language, see the [C# Reference](../../csharp/language-reference/index.md). + +- For more information about [!INCLUDE[vbteclinq](../../csharp/includes/vbteclinq_md.md)], see [LINQ (Language-Integrated Query)](http://msdn.microsoft.com/library/a73c4aec-5d15-4e98-b962-1274021ea93d). + +- To find the latest articles and resources from the Visual C# team, see the [Visual C# Developer Center](http://go.microsoft.com/fwlink/?LinkId=47811). + +## .NET Framework Platform Architecture + C# programs run on the [!INCLUDE[dnprdnshort](../../csharp/getting-started/includes/dnprdnshort_md.md)], an integral component of Windows that includes a virtual execution system called the common language runtime (CLR) and a unified set of class libraries. The CLR is the commercial implementation by Microsoft of the common language infrastructure (CLI), an international standard that is the basis for creating execution and development environments in which languages and libraries work together seamlessly. + + Source code written in C# is compiled into an intermediate language (IL) that conforms to the CLI specification. The IL code and resources, such as bitmaps and strings, are stored on disk in an executable file called an assembly, typically with an extension of .exe or .dll. An assembly contains a manifest that provides information about the assembly's types, version, culture, and security requirements. + + When the C# program is executed, the assembly is loaded into the CLR, which might take various actions based on the information in the manifest. Then, if the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions. The CLR also provides other services related to automatic garbage collection, exception handling, and resource management. Code that is executed by the CLR is sometimes referred to as "managed code," in contrast to "unmanaged code" which is compiled into native machine language that targets a specific system. The following diagram illustrates the compile-time and run-time relationships of C# source code files, the .NET Framework class libraries, assemblies, and the CLR. + + ![From C# source code to machine execution](../../csharp/getting-started/media/netarchitecture.png "NETarchitecture") + + Language interoperability is a key feature of the [!INCLUDE[dnprdnshort](../../csharp/getting-started/includes/dnprdnshort_md.md)]. Because the IL code produced by the C# compiler conforms to the Common Type Specification (CTS), IL code generated from C# can interact with code that was generated from the .NET versions of Visual Basic, Visual C++, or any of more than 20 other CTS-compliant languages. A single assembly may contain multiple modules written in different .NET languages, and the types can reference each other just as if they were written in the same language. + + In addition to the run time services, the [!INCLUDE[dnprdnshort](../../csharp/getting-started/includes/dnprdnshort_md.md)] also includes an extensive library of over 4000 classes organized into namespaces that provide a wide variety of useful functionality for everything from file input and output to string manipulation to XML parsing, to Windows Forms controls. The typical C# application uses the [!INCLUDE[dnprdnshort](../../csharp/getting-started/includes/dnprdnshort_md.md)] class library extensively to handle common "plumbing" chores. + + For more information about the .NET Framework, see [Overview of the Microsoft .NET Framework](http://msdn.microsoft.com/en-us/d05daf50-00fe-45c7-8383-06fe41697355). + +## Featured Book Chapters + [C# Language Fundamentals](http://go.microsoft.com/fwlink/?LinkId=195416) in [Learning C# 3.0: Master the fundamentals of C# 3.0](http://go.microsoft.com/fwlink/?LinkId=195412) + + [C# and .NET Programming](http://go.microsoft.com/fwlink/?LinkId=195413) in [Learning C# 3.0: Master the fundamentals of C# 3.0](http://go.microsoft.com/fwlink/?LinkId=195412) + + [Introducing C#](http://go.microsoft.com/fwlink/?LinkId=221226) in [Beginning Visual C# 2010](http://go.microsoft.com/fwlink/?LinkId=221214) + + [Visual Studio 2008 and C# Express 2008](http://go.microsoft.com/fwlink/?LinkId=195414) in [Learning C# 3.0: Master the fundamentals of C# 3.0](http://go.microsoft.com/fwlink/?LinkId=195412) + +## See Also + [C#](../../csharp/csharp.md) + [Getting Started with Visual C# and Visual Basic](/visualstudio/ide/getting-started-with-visual-csharp-and-visual-basic) \ No newline at end of file diff --git a/docs/csharp/getting-started/media/netarchitecture.png b/docs/csharp/getting-started/media/netarchitecture.png new file mode 100644 index 0000000000000..174571e03e542 Binary files /dev/null and b/docs/csharp/getting-started/media/netarchitecture.png differ diff --git a/docs/csharp/getting-started/whats-new.md b/docs/csharp/getting-started/whats-new.md new file mode 100644 index 0000000000000..8774fdbb1876c --- /dev/null +++ b/docs/csharp/getting-started/whats-new.md @@ -0,0 +1,100 @@ +--- +title: "What's New for Visual C# | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "article" +dev_langs: + - "CSharp" +ms.assetid: 9f18dc26-27fa-4603-a639-b573f07a117b +caps.latest.revision: 39 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# What's New for Visual C# +This page lists key feature names for each version of C# with descriptions of the new and enhanced features in the lastest version of the language. + +## Previous Versions + C# 1, Visual Studio .NET 2002 + First release + + C# 1.1, Visual Studio .NET 2003 + `#line` pragma and xml doc comments + + C# 2, Visual Studio .NET 2005 + Anonymous methods, generics, nullable types, iterators/yield, `static` classes, co/contra variance for delegates + + C# 3, Visual Studio .NET 2008 + Object and collection initializers, lambda expressions, extension methods, anonymous types, automatic properties, Language Integrated Query (LINQ), anonymous types, local `var` type inference, LINQ + + C# 4, Visual Studio .NET 2010 + `Dynamic`, named arguments, optional parameters, generic co/contra variance + + C# 5, Visual Studio .NET 2012 + `Async` / `await`, caller information attributes + + Visual Studio .NET 2013 + Bug fixes, performance improvements, and technology previews of .NET Compiler Platform (“Roslyn”) + + C# 6, Visual Studio .NET 2015 + Current version, see below + +## Current Version + [nameof](../../csharp/language-reference/keywords/nameof.md) + You can get the unqualified string name of a type or member for use in an error message without hard coding a string. This allows your code to remain correct when refactoring. This feature is also useful for hooking up model-view-controller MVC links and firing property changed events. + + [String Interpolation](../../csharp/language-reference/keywords/interpolated-strings.md) + You can use string interpolation expressions to construct strings. An interpolated string expression looks like a template string that contains expressions. C# creates a string by replacing the expressions with the ToString represenations of the expressions’ results. An interpolated string is easier to understand with respect to arguments than [Composite Formatting](http://msdn.microsoft.com/library/87b7d528-73f6-43c6-b71a-f23043039a49). + + [Null-conditional Member Access and Indexing](../../csharp/language-reference/operators/null-conditional-operators.md) + You can test for null in a very light syntactic way before performing a member access (`?.`) or index (`?[]`) operation. These operators help you write less code to handle null checks, especially for descending into data structures. If the left operand or object reference is null, the operations returns null. + + [Index Initializers](../../csharp/programming-guide/classes-and-structs/object-and-collection-initializers.md) + You can now initialize specific elements of a collection that supports indexing, such as initializing a dictionary. + + [Collection Initializer and Add Extension Methods](../../csharp/programming-guide/classes-and-structs/object-and-collection-initializers.md) + You can use initializers for collections now when the collection has an Add Extension method. Previously the Add method had to be an instance method. + + **Overload Resolution** + The compiler has improved overload resolution that results in more code just working the way you would expect it to behave. One place where you might stop noticing a problem is when choosing between overloads taking nullable value types, or when passing method groups (instead of lambdas) to overloads that take delegates. + + [Exception Filters](../../csharp/language-reference/keywords/try-catch.md) + You can use exception filers in `catch` clauses to determine whether a catch clause should handle the exception. Without this feature, you have to rethrow the exception, which clips the call stack reported in the rethrown exception. + + [Await in Catch and Finally Blocks](../../csharp/language-reference/keywords/try-catch.md) + You can use `await` in `catch` and `finally` clauses. + + [Auto-property Initializers](../../csharp/programming-guide/classes-and-structs/auto-implemented-properties.md) + You can initialize auto-properties now similarly to how you initialize fields. + + [Getter-only Auto-properites](../../csharp/programming-guide/classes-and-structs/auto-implemented-properties.md) + You can define read-only auto-properties now without having to define a property with complete property syntax. You can initialize the property where you declare it or in the type’s constructor. + + **Function Members with Expression Bodies** + You can declare members with expression-bodies of code in the same lightweight syntax you use with lambda expressions. See [Methods](../../csharp/programming-guide/classes-and-structs/methods.md), [Properties](../../csharp/programming-guide/classes-and-structs/properties.md), [Indexers](../../csharp/programming-guide/indexers/index.md), and [Overloadable Operators](../../csharp/programming-guide/statements-expressions-operators/overloadable-operators.md). + + [Using Static](../../csharp/language-reference/keywords/using-directive.md) + You can import accessible static members of static types so that you can refer to the members without qualifying the access with the type’s name. + +## See Also + [What's New in Visual Studio 2015](/visualstudio/ide/what-s-new-in-visual-studio-2015) \ No newline at end of file diff --git a/docs/csharp/includes/csprcs_md.md b/docs/csharp/includes/csprcs_md.md new file mode 100644 index 0000000000000..71d63006f278b --- /dev/null +++ b/docs/csharp/includes/csprcs_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +Visual C# \ No newline at end of file diff --git a/docs/csharp/includes/vbtecdlinq_md.md b/docs/csharp/includes/vbtecdlinq_md.md new file mode 100644 index 0000000000000..88250d0caf3a4 --- /dev/null +++ b/docs/csharp/includes/vbtecdlinq_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +LINQ to SQL \ No newline at end of file diff --git a/docs/csharp/includes/vbteclinq_md.md b/docs/csharp/includes/vbteclinq_md.md new file mode 100644 index 0000000000000..d24982b4b045a --- /dev/null +++ b/docs/csharp/includes/vbteclinq_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +LINQ \ No newline at end of file diff --git a/docs/csharp/includes/vs_dev11_long_md.md b/docs/csharp/includes/vs_dev11_long_md.md new file mode 100644 index 0000000000000..b422542b1dfd6 --- /dev/null +++ b/docs/csharp/includes/vs_dev11_long_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +Visual Studio 2012 \ No newline at end of file diff --git a/docs/csharp/includes/vsprvs_md.md b/docs/csharp/includes/vsprvs_md.md new file mode 100644 index 0000000000000..bc46fcad8dc99 --- /dev/null +++ b/docs/csharp/includes/vsprvs_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +Visual Studio \ No newline at end of file diff --git a/docs/csharp/includes/win8_appname_long_md.md b/docs/csharp/includes/win8_appname_long_md.md new file mode 100644 index 0000000000000..10f8dcf96bbe5 --- /dev/null +++ b/docs/csharp/includes/win8_appname_long_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +Windows 8.x Store \ No newline at end of file diff --git a/docs/csharp/includes/wrt_md.md b/docs/csharp/includes/wrt_md.md new file mode 100644 index 0000000000000..be177d7661078 --- /dev/null +++ b/docs/csharp/includes/wrt_md.md @@ -0,0 +1,17 @@ +--- +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +Windows Runtime \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0001.md b/docs/csharp/language-reference/compiler-messages/cs0001.md new file mode 100644 index 0000000000000..fff756fc4dd05 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0001.md @@ -0,0 +1,41 @@ +--- +title: "Compiler Error CS0001 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0001" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0001" +ms.assetid: 5e4564df-ba1c-4d56-a71c-e383d7c3dda2 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0001 +Internal compiler error + + Try to determine whether the compiler is failing because of its inability to parse unexpected syntax. If you receive this error repeatedly, please contact Microsoft. \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0006.md b/docs/csharp/language-reference/compiler-messages/cs0006.md new file mode 100644 index 0000000000000..a03da6b7aedb8 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0006.md @@ -0,0 +1,41 @@ +--- +title: "Compiler Error CS0006 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0006" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0006" +ms.assetid: fe029a0e-d85a-4d8e-8a46-01f6120092fe +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0006 +Metadata file 'dll_name' could not be found + + The program was compiled and explicitly passed the name of a file that contained metadata; however, the .dll was not found. For more information, see [/reference (C# Compiler Options)](../../../csharp/language-reference/compiler-options/reference-compiler-option.md). \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0007.md b/docs/csharp/language-reference/compiler-messages/cs0007.md new file mode 100644 index 0000000000000..c3e702edb85cb --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0007.md @@ -0,0 +1,43 @@ +--- +title: "Compiler Error CS0007 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0007" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0007" +ms.assetid: d65849cf-2713-454a-b928-3c8aa8fc993e +caps.latest.revision: 6 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0007 +Unexpected common language runtime initialization error — 'description' + + This error occurs if the runtime could not be loaded. This could occur if the version of the common language runtime that the compiler attempts to load is not present on the machine, or if the common language runtime installation or configuration is corrupt. + + This can happen if the `csc.exe.config` file was changed. This file is configured during setup and should not be changed. If there is a possibility that the `csc.exe.config` file was changed, check the file to make sure that the version of the runtime specified in the file is present on the machine. If the correct version is present, it may be corrupted. Reinstall the common language runtime. \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0015.md b/docs/csharp/language-reference/compiler-messages/cs0015.md new file mode 100644 index 0000000000000..c2270c74b3ad8 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0015.md @@ -0,0 +1,69 @@ +--- +title: "Compiler Error CS0015 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0015" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0015" +ms.assetid: e9d3272b-2b80-435a-98ef-79bff158ae7b +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Error CS0015 +The name of type 'type' is too long + + The fully qualified name of a user-defined type must have fewer than 1024 characters, including the periods. + + The following sample generates CS0015: + +```cs +// CS0015.cs + +// Remove a C from one of the namespace names or the class name to resolve the error by +// reducing the number of characters in the qualified class name to fewer than 1024. + +namespace CC +{ + // The following namespace name has 510 characters. + namespace CCC510charsCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC + { + // The following class name has 510 characters. The qualified class name, + // CC.CCC510chars…C.CCCC510chars…C (namespace.namespace.class), has 1024 + // characters, which causes compiler error CS0015. + public class CCCC510charsCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC + { + public static void Main() + { + } + } + } +} + +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0016.md b/docs/csharp/language-reference/compiler-messages/cs0016.md new file mode 100644 index 0000000000000..9b00e28c2d7ba --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0016.md @@ -0,0 +1,41 @@ +--- +title: "Compiler Error CS0016 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0016" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0016" +ms.assetid: da62084c-7a18-4858-9034-d1fe099bf34c +caps.latest.revision: 6 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0016 +Could not write to output file 'file' — 'reason' + + The compiler could not write to an output file. Check the path to the file to make sure it exists. If a previously built file is already at the location, make sure it is writeable, and that no process currently has a lock on the file. For example,make sure your executable is not running when you attempt to build. \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0019.md b/docs/csharp/language-reference/compiler-messages/cs0019.md new file mode 100644 index 0000000000000..4ce59c7800667 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0019.md @@ -0,0 +1,101 @@ +--- +title: "Compiler Error CS0019 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0019" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0019" +ms.assetid: 5a25be41-535b-4850-a230-9a385e01fd20 +caps.latest.revision: 15 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0019 +Operator 'operator' cannot be applied to operands of type 'type' and 'type' + + A binary operator is applied to data types that do not support it. For example, you cannot use the [||](../../../csharp/language-reference/operators/conditional-or-operator.md) operator on strings, you cannot use [+](../../../csharp/language-reference/operators/addition-operator.md) , [-](../../../csharp/language-reference/operators/subtraction-operator.md) , [\<](../../../csharp/language-reference/operators/less-than-operator.md) , or [>](../../../csharp/language-reference/operators/greater-than-operator.md) operators on [bool](../../../csharp/language-reference/keywords/bool.md) variables, and you cannot use the [==](../../../csharp/language-reference/operators/equality-comparison-operator.md) operator with a `struct` type unless the type explicitly overloads that operator. + + If you encounter this error with a class type, it is because the class does not overload the operator. For more information, see [Overloadable Operators](../../../csharp/programming-guide/statements-expressions-operators/overloadable-operators.md). + +## Example + In the following example, CS0019 is generated in two places because [bool](../../../csharp/language-reference/keywords/bool.md) in C# is not convertible to [int](../../../csharp/language-reference/keywords/int.md). CS0019 also is generated when the subtraction operator is applied to a string. The addition operator (+) can be used with string operands because that operator is overloaded by the `String` class to perform string concatenation. + +``` +static void Main() +{ + bool result = true; + if (result > 0) //CS0019 + { + // Do something. + } + + int i = 1; + // You cannot compare an integer and a boolean value. + if (i == true) //CS0019 + { + //Do something... + } + + // The following use of == causes no error. It is the comparison of + // an integer and a boolean value that causes the error in the + // previous if statement. + if (result == true) + { + //Do something... + } + + string s = "Just try to subtract me."; + float f = 100 - s; // CS0019 +} + +``` + +## Example + In the following example, conditional logic must be specified outside the . You can pass only one predefined symbol to the . + + The following sample generates CS0019. + +``` +// CS0019_a.cs +// compile with: /target:library +using System.Diagnostics; +public class MyClass +{ + [ConditionalAttribute("DEBUG" || "TRACE")] // CS0019 + public void TestMethod() {} + + // OK + [ConditionalAttribute("DEBUG"), ConditionalAttribute("TRACE")] + public void TestMethod2() {} +} + +``` + +## See Also + [Operators](../../../csharp/programming-guide/statements-expressions-operators/operators.md) + [Implicit Numeric Conversions Table](../../../csharp/language-reference/keywords/implicit-numeric-conversions-table.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0029.md b/docs/csharp/language-reference/compiler-messages/cs0029.md new file mode 100644 index 0000000000000..baf84a2ef4255 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0029.md @@ -0,0 +1,110 @@ +--- +title: "Compiler Error CS0029 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0029" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0029" +ms.assetid: 63c3e574-1868-4a9e-923e-dcd9f38bce88 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0029 +Cannot implicitly convert type 'type' to 'type' + + The compiler requires an explicit conversion. For example, you may need to cast an r-value to be the same type as an l-value. Or, you must provide conversion routines to support certain operator overloads. + + Conversions must occur when assigning a variable of one type to a variable of a different type. When making an assignment between variables of different types, the compiler must convert the type on the right-hand side of the assignment operator to the type on the left-hand side of the assignment operator. Take the following the code: + +``` +int i = 50; +long lng = 100; +i = lng; +``` + + `i = lng;` makes an assignment, but the data types of the variables on the left and right-hand side of the assignment operator don't match. Before making the assignment the compiler is implicitly converting the variable `lng`, which is of type long, to an int. This is implicit because no code explicitly instructed the compiler to perform this conversion. The problem with this code is that this is considered a narrowing conversion, and the compiler does not allow implicit narrowing conversions because there could be a potential loss of data. + + A narrowing conversion exists when converting to a data type that occupies less storage space in memory than the data type we are converting from. For example, converting a long to an int would be considered a narrowing conversion. A long occupies 8 bytes of memory while an int occupies 4 bytes. To see how data loss can occur, consider the following sample: + +``` +int i = 50; +long lng = 3147483647; +i = lng; +``` + + The variable `lng` now contains a value that cannot be stored in the variable `i` because it is too large. If we were to convert this value to an int type we would be losing some of our data and the converted value would not be the same as the value before the conversion. + + A widening conversion would be the opposite of a narrowing conversion. With widening conversions, we are converting to a data type that occupies more storage space in memory than the data type we are converting from. Here is an example of a widening conversion: + +``` +int i = 50; +long lng = 100; +lng = i; +``` + + Notice the difference between this code sample and the first. This time the variable `lng` is on the left-hand side of the assignment operator, so it is the target of our assignment. Before the assignment can be made, the compiler must implicitly convert the variable `i`, which is of type int, to type long. This is a widening conversion since we are converting from a type that occupies 4 bytes of memory (an int) to a type that occupies 8 bytes of memory (a long). Implicit widening conversions are allowed because there is no potential loss of data. Any value that can be stored in an int can also be stored in a long. + + We know that implicit narrowing conversions are not allowed, so to be able to compile this code we need to explicitly convert the data type. Explicit conversions are done using casting. Casting is the term used in C# to describe converting one data type to another. To get the code to compile we would need to use the following syntax: + +``` +int i = 50; +long lng = 100; +i = (int) lng; // cast to int +``` + + The third line of code tells the compiler to explicitly convert the variable `lng`, which is of type long, to an int before making the assignment. Remember that with a narrowing conversion, there is a potential loss of data. Narrowing conversions should be used with caution and even though the code will compile you may get unexpected results at run-time. + + This discussion has only been for value types. When working with value types you work directly with the data stored in the variable. However, the .NET Framework also has reference types. When working with reference types you are working with a reference to a variable, not the actual data. Examples of reference types would be classes, interfaces and arrays. You cannot implicitly or explicitly convert one reference type to another unless the compiler allows the specific conversion or the appropriate conversion operators are implemented. + + The following sample generates CS0029: + +``` +// CS0029.cs +public class MyInt +{ + private int x = 0; + + // Uncomment this conversion routine to resolve CS0029 + /* + public static implicit operator int(MyInt i) + { + return i.x; + } + */ + + public static void Main() + { + MyInt myInt = new MyInt(); + int i = myInt; // CS0029 + } +} +``` + +## See Also + [Conversion Operators](../../../csharp/programming-guide/statements-expressions-operators/conversion-operators.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0034.md b/docs/csharp/language-reference/compiler-messages/cs0034.md new file mode 100644 index 0000000000000..238aa1e202308 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0034.md @@ -0,0 +1,133 @@ +--- +title: "Compiler Error CS0034 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0034" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0034" +ms.assetid: cb72ec9b-3a6b-40f3-b2ad-2ea122920edd +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0034 +Operator 'operator' is ambiguous on operands of type 'type1' and 'type2' + + An operator was used on two objects and the compiler found more than one conversion. Because conversions have to be unique, you either have to make a cast or to make one of the conversions explicit. For more information, see [Conversion Operators](../../../csharp/programming-guide/statements-expressions-operators/conversion-operators.md). + + The following sample generates CS0034: + +``` +// CS0034.cs +public class A +{ + // allows for the conversion of A object to int + public static implicit operator int (A s) + { + return 0; + } + + public static implicit operator string (A i) + { + return null; + } +} + +public class B +{ + public static implicit operator int (B s) + // one way to resolve this CS0034 is to make one conversion explicit + // public static explicit operator int (B s) + { + return 0; + } + + public static implicit operator string (B i) + { + return null; + } + + public static implicit operator B (string i) + { + return null; + } + + public static implicit operator B (int i) + { + return null; + } +} + +public class C +{ + public static void Main () + { + A a = new A(); + B b = new B(); + b = b + a; // CS0034 + // another way to resolve this CS0034 is to make a cast + // b = b + (int)a; + } +} +``` + + In C# 1.1 a compiler bug made it possible to define a class that has implicit user-defined conversions to both `int` and `bool`, and to use a bitwise `AND` operator (`&`) on objects of that type. In C# 2.0, this bug was fixed to bring the compiler into compliance with the C# specification, and therefore the following code will now cause CS0034: + +``` +namespace CS0034 +{ + class TestClass2 + { + public void Test() + { + TestClass o1 = new TestClass(); + TestClass o2 = new TestClass(); + TestClass o3 = o1 & o2; //CS0034 + } + } + + class TestClass + { + public static implicit operator int(TestClass o) + { + return 1; + } + + public static implicit operator TestClass(int v) + { + return new TestClass(); + } + + public static implicit operator bool(TestClass o) + { + return true; + } + } + +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0038.md b/docs/csharp/language-reference/compiler-messages/cs0038.md new file mode 100644 index 0000000000000..efadf63068d08 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0038.md @@ -0,0 +1,68 @@ +--- +title: "Compiler Error CS0038 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0038" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0038" +ms.assetid: ed378c79-c31b-4373-adfa-ee5dd2dccc9e +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0038 +Cannot access a nonstatic member of outer type 'type1' via nested type 'type2' + + A field in a class is not automatically available to a nested class. To be available to a nested class, the field must be [static](../../../csharp/language-reference/keywords/static.md). Otherwise, you must create an instance of the outer class. For more information, see [Nested Types](../../../csharp/programming-guide/classes-and-structs/nested-types.md). + + The following sample generates CS0038: + +``` +// CS0038.cs +class OuterClass +{ + public int count; + // try the following line instead + // public static int count; + + class InnerClass + { + void func() + { + // or, create an instance + // OuterClass class_inst = new OuterClass(); + // int count2 = class_inst.count; + int count2 = count; // CS0038 + } + } + + public static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0039.md b/docs/csharp/language-reference/compiler-messages/cs0039.md new file mode 100644 index 0000000000000..013410829a3f7 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0039.md @@ -0,0 +1,75 @@ +--- +title: "Compiler Error CS0039 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0039" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0039" +ms.assetid: f9fcb1c5-4ea4-41f3-826e-9ab0ac43dd3e +caps.latest.revision: 17 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0039 +Cannot convert type 'type1' to 'type2' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion + + A conversion with the [as](../../../csharp/language-reference/keywords/as.md) operator is allowed by inheritance, reference conversions, and boxing conversions. For more information, see [Conversion Operators](../../../csharp/programming-guide/statements-expressions-operators/conversion-operators.md). + +## Example + The following example generates CS0039. + +``` +// CS0039.cs +using System; +class A +{ +} +class B: A +{ +} +class C: A +{ +} +class M +{ + static void Main() + { + A a = new C(); + B b = new B(); + C c; + + // This is valid; there is a built-in reference + // conversion from A to C. + c = a as C; + + //The following generates CS0039; there is no + // built-in reference conversion from B to C. + c = b as C; // CS0039 + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0050.md b/docs/csharp/language-reference/compiler-messages/cs0050.md new file mode 100644 index 0000000000000..7215904af2a8c --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0050.md @@ -0,0 +1,63 @@ +--- +title: "Compiler Error CS0050 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0050" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0050" +ms.assetid: dead2d28-f4db-4afe-b8dd-38968625f7c3 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0050 +Inconsistent accessibility: return type 'type' is less accessible than method 'method' + + The return type and each of the types referenced in the formal parameter list of a method must be at least as accessible as the method itself. For more information, see [Access Modifiers](../../../csharp/programming-guide/classes-and-structs/access-modifiers.md). + +## Example + The following sample generates CS0050 because no accessiblity modifier is supplied for `MyClass` and its accessibility therefore defaults to `private`. + +``` +// CS0050.cs +class MyClass //accessibility defaults to private +// try the following line instead +// public class MyClass +{ +} + +public class MyClass2 +{ + public static MyClass MyMethod() // CS0050 + { + return new MyClass(); + } + + public static void Main() { } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0051.md b/docs/csharp/language-reference/compiler-messages/cs0051.md new file mode 100644 index 0000000000000..03892e14dbdd5 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0051.md @@ -0,0 +1,64 @@ +--- +title: "Compiler Error CS0051 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0051" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0051" +ms.assetid: 62182e8d-c4a5-4853-a990-fd57a4f7c3b8 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0051 +Inconsistent accessibility: parameter type 'type' is less accessible than method 'method' + + The return type and each of the types referenced in the formal parameter list of a method must be at least as accessible as the method itself. Make sure the types used in method signatures are not accidentally private due to the omission of the `public` modifier. For more information, see [Access Modifiers](../../../csharp/programming-guide/classes-and-structs/access-modifiers.md). + +## Example + The following sample generates CS0051: + +``` +// CS0051.cs +public class A +{ + // Try making B public since F is public + // B is implicitly private here + class B + { + } + + public static void F(B b) // CS0051 + { + } + + public static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0052.md b/docs/csharp/language-reference/compiler-messages/cs0052.md new file mode 100644 index 0000000000000..875883ea6f7f0 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0052.md @@ -0,0 +1,77 @@ +--- +title: "Compiler Error CS0052 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0052" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0052" +ms.assetid: 3beed1c9-f482-4a48-b98d-b9fdc279b9d7 +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0052 +Inconsistent accessibility: field type 'type' is less accessible than field 'field' + + The type of a field cannot be less accessible than the field itself because all public constructs must return a publicly accessible object. + +## Example + The following sample generates CS0052: + +```cs +// CS0052.cs +public class MyClass2 +{ + // The following line causes an error because the field, M, is declared + // as public, but the type, MyClass, is private. Therefore the type is + // less accessible than the field. + public MyClass M; // CS0052 + + private class MyClass + { + } + // One way to resolve the error is to change the accessibility of the type + // to public. + //public class MyClass + // Another solution is to change the accessibility of the field to private. + // private MyClass M; +} + + public class MainClass + { + public static void Main() + { + } + } +``` + +## See Also + [C# Keywords](../../../csharp/language-reference/keywords/index.md) + [Access Modifiers](../../../csharp/language-reference/keywords/access-modifiers.md) + [Accessibility Levels](../../../csharp/language-reference/keywords/accessibility-levels.md) + [Modifiers](../../../csharp/language-reference/keywords/modifiers.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0071.md b/docs/csharp/language-reference/compiler-messages/cs0071.md new file mode 100644 index 0000000000000..64c0549643d35 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0071.md @@ -0,0 +1,77 @@ +--- +title: "Compiler Error CS0071 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0071" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0071" +ms.assetid: 787cbeae-fb2b-455a-ba10-811b956ed170 +caps.latest.revision: 14 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0071 +An explicit interface implementation of an event must use event accessor syntax + + When explicitly implementing an [event](../../../csharp/language-reference/keywords/event.md) that was declared in an interface, you must use manually provide the `add` and `remove` event accessors that are typically provided by the compiler. The accessor code can connect the interface event to another event in your class (shown later in this topic), or to its own delegate type. For more information, see [How to: Implement Interface Events](../../../csharp/programming-guide/events/how-to-implement-interface-events.md). + +## Example + The following sample generates CS0071. + +``` +// CS0071.cs +public delegate void MyEvent(object sender); + +interface ITest +{ + event MyEvent Clicked; +} + +class Test : Itest +{ + event MyEvent ITest.Clicked; // CS0071 + + // try the following code instead +/* +private MyEvent clicked; + + event MyEvent Itest.Clicked + { + add + { + clicked += value; + } + remove + { + clicked -= value; + } + } +*/ + public static void Main() { } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0103.md b/docs/csharp/language-reference/compiler-messages/cs0103.md new file mode 100644 index 0000000000000..883398f5e84ab --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0103.md @@ -0,0 +1,99 @@ +--- +title: "Compiler Error CS0103 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0103" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0103" +ms.assetid: fd1f2104-a945-4dba-8137-8ef869826062 +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0103 +The name 'identifier' does not exist in the current context + + An attempt was made to use a name that does not exist in the class, [namespace](../../../csharp/language-reference/keywords/namespace.md), or scope. Check the spelling of the name and check your using directives and assembly references to make sure that the name that you are trying to use is available. + + This error frequently occurs if you declare a variable in a loop or a `try` or `if` block and then attempt to access it from an enclosing code block or a separate code block, as shown in the following example. + +```cs +using System; + +class MyClass1 +{ + public static void Main() + { + try + { + // The following declaration is only available inside the try block. + MyClass1 conn = new MyClass1(); + } + catch (Exception e) + { + // The following expression causes error CS0103, because variable + // conn only exists in the try block. + if (conn != null) + Console.WriteLine("{0}", e); + } + } +} + +``` + + The following example resolves the error. + +```cs + +using System; + +class MyClass2 +{ + public static void Main() + { + // To resolve the error in the example, the first step is to + // move the declaration of conn out of the try block. The following + // declaration is available throughout the Main method. + MyClass2 conn = null; + try + { + // Inside the try block, use the conn variable that you declared + // previously. + conn = new MyClass2(); + } + catch (Exception e) + { + // The following expression no longer causes an error, because + // the declaration of conn is in scope. + if (conn != null) + Console.WriteLine("{0}", e); + } + } +} + +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0106.md b/docs/csharp/language-reference/compiler-messages/cs0106.md new file mode 100644 index 0000000000000..d4afedfe2bd64 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0106.md @@ -0,0 +1,72 @@ +--- +title: "Compiler Error CS0106 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0106" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0106" +ms.assetid: 8dec906a-ed69-4ed5-aa61-c8600d138200 +caps.latest.revision: 16 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0106 +The modifier 'modifier' is not valid for this item + + A class or interface member was marked with an invalid access modifier. The following examples describe some of these invalid modifiers: + +- The [static](../../../csharp/language-reference/keywords/static.md) and [public](../../../csharp/language-reference/keywords/public.md) modifiers are not permitted on interface methods. + +- The `public` keyword is not allowed on an explicit interface declaration. In this case, remove the `public` keyword from the explicit interface declaration. + +- The [abstract](../../../csharp/language-reference/keywords/abstract.md) keyword is not allowed on an explicit interface declaration because an explicit interface implementation can never be overridden. + + In prior releases of Visual Studio, the `static` modifier was not permitted on a class, but `static` classes are allowed starting with [!INCLUDE[vsprvsext](../../../csharp/language-reference/compiler-messages/includes/vsprvsext_md.md)]. + + For more information, see [Interfaces](../../../csharp/programming-guide/interfaces/index.md) + +## Example + The following sample generates CS0106. + +``` +// CS0106.cs +namespace MyNamespace +{ + interface I + { + void m(); + static public void f(); // CS0106 + } + + public class MyClass + { + public void I.m() {} // CS0106 + public static void Main() {} + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0108.md b/docs/csharp/language-reference/compiler-messages/cs0108.md new file mode 100644 index 0000000000000..3bd9817e19042 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0108.md @@ -0,0 +1,73 @@ +--- +title: "Compiler Warning (level 2) CS0108 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0108" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0108" +ms.assetid: 04330ed2-80d5-4bf2-b0c1-a0c2bec03074 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 2) CS0108 +'member1' hides inherited member 'member2'. Use the new keyword if hiding was intended. + + A variable was declared with the same name as a variable in a base class. However, the [new](../../../csharp/language-reference/keywords/new.md) keyword was not used. This warning informs you that you should use **new**; the variable is declared as if **new** had been used in the declaration. + + The following sample generates CS0108: + +``` +// CS0108.cs +// compile with: /W:2 +using System; + +namespace x +{ + public class clx + { + public int i = 1; + } + + public class cly : clx + { + public static int i = 2; // CS0108, use the new keyword + // Use the following line instead: + // public static new int i = 2; + + public static void Main() + { + Console.WriteLine(i); + } + } +} +``` + +## See Also + [new Modifier](../../../csharp/language-reference/keywords/new-modifier.md) + [new](../../../csharp/language-reference/keywords/new.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0115.md b/docs/csharp/language-reference/compiler-messages/cs0115.md new file mode 100644 index 0000000000000..45be0d9de97b8 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0115.md @@ -0,0 +1,71 @@ +--- +title: "Compiler Error CS0115 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0115" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0115" +ms.assetid: a0e4bd8a-a6c2-4568-8ea5-8bb1d2ad0e95 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0115 +'function' : no suitable method found to override + + A method was marked as an override, but the compiler found no method to override. For more information, see [override](../../../csharp/language-reference/keywords/override.md), and [Knowing When to Use Override and New Keywords](../../../csharp/programming-guide/classes-and-structs/knowing-when-to-use-override-and-new-keywords.md). + +## Example + The following sample generates CS0115. You can resolve CS0115 in one of two ways: + +- Remove the `override` keyword from the method in `MyClass2`. + +- Use `MyClass1` as a base class for `MyClass2`. + +``` +// CS0115.cs +namespace MyNamespace +{ + abstract public class MyClass1 + { + public abstract int f(); + } + + abstract public class MyClass2 + { + public override int f() // CS0115 + { + return 0; + } + + public static void Main() + { + } + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0116.md b/docs/csharp/language-reference/compiler-messages/cs0116.md new file mode 100644 index 0000000000000..4b02e5ff619f7 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0116.md @@ -0,0 +1,72 @@ +--- +title: "Compiler Error CS0116 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0116" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0116" +ms.assetid: 4cb137b5-ec29-4c1a-adde-9f8424cb9496 +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0116 +A namespace does not directly contain members such as fields or methods + + Inside a [namespace](../../../csharp/language-reference/keywords/namespace.md), the compiler only accepts classes, structures, unions, enumerations, interfaces, and delegates. This error is often generated by developers from a C/C++ background who forget that in C#, methods and variables must be declared and defined within a struct or class. For more information, see [General Structure of a C# Program](../../../csharp/programming-guide/inside-a-program/general-structure-of-a-csharp-program.md). + +## Example + The following sample generates CS0116: + +``` +// CS0116.cs +namespace x +{ + using System; + + // method must be in class/struct + void Method(string str) // CS0116 + { + Console.WriteLine(str); + } + // To fix the error, you must + // enclose a method in a class: + class Program + { + void Method2(string str) + { + Console.WriteLine(str); + } + } +} +``` + +## See Also + [General Structure of a C# Program](../../../csharp/programming-guide/inside-a-program/general-structure-of-a-csharp-program.md) + [Classes and Structs](../../../csharp/programming-guide/classes-and-structs/index.md) + [Namespaces](../../../csharp/programming-guide/namespaces/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0120.md b/docs/csharp/language-reference/compiler-messages/cs0120.md new file mode 100644 index 0000000000000..b5ed4a4ce91c5 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0120.md @@ -0,0 +1,124 @@ +--- +title: "Compiler Error CS0120 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0120" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0120" +ms.assetid: 3ff67f11-bdf9-436b-bc0c-4fa3cd1925a6 +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0120 +An object reference is required for the nonstatic field, method, or property 'member' + + In order to use a non-static field, method, or property, you must first create an object instance. For more information about static methods, see [Static Classes and Static Class Members](../../../csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members.md). For more information about creating instances of classes, see [Instance Constructors](../../../csharp/programming-guide/classes-and-structs/instance-constructors.md). + + The following sample generates CS0120: + +``` +// CS0120_1.cs +public class MyClass +{ + // Non-static field + public int i; + // Non-static method + public void f(){} + // Non-static property + int Prop + { + get + { + return 1; + } + } + + public static void Main() + { + i = 10; // CS0120 + f(); // CS0120 + int p = Prop; // CS0120 + // try the following lines instead + // MyClass mc = new MyClass(); + // mc.i = 10; + // mc.f(); + // int p = mc.Prop; + } +} +``` + + CS0120 will also be generated if there is a call to a non-static method from a static method, as follows: + +``` +// CS0120_2.cs +// CS0120 expected +using System; + +public class MyClass +{ + public static void Main() + { + TestCall(); // CS0120 + // To call a non-static method from Main, + // first create an instance of the class. + // Use the following two lines instead: + // MyClass anInstanceofMyClass = new MyClass(); + // anInstanceofMyClass.TestCall(); + } + + public void TestCall() + { + } +} +``` + + Similarly, a static method cannot call an instance method unless you explicitly give it an instance of the class, as follows: + +``` +// CS0120_3.cs +using System; + +public class MyClass +{ + public static void Main() + { + do_it("Hello There"); // CS0120 + } + + private void do_it(string sText) + // You could also add the keyword static to the method definition: + // private static void do_it(string sText) + { + Console.WriteLine(sText); + } +} +``` + +## See Also + [Classes and Structs](../../../csharp/programming-guide/classes-and-structs/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0122.md b/docs/csharp/language-reference/compiler-messages/cs0122.md new file mode 100644 index 0000000000000..efc628379bf5a --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0122.md @@ -0,0 +1,68 @@ +--- +title: "Compiler Error CS0122 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0122" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0122" +ms.assetid: 5f639a66-c807-4166-b88a-93e5f272ceb7 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0122 +'member' is inaccessible due to its protection level + + The [access modifier](../../../csharp/language-reference/keywords/modifiers.md) for a class member prevents accessing the member. For more information, see [Access Modifiers](../../../csharp/programming-guide/classes-and-structs/access-modifiers.md). + + One cause of this (not shown in the sample below) can be omitting the **/out** compiler flag on the target of a friend assembly. For more information, see [Friend Assemblies](http://msdn.microsoft.com/library/df0c70ea-2c2a-4bdc-9526-df951ad2d055) and [/out (C# Compiler Options)](../../../csharp/language-reference/compiler-options/out-compiler-option.md) + +## Example + The following sample generates CS0122: + +``` +// CS0122.cs +public class MyClass +{ + // Make public to resolve CS0122 + void MyMethod() + { + } +} + +public class MyClass2 +{ + public static int Main() + { + MyClass a = new MyClass(); + // MyMethod is private + a.MyMethod(); // CS0122 + return 0; + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0134.md b/docs/csharp/language-reference/compiler-messages/cs0134.md new file mode 100644 index 0000000000000..c05279c92dbc4 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0134.md @@ -0,0 +1,61 @@ +--- +title: "Compiler Error CS0134 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0134" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0134" +ms.assetid: c7b57de2-42ad-473e-8e45-8ac7a0caea9a +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0134 +'variable' is of type 'type'. A const field of a reference type other than string can only be initialized with null. + + A constant-expression is an expression that can be fully evaluated at compile-time. Because the only way to create a non-null value of a reference-type is to apply the new operator, and because the new operator is not permitted in a constant-expression, the only possible value for constants of reference-types other than string is null. + + If you encounter this error by trying to create a [const](../../../csharp/language-reference/keywords/const.md) string array, the solution is to make the array [readonly](../../../csharp/language-reference/keywords/readonly.md), and initialize it in the constructor. + +## Example + The following example generates CS0134. + +``` +// CS0134.cs +// compile with: /target:library +class MyTest {} + +class MyClass +{ + const MyTest test = new MyTest(); // CS0134 + + //OK + const MyTest test2 = null; + const System.String test3 = "test"; +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0151.md b/docs/csharp/language-reference/compiler-messages/cs0151.md new file mode 100644 index 0000000000000..cb4eeb47c21b4 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0151.md @@ -0,0 +1,96 @@ +--- +title: "Compiler Error CS0151 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0151" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0151" +ms.assetid: 1adda08b-6be5-46c8-96f9-5ac7c7bfe48c +caps.latest.revision: 14 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0151 +A value of an integral type expected + + A variable was used in a situation where an integral data type was required. For more information, see [Types](../../../csharp/programming-guide/types/index.md). + +## Example + This error can occur when there is no conversion or if the available implicit conversions result in an ambiguous situation. The following sample generates CS0151. + +``` +// CS0151.cs +public class MyClass +{ + public static implicit operator int (MyClass aa) + { + return 0; + } + + public static implicit operator long (MyClass aa) + { + return 0; + } + + public static void Main() + { + MyClass a = new MyClass(); + + // Compiler cannot choose between int and long + switch (a) // CS0151 + // try the following line instead + // switch ((int)a) + { + case 1: + break; + } + } +} +``` + +## Example + In Visual Studio 2008 and later, a [void](../../../csharp/language-reference/keywords/void.md) method invocation generates CS0151. You can fix the error by calling a method that returns an integral type such as [int](../../../csharp/language-reference/keywords/int.md) or [long](../../../csharp/language-reference/keywords/long.md). + +``` +class C +{ + static void Main() + { + + switch (M()) // CS0151 + { + default: + break; + } + } + + static void M() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0163.md b/docs/csharp/language-reference/compiler-messages/cs0163.md new file mode 100644 index 0000000000000..dee3ceeca5be1 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0163.md @@ -0,0 +1,91 @@ +--- +title: "Compiler Error CS0163 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0163" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0163" +ms.assetid: 00139dcf-33cd-45ea-bf80-d6f26b10a5d2 +caps.latest.revision: 14 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Error CS0163 +Control cannot fall through from one case label ('label') to another + + When a [switch statement](../../../csharp/language-reference/keywords/switch.md) contains more than one switch section, you must explicitly terminate each section, including the last one, by using one of the following keywords: + +- [return](../../../csharp/language-reference/keywords/return.md) + +- [goto](../../../csharp/language-reference/keywords/goto.md) + +- [break](../../../csharp/language-reference/keywords/break.md) + +- [throw](../../../csharp/language-reference/keywords/throw.md) + +- [continue](../../../csharp/language-reference/keywords/continue.md) + + If you want to implement "fall through" behavior from one section to the next, use `goto case #`. For more information and examples, see [switch](../../../csharp/language-reference/keywords/switch.md). + + The following sample generates CS0163. + +```cs +// CS0163.cs +public class MyClass +{ + public static void Main() + { + int i = 0; + + switch (i) // CS0163 + { + // Compiler error CS0163 is reported on the following line. + case 1: + i++; + // To resolve the error, uncomment one of the following example statements. + // return; + // break; + // goto case 3; + + case 2: + i++; + return; + + case 3: + i = 0; + return; + + // Compiler error CS0163 is reported on the following line. + default: + Console.WriteLine("Default"); + // To resolve the error, uncomment the following line: + //break; + } + } +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0165.md b/docs/csharp/language-reference/compiler-messages/cs0165.md new file mode 100644 index 0000000000000..6cf21908b95c6 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0165.md @@ -0,0 +1,119 @@ +--- +title: "Compiler Error CS0165 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0165" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0165" +ms.assetid: e7eb7c90-af16-4734-b747-214030696975 +caps.latest.revision: 15 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0165 +Use of unassigned local variable 'name' + + The C# compiler does not allow the use of uninitialized variables. If the compiler detects the use of a variable that might not have been initialized, it generates compiler error CS0165. For more information, see [Fields](../../../csharp/programming-guide/classes-and-structs/fields.md). Note that this error is generated when the compiler encounters a construct that might result in the use of an unassigned variable, even if your particular code does not. This avoids the necessity of overly-complex rules for definite assignment. + + For more information, see [http://blogs.msdn.com/ericlippert/archive/2006/08/18/706398.aspx](http://blogs.msdn.com/ericlippert/archive/2006/08/18/706398.aspx). + +## Example + The following sample generates CS0165: + +```cs +// CS0165.cs +using System; + +class MyClass +{ + public int i; +} + +class MyClass2 +{ + public static void Main(string[] args) + { + // i and j are not initialized. + int i, j; + + // You can provide a value for args[0] in the 'Command line arguments' + // text box on the Debug tab of the project Properties window. + if (args[0] == "test") + { + i = 0; + } + // If the following else clause is absent, i might not be + // initialized. + //else + //{ + // i = 1; + //} + + // Because i might not have been initialized, the following + // line causes CS0165. + j = i; + + // To resolve the error, uncomment the else clause of the previous + // if statement, or initialize i when you declare it. + + // The following example causes CS0165 because myInstance is + // declared but not instantiated. + MyClass myInstance; + // The following line causes the error. + myInstance.i = 0; + + // To resolve the error, replace the previous declaration with + // the following line. + //MyClass myInstance = new MyClass(); + } +} + +``` + +## Example + Compiler error CS0165 can occur in recursive delegate definitions. You can avoid the error by defining the delegate in two statements so that the variable is not used before it is initialized. The following example demonstrates the error and the resolution. + +```cs +class Program +{ + delegate void Del(); + static void Main(string[] args) + { + // The following line causes CS0165 because variable d is used + // as an argument before it has been initialized. + Del d = delegate() { System.Console.WriteLine(d); }; + + //// To resolve the error, initialize d in a separate statement. + //Del d = null; + //// After d is initialized, you can use it as an argument. + //d = delegate() { System.Console.WriteLine(d); }; + //d(); + } +} + +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0173.md b/docs/csharp/language-reference/compiler-messages/cs0173.md new file mode 100644 index 0000000000000..7104c3855cd16 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0173.md @@ -0,0 +1,104 @@ +--- +title: "Compiler Error CS0173 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0173" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0173" +ms.assetid: eb1797ad-bf62-4e2b-8922-bef4aff36954 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0173 +Type of conditional expression cannot be determined because there is no implicit conversion between 'class1' and 'class2' + + Conversions between classes are useful when you want objects of different classes to work with the same code. However, two classes that work together cannot have mutual and redundant conversions, or no implicit conversions. The types of `class1` and `class2` are determined independently, and the more general type is selected as the type of the conditional expression. For more information about how types are determined, see [Conditional operator cannot cast implicitly](http://go.microsoft.com/fwlink/?LinkId=213999). + + To resolve CS0173, verify that there is one and only one implicit conversion between `class1` and `class2`, regardless of which direction the conversion is in and regardless of which class the conversion is in. For more information, see [Implicit Numeric Conversions Table](../../../csharp/language-reference/keywords/implicit-numeric-conversions-table.md) and [Conversion Operators](../../../csharp/programming-guide/statements-expressions-operators/conversion-operators.md). + +## Example + The following sample generates CS0173: + +```cs +// CS0173.cs +public class C {} + +public class A +{ + //// The following code defines an implicit conversion operator from + //// type C to type A. + //public static implicit operator A(C c) + //{ + // A a = new A(); + // a = c; + // return a; + //} +} + +public class MyClass +{ + public static void F(bool b) + { + A a = new A(); + C c = new C(); + + // The following line causes CS0173 because there is no implicit + // conversion from a to c or from c to a. + object o = b ? a : c; + + // To resolve the error, you can cast a and c. + //object o = b ? (object)a : (object)c; + + // Alternatively, you can add a conversion operator from class C to + // class A, or from class A to class C, but not both. + } + + public static void Main() + { + F(true); + } +} +``` + +## Example + The following code does not produce CS0173 in Visual Studio 2005, but does in later versions. + +```cs +//cs0173_2.cs +class M +{ + static int Main () + { + int X = 1; + // The following line causes CS0173 in Visual Studio 2005. + object o = (X == 0) ? null : null; + return -1; + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0178.md b/docs/csharp/language-reference/compiler-messages/cs0178.md new file mode 100644 index 0000000000000..535aa9009faa5 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0178.md @@ -0,0 +1,69 @@ +--- +title: "Compiler Error CS0178 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0178" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0178" +ms.assetid: 73e48648-6c0c-4987-92ca-fb2015a38910 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0178 +Invalid rank specifier: expected ',' or ']' + + An array initialization was ill-formed. For example, when specifying the array dimensions, you can specify the following: + +- A number in brackets + +- Empty brackets + +- A comma enclosed in brackets + + For more information, see [Arrays](../../../csharp/programming-guide/arrays/index.md) and the C# specification ([C# Language Specification](../../../csharp/language-reference/language-specification.md)) section on array initializers. + +## Example + The following sample generates CS0178. + +``` +// CS0178.cs +class MyClass +{ + public static void Main() + { + int a = new int[5][,][][5; // CS0178 + int[,] b = new int[3,2]; // OK + + int[][] c = new int[10][]; + c[0] = new int[5][5]; // CS0178 + c[0] = new int[2]; // OK + c[1] = new int[2]{1,2}; // OK + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0188.md b/docs/csharp/language-reference/compiler-messages/cs0188.md new file mode 100644 index 0000000000000..c7d534ffaeb97 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0188.md @@ -0,0 +1,80 @@ +--- +title: "Compiler Error CS0188 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0188" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0188" +ms.assetid: 4e693c18-584d-4c94-9863-283c69b97b0b +caps.latest.revision: 17 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0188 +The 'this' object cannot be used before all of its fields are assigned to + + All fields in a `struct` have to be assigned by a constructor before the constructor can call a method in the `struct`. + + If you see this error when trying to initialize a property in a struct constructor, the solution is to change the constructor parameter to specify the backing field instead of the property itself. Auto-implemented properties should be avoided in structs because they have no backing field and therefore cannot be initialized in any way from the constructor. + + For more information, see [Using Structs](../../../csharp/programming-guide/classes-and-structs/using-structs.md). + +## Example + The following sample generates CS0188: + +``` +// CS0188.cs +// compile with: /t:library +namespace MyNamespace +{ + class MyClass + { + struct S + { + public int a; + + void MyMethod() + { + } + + S(int i) + { + // a = i; + MyMethod(); // CS0188 + } + } + public static void Main() + { } + + } +} +``` + +## See Also + [Structs](../../../csharp/programming-guide/classes-and-structs/structs.md) + [Auto-Implemented Properties](../../../csharp/programming-guide/classes-and-structs/auto-implemented-properties.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0201.md b/docs/csharp/language-reference/compiler-messages/cs0201.md new file mode 100644 index 0000000000000..7d6b7a4499131 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0201.md @@ -0,0 +1,84 @@ +--- +title: "Compiler Error CS0201 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0201" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0201" +ms.assetid: cf5d6701-50cc-4e4f-878b-e1a4ad8a2061 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0201 +Only assignment, call, increment, decrement, and new object expressions can be used as a statement + + The compiler generates an error when it encounters an invalid statement. An invalid statement is any line or series of lines ending in a semicolon that does not represent an assignment ([=](../../../csharp/language-reference/operators/assignment-operator.md)), method call [()](../../../csharp/language-reference/operators/invocation-operator.md), [new](../../../csharp/language-reference/keywords/new.md), [--](../../../csharp/language-reference/operators/decrement-operator.md) or [++](../../../csharp/language-reference/operators/increment-operator.md) operation. For more information, see [Statements, Expressions, and Operators](../../../csharp/programming-guide/statements-expressions-operators/index.md). + +## Example + The following sample generates CS0201 because 2 * 3 is an expression, not a statement. To make the code compile, try assigning the value of the expression to a variable. + +``` +// CS0201.cs +public class MainClass +{ + public static void Main() + { + 2 * 3; // CS0201 + // Try the following line instead. + // int i = 2 * 3; + } +} +``` + +## Example + The following sample generates CS0201 because checked by itself is not a statement, even though it is parameterized by an increment operation. + +``` +// CS0201_b.cs +// compile with: /target:library +public class MyList +{ + public void Add(T x) + { + int i = 0; + if ( (object)x == null) + { + checked(i++); // CS0201 + + // OK + checked { + i++; + } + } + } +} +``` + +## See Also + [C# Compiler Errors](../../../csharp/language-reference/compiler-messages/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0229.md b/docs/csharp/language-reference/compiler-messages/cs0229.md new file mode 100644 index 0000000000000..ff4548532c6ee --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0229.md @@ -0,0 +1,87 @@ +--- +title: "Compiler Error CS0229 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0229" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0229" +ms.assetid: f1ff7e91-1243-4d36-b792-26ba69186f8f +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0229 +Ambiguity between 'member1' and 'member2' + + Members of different interfaces have the same name. If you want to keep the same names, you must qualify the names. For more information, see [Interfaces](../../../csharp/programming-guide/interfaces/index.md). + +> [!NOTE] +> In some cases, this ambiguity can be resolved by providing an explicit prefix to the identifier via a [using](../../../csharp/language-reference/keywords/using-directive.md) alias. + +## Example + The following example generates CS0229: + +``` +// CS0229.cs + +interface IList +{ + int Count + { + get; + set; + } + + void Counter(); +} + +interface Icounter +{ + double Count + { + get; + set; + } +} + +interface IListCounter : IList , Icounter {} + +class MyClass +{ + void Test(IListCounter x) + { + x.Count = 1; // CS0229 + // Try one of the following lines instead: + // ((IList)x).Count = 1; + // or + // ((Icounter)x).Count = 1; + } + + public static void Main() {} +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0233.md b/docs/csharp/language-reference/compiler-messages/cs0233.md new file mode 100644 index 0000000000000..5dea09ba8632c --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0233.md @@ -0,0 +1,67 @@ +--- +title: "Compiler Error CS0233 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0233" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0233" +ms.assetid: 75b0123f-2237-43dc-9234-a0f727eee482 +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0233 +'identifier' does not have a predefined size, therefore sizeof can only be used in an unsafe context (consider using System.Runtime.InteropServices.Marshal.SizeOf) + + The [sizeof](../../../csharp/language-reference/keywords/sizeof.md) operator can only be used for types that are compile-time constants. If you are getting this error, make sure that the size of the identifier can be determined at compile time. If it cannot, then use instead of `sizeof`. + +## Example + The following example generates CS0233: + +``` +// CS0233.cs +using System; +using System.Runtime.InteropServices; + +[StructLayout(LayoutKind.Sequential)] +public struct S +{ + public int a; +} + +public class MyClass +{ + public static void Main() + { + S myS = new S(); + Console.WriteLine(sizeof(S)); // CS0233 + // Try the following line instead: + // Console.WriteLine(Marshal.SizeOf(myS)); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0234.md b/docs/csharp/language-reference/compiler-messages/cs0234.md new file mode 100644 index 0000000000000..5b7cc3dbc37a7 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0234.md @@ -0,0 +1,64 @@ +--- +title: "Compiler Error CS0234 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0234" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0234" +ms.assetid: 413774cc-b63e-472b-8fe7-cf23ca970a5f +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0234 +The type or namespace name 'name' does not exist in the namespace 'namespace' (are you missing an assembly reference?) + + A type was expected. Possible causes for this error include the following: + +- An assembly that contains the definition of a type was not referenced in the compilation; use [/reference (Import Metadata)](../../../csharp/language-reference/compiler-options/reference-compiler-option.md) to specify the assembly + +- You passed a variable name to the [typeof](../../../csharp/language-reference/keywords/typeof.md) operator. + +- You tried to reference an assembly that is not part of your target .NET Framework profile. For more information, see [Troubleshooting .NET Framework Targeting Errors](/visualstudio/msbuild/troubleshooting-dotnet-framework-targeting-errors). + + If you see this error after moving code from one development machine to another, make sure that the project on the new machine has the correct references, and that the versions of the assemblies are the same as on the old machine. You can also use the Object Browser to inspect an assembly and verify whether it contains the types that you expect it to contain. + + The following sample generates CS0234: + +``` +// CS0234.cs +public class C +{ + public static void Main() + { + System.DateTime x = new System.DateTim(); // CS0234 + // try the following line instead + // System.DateTime x = new System.DateTime(); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0246.md b/docs/csharp/language-reference/compiler-messages/cs0246.md new file mode 100644 index 0000000000000..8db9e610147e8 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0246.md @@ -0,0 +1,124 @@ +--- +title: "Compiler Error CS0246 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0246" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0246" +ms.assetid: 4948fae2-2cc0-4ce4-b98c-ea69a8120b71 +caps.latest.revision: 17 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Error CS0246 +The type or namespace name 'type/namespace' could not be found (are you missing a using directive or an assembly reference?) + + A type or namespace that is used in the program was not found. You might have forgotten to reference ([/reference](../../../csharp/language-reference/compiler-options/reference-compiler-option.md)) the assembly that contains the type, or you might not have added the required [using directive](../../../csharp/language-reference/keywords/using-directive.md). Or, there might be an issue with the assembly you are trying to reference. + + The following situations cause compiler error CS0246. + +- Did you misspell the name of the type or namespace? Without the correct name, the compiler cannot find the definition for the type or namespace. This often occurs because the casing used in the name of the type is not correct. For example, `Dataset ds;` generates CS0246 because the s in Dataset must be capitalized. + +- If the error is for a namespace name, did you add a reference ([/reference](../../../csharp/language-reference/compiler-options/reference-compiler-option.md)) to the assembly that contains the namespace? For example, your code might contain the directive `using Accessibility`. However, if your project does not reference the assembly Accessibility.dll, error CS0246 is reported. For more information, see [Managing references in a project](/visualstudio/ide/managing-references-in-a-project) + +- If the error is for a type name, did you include the proper [using](../../../csharp/language-reference/keywords/using.md) directive, or, alternatively, fully qualify the name of the type? Consider the following declaration: `DataSet ds`. To use the `DataSet` type, you need two things. First, you need a reference to the assembly that contains the definition for the `DataSet` type. Second, you need a `using` directive for the namespace where `DataSet` is located. For example, because `DataSet` is located in the **System.Data** namespace, you need the following directive at the beginning of your code: `using System.Data`. + + The `using` directive is not required. However, if you omit the directive, you must fully qualify the `DataSet` type when referring to it. Full qualification means that you specify both the namespace and the type each time you refer to the type in your code. If you omit the `using` directive in the previous example, you must write `System.Data.DataSet ds` to declare `ds` instead of `DataSet ds`. + +- Did you use a variable or some other language element where a type was expected? For example, in an **is** statement, if you use a `Type` object instead of an actual type, you get error CS0246. + +- Did you use a *using alias directive* without fully qualifying the type name? A `using` alias directive does not use the `using` directives in the source code file to resolve types. The following example generates CS0246 because the type `List` is not fully qualified. The `using` directive for `System.Collections.Generic` does not prevent the error. + + ```cs + using System.Collections.Generic; + + // The following declaration generates CS0246. + using myAliasName = List; + + // To avoid the error, fully qualify List. + using myAliasName2 = System.Collections.Generic.List; + + ``` + + If you get this error in code that was previously working, first look for missing or unresolved references in Solution Explorer. Do you need to re-install a [NuGet](https://www.nuget.org/)package? For information about how the build system searches for references, see [Resolving file references in team build](http://blogs.msdn.com/b/manishagarwal/archive/2005/09/28/474769.aspx). If all references seem to be correct, look in your source control history to see what has changed in your .csproj file and/or your local source file. + + If you haven’t successfully accessed the reference yet, use the Object Browser to inspect the assembly that is supposed to contain this namespace and verify that the namespace is present. If you verify with Object Browser that the assembly contains the namespace, try removing the “using” directive for the namespace and see what else breaks. The root problem may be with some other type in another assembly. + + The following example generates CS0246 because a necessary `using` directive is missing. + +```cs +// CS0246.cs +//using System.Diagnostics; + +public class MyClass +{ + // The following line causes CS0246. To fix the error, uncomment + // the using directive for the namespace for this attribute, + // System.Diagnostics. + [Conditional("A")] + public void Test() + { + } + + public static void Main() + { + } +} +``` + + The following example causes CS0246 because an object of type `Type` was used where an actual type was expected. + +```cs +// CS0246b.cs +using System; + +class ExampleClass +{ + public bool supports(object o, Type t) + { + // The following line causes CS0246. You must use an + // actual type, such as ExampleClass, String, or Type. + if (o is t) + { + return true; + } + return false; + } +} + +class Program +{ + public static void Main() + { + ExampleClass myC = new ExampleClass(); + myC.supports(myC, myC.GetType()); + } +} + +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0260.md b/docs/csharp/language-reference/compiler-messages/cs0260.md new file mode 100644 index 0000000000000..6c25e07fa8627 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0260.md @@ -0,0 +1,64 @@ +--- +title: "Compiler Error CS0260 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0260" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0260" +ms.assetid: 58e091da-e093-4093-86df-dcd24ffab750 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0260 +Missing partial modifier on declaration of type 'type'; another partial declaration of this type exists + + This error indicates that you have declared multiple classes that have the same name. In addition, at least one but not all of the declarations contains the `partial` modifier. If you want to define a class in several parts, you must declare each part by using the keyword `partial`. + + This error also occurs if you declare a class and accidentally give it the same name as a partial class that's declared elsewhere in the same namespace. + + The following sample generates CS0260: + +```cs +// CS0260.cs +// You must mark both parts of the definition of class C +// by using the partial keyword. + +// The following line causes CS0260. To resolve the error, add +// the 'partial' keyword to the declaration. +class C +{ +} + +partial class C +{ +} +``` + +## See Also + [Partial Classes and Methods](../../../csharp/programming-guide/classes-and-structs/partial-classes-and-methods.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0266.md b/docs/csharp/language-reference/compiler-messages/cs0266.md new file mode 100644 index 0000000000000..1e9a82ec9fc28 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0266.md @@ -0,0 +1,85 @@ +--- +title: "Compiler Error CS0266 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0266" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0266" +ms.assetid: 6cca5d6a-f3e0-482a-af25-af73bfe3e303 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0266 +Cannot implicitly convert type 'type1' to 'type2'. An explicit conversion exists (are you missing a cast?) + + This error occurs when your code tries to convert between two types that cannot be implicitly converted, but where an explicit conversion is available. For more information, see [Casting and Type Conversions](../../../csharp/programming-guide/types/casting-and-type-conversions.md). + + The following code shows examples that generate CS0266. + +```cs +// CS0266.cs +class MyClass +{ + public static void Main() + { + // You cannot implicitly convert a double to an integer. + double d = 3.2; + + // The following line causes compiler error CS0266. + int i1 = d; + + // However, you can resolve the error by using an explicit conversion. + int i2 = (int)d; + + // You cannot implicitly convert an object to a class type. + object obj = "MyString"; + + // The following assignment statement causes error CS0266. + MyClass myClass = obj; + + // You can resolve the error by using an explicit conversion. + MyClass c = ( MyClass )obj; + + // You cannot implicitly convert a base class object to a derived class type. + MyClass mc = new MyClass(); + DerivedClass dc = new DerivedClass(); + + // The following line causes compiler error CS0266. + dc = mc; + + // You can resolve the error by using an explicit conversion. + dc = (DerivedClass)mc; + } +} + +class DerivedClass : MyClass +{ +} + +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0269.md b/docs/csharp/language-reference/compiler-messages/cs0269.md new file mode 100644 index 0000000000000..172ffe946a09e --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0269.md @@ -0,0 +1,102 @@ +--- +title: "Compiler Error CS0269 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0269" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0269" +ms.assetid: 7ef8374c-6f82-4096-bf4b-70080d4ddf88 +caps.latest.revision: 14 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0269 +Use of unassigned out parameter 'parameter' + + The compiler could not verify that the out parameter was assigned a value before it was used; its value may be undefined when assigned. Be sure to assign a value to `out` parameters in the called method before accessing the value. If you need to use the value of the variable passed in, use a `ref` parameter instead. For more information, see [Passing Parameters](../../../csharp/programming-guide/classes-and-structs/passing-parameters.md). + +## Example + The following sample generates CS0269: + +```cs +// CS0269.cs +class C +{ + public static void F(out int i) + // One way to resolve the error is to use a ref parameter instead + // of an out parameter. + //public static void F(ref int i) + { + // The following line causes a compiler error because no value + // has been assigned to i. + int k = i; // CS0269 + i = 1; + // The error does not occur if the order of the two previous + // lines is reversed. + } + + public static void Main() + { + int myInt = 1; + F(out myInt); + // If the declaration of method F is changed to require a ref + // parameter, ref must be specified in the call as well. + //F(ref myInt); + } +} +``` + +## Example + This could also occur if the initialization of a variable occurs in a try block, which the compiler is unable to verify will execute successfully: + +```cs +// CS0269b.cs +class C +{ + public static void F(out int i) + { + try + { + // Assignment occurs, but compiler can't verify it + i = 1; + } + catch + { + } + + int k = i; // CS0269 + i = 1; + } + + public static void Main() + { + int myInt; + F(out myInt); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0270.md b/docs/csharp/language-reference/compiler-messages/cs0270.md new file mode 100644 index 0000000000000..0f2f8b2d27eaa --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0270.md @@ -0,0 +1,55 @@ +--- +title: "Compiler Error CS0270 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0270" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0270" +ms.assetid: ce3eaf5f-5c49-4608-a172-d92c515cab50 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0270 +Array size cannot be specified in a variable declaration (try initializing with a 'new' expression) + + This error occurs when a size is specified as part of an array declaration. To resolve, use the [new Operator](../../../csharp/language-reference/keywords/new-operator.md) expression. + + The following example generates CS0270: + +``` +// CS0270.cs +// compile with: /t:module + +public class Test +{ + int[10] a; // CS0270 + // To resolve, use the following line instead: + // int[] a = new int[10]; +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0304.md b/docs/csharp/language-reference/compiler-messages/cs0304.md new file mode 100644 index 0000000000000..82243d38ee7fb --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0304.md @@ -0,0 +1,97 @@ +--- +title: "Compiler Error CS0304 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0304" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0304" +ms.assetid: 22dc7211-57a8-4c92-96f6-fc1cf0263b68 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0304 +Cannot create an instance of the variable type 'type' because it does not have the new() constraint + + When you implement a generic class, and you want to use the `new` keyword to create a new instance of any type that is supplied for a type parameter `T`, you must apply the [new() constraint](../../../csharp/language-reference/keywords/new.md) to `T` in the class declaration, as shown in the following example. + +```cs +class C where T : new() +``` + + The `new()` constraint enforces type safety by guaranteeing that any concrete type that is supplied for `T` has a default, parameterless constructor. CS0304 occurs if you attempt to use the `new` operator in the body of the class to create an instance of type parameter `T` when `T` does not specify the `new()` constraint. On the client side, if code attempts to instantiate the generic class with a type that has no default constructor, that code will generate [Compiler Error CS0310](../../../csharp/language-reference/compiler-messages/cs0310.md). + + The following example generates CS0304. + +```cs + +// CS0304.cs +// Compile with: /target:library. +class C +{ + // The following line generates CS0304. + T t = new T(); +} + +``` + + The `new` operator also is not allowed in methods of the class. + +```cs + +// Compile with: /target:library. +class C +{ + public void ExampleMethod() + { + // The following line generates CS0304. + T t = new T(); + } +} + +``` + + To avoid the error, declare the class by using the `new()` constraint, as shown in the following example. + +```cs + +// Compile with: /target:library. +class C where T : new() +{ + T t = new T(); + + public void ExampleMethod() + { + T t = new T(); + } +} + +``` + +## See Also + [C# Compiler Errors](../../../csharp/language-reference/compiler-messages/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0310.md b/docs/csharp/language-reference/compiler-messages/cs0310.md new file mode 100644 index 0000000000000..bce0e79a0de59 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0310.md @@ -0,0 +1,76 @@ +--- +title: "Compiler Error CS0310 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0310" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0310" +ms.assetid: f7db7e56-f51f-406f-a54b-48ea61b5cb3e +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0310 +The type 'typename' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'parameter' in the generic type or method 'generic' + + The generic type or method defines a new constraint in its where clause, so any type must have a public parameterless constructor in order to be used as a type argument for that generic type or method. To avoid this error, make sure that the type has the correct constructor, or modify the constraint clause of the generic type or method. + +## Example + The following sample generates CS0310: + +``` +// CS0310.cs +using System; + +class G where T : new() +{ + T t; + + public G() + { + t = new T(); + Console.WriteLine(t); + } +} + +class B +{ + private B() { } + // Try this instead: + // public B() { } +} + +class CMain +{ + public static void Main() + { + G g = new G(); // CS0310 + Console.WriteLine(g.ToString()); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0311.md b/docs/csharp/language-reference/compiler-messages/cs0311.md new file mode 100644 index 0000000000000..77921126d66a8 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0311.md @@ -0,0 +1,70 @@ +--- +title: "Compiler Error CS0311 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0311" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0311" +ms.assetid: d095f0fa-efd7-491c-a80b-4c5704a90de7 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0311 +The type 'type1' cannot be used as type parameter 'T' in the generic type or method '\'. There is no implicit reference conversion from 'type1' to 'type2'. + + When a constraint is applied to a generic type parameter, an implicit identity or reference conversion must exist from the concrete argument to the type of the constraint. + +## To correct this error + +1. Change the argument you are using to create the class. + +2. If you own the class, you can remove the constraint or else do something to enable an implicit reference or identity conversion. For example, you can make the second type inherit from the first. + +## Example + +``` +// cs0311.cs +class B{} +class C{} +class Test where T : C +{ } + +class Program +{ + static void Main() + { + Test test = new Test(); //CS0311 + } +} +``` + + If this error occurs when trying to use a value-type argument, notice that an implicit numeric conversion, for example from `short` to `int`, does not satisfy a generic type parameter. + +## See Also + [Constraints on Type Parameters](../../../csharp/programming-guide/generics/constraints-on-type-parameters.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0413.md b/docs/csharp/language-reference/compiler-messages/cs0413.md new file mode 100644 index 0000000000000..b18406880846d --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0413.md @@ -0,0 +1,71 @@ +--- +title: "Compiler Error CS0413 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0413" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0413" +ms.assetid: a01bd1ec-015b-433b-be55-b91db268d6a5 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Error CS0413 +The type parameter 'type parameter' cannot be used with the 'as' operator because it does not have a class type constraint nor a 'class' constraint + + This error occurs if a generic type uses the [as](../../../csharp/language-reference/keywords/as.md) operator, but that generic type does not have a class type constraint. The `as` operator is only allowed with reference types, so the type parameter must be constrained to guarantee that it is not a value type. To avoid this error, use a class type constraint or a reference type constraint. + + This is because the `as` operator could return `null`, which is not a possible value for a value type, and the type parameter must be treated as a value type unless it is a class type constraint or a reference type constraint. + +## Example + The following sample generates CS0413. + +``` +// CS0413.cs +// compile with: /target:library +class A {} +class B : A {} + +class CMain +{ + A a = null; + public void G() + { + a = new A(); + System.Console.WriteLine (a as T); // CS0413 + } + + // OK + public void H() where T : A + { + a = new A(); + System.Console.WriteLine (a as T); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0417.md b/docs/csharp/language-reference/compiler-messages/cs0417.md new file mode 100644 index 0000000000000..52f1c8db51852 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0417.md @@ -0,0 +1,60 @@ +--- +title: "Compiler Error CS0417 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0417" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0417" +ms.assetid: e2a617da-f0b2-4bad-aefa-3dd3bc1fb24b +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0417 +'identifier': cannot provide arguments when creating an instance of a variable type + + This error occurs if a call to the `new` operator on a type parameter has arguments. The only constructor that can be called by using the `new` operator on an unknown parameter type is a constructor that has no arguments. If you need to call another constructor, consider using a class type constraint or interface constraint. + +## Example + The following example generates CS0417: + +```cs +// CS0417 +class ExampleClass where T : new() +{ + // The following line causes CS0417. + T instance1 = new T(1); + + // The following line doesn't cause the error. + T instance2 = new T(); +} + +``` + +## See Also + [Constraints on Type Parameters](../../../csharp/programming-guide/generics/constraints-on-type-parameters.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0420.md b/docs/csharp/language-reference/compiler-messages/cs0420.md new file mode 100644 index 0000000000000..9d7f0082a748d --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0420.md @@ -0,0 +1,64 @@ +--- +title: "Compiler Warning (level 1) CS0420 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0420" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0420" +ms.assetid: 0f52f508-286e-493d-9151-180e05397bf9 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS0420 +'identifier': a reference to a volatile field will not be treated as volatile + + A volatile field should not normally be passed using a `ref` or **out** parameter, since it will not be treated as volatile within the scope of the function. There are exceptions to this, such as when calling an interlocked API. As with any warning, you may use the [#pragma warning](../../../csharp/language-reference/preprocessor-directives/preprocessor-pragma-warning.md) to disable this warning in those rare cases where you are intentionally using a volatile field as a reference parameter. + + The following sample generates CS0420: + +``` +// CS0420.cs +// compile with: /W:1 +using System; + +class TestClass +{ + private volatile int i; + + public void TestVolatile(ref int ii) + { + } + + public static void Main() + { + TestClass x = new TestClass(); + x.TestVolatile(ref x.i); // CS0420 + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0429.md b/docs/csharp/language-reference/compiler-messages/cs0429.md new file mode 100644 index 0000000000000..5ab98a86f7364 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0429.md @@ -0,0 +1,66 @@ +--- +title: "Compiler Warning (level 4) CS0429 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0429" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0429" +ms.assetid: 906442de-9760-4e28-aea1-c94f0af918fb +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 4) CS0429 +Unreachable expression code detected + + This error occurs whenever part of an expression in your code is unreachable. In the following example, the condition `false && myTest()` meets this criteria because the `myTest()` method will never get evaluated due to the fact that the left side of the `&&` operation is always false. As soon as the `&&` operator evaluates the `false` statement as false, it stops the evaluation, and will never evaluate the right side. + +## Example + The following code generates CS0429. + +``` +// CS0429.cs +public class cs0429 +{ + public static void Main() + { + if (false && myTest()) // CS0429 + // Try the following line instead: + // if (true && myTest()) + { + } + else + { + int i = 0; + i++; + } + } + + static bool myTest() { return true; } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0433.md b/docs/csharp/language-reference/compiler-messages/cs0433.md new file mode 100644 index 0000000000000..a11742e316523 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0433.md @@ -0,0 +1,99 @@ +--- +title: "Compiler Error CS0433 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0433" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0433" +ms.assetid: efec174a-faa1-4b88-860b-7d9db9c82a02 +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0433 +The type TypeName1 exists in both TypeName2 and TypeName3 + + Two different assemblies referenced in your application contain the same namespace and type, which produces ambiguity. + + To resolve this error, use the alias feature of the [/reference (C# Compiler Options)](../../../csharp/language-reference/compiler-options/reference-compiler-option.md) compiler option or do not reference one of your assemblies. + +## Example + This code creates the DLL with the first copy of the ambiguous type. + +``` +// CS0433_1.cs +// compile with: /target:library +namespace TypeBindConflicts +{ + public class AggPubImpAggPubImp {} +} +``` + +## Example + This code creates the DLL with the second copy of the ambiguous type. + +``` +// CS0433_2.cs +// compile with: /target:library +namespace TypeBindConflicts +{ + public class AggPubImpAggPubImp {} +} +``` + +## Example + The following example generates CS0433. + +``` +// CS0433_3.cs +// compile with: /reference:cs0433_1.dll /reference:cs0433_2.dll +using TypeBindConflicts; +public class Test +{ + public static void Main() + { + AggPubImpAggPubImp n6 = new AggPubImpAggPubImp(); // CS0433 + } +} +``` + +## Example + The following example shows how you can use the alias feature of the **/reference** compiler option to resolve this CS0433 error. + +``` +// CS0433_4.cs +// compile with: /reference:cs0433_1.dll /reference:TypeBindConflicts=cs0433_2.dll +using TypeBindConflicts; +public class Test +{ + public static void Main() + { + AggPubImpAggPubImp n6 = new AggPubImpAggPubImp(); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0445.md b/docs/csharp/language-reference/compiler-messages/cs0445.md new file mode 100644 index 0000000000000..9621862afc1da --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0445.md @@ -0,0 +1,75 @@ +--- +title: "Compiler Error CS0445 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0445" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0445" +ms.assetid: 43f3e5c5-115c-4a34-b0f3-1b7623c49d64 +caps.latest.revision: 15 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0445 +Cannot modify the result of an unboxing conversion + + The result of an unboxing conversion is a temporary variable. The compiler prevents you from modifying such variables because any modification would go away when the temporary variable goes away. To fix this, declare a new value-type variable to store the intermediate expression, and assign the result of the unboxing conversion to that variable. + + The following code generates CS0455. + +```cs + +// CS0445.CS +class UnboxingTest +{ + public static void Main() + { + Point p; + p.x = 1; + p.y = 2; + object obj = p; + // The following line generates CS0445, because the result + // of unboxing obj is a temporary variable. + ((Point)obj).x = 2; + + // The following lines resolve the error. + + // Store the result of the unboxing conversion in p2. + Point p2; + p2 = (Point)obj; + // Then you can modify the unboxed value. + p2.x = 2; + } +} + +struct Point +{ + public int x, y; +} + +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0446.md b/docs/csharp/language-reference/compiler-messages/cs0446.md new file mode 100644 index 0000000000000..784ab5f71dc1f --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0446.md @@ -0,0 +1,58 @@ +--- +title: "Compiler Error CS0446 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0446" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0446" +ms.assetid: d7a07e24-722e-484d-b6d7-ca809b51858f +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0446 +Foreach cannot operate on a 'Method or Delegate'. Did you intend to invoke the 'Method or Delegate'? + + This error is caused by specifying a method without parentheses or an anonymous method without parentheses in the part of the `foreach` statement where you would normally put a collection class. Note that it is valid, though unusual, to put a method call in that location, if the method returns a collection class. + +## Example + The following code will generate CS0446. + +``` +// CS0446.cs +using System; +class Tester +{ + static void Main() + { + int[] intArray = new int[5]; + foreach (int i in M) { } // CS0446 + } + static void M() { } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0465.md b/docs/csharp/language-reference/compiler-messages/cs0465.md new file mode 100644 index 0000000000000..d8fdfd627030a --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0465.md @@ -0,0 +1,61 @@ +--- +title: "Compiler Warning (level 1) CS0465 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0465" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0465" +ms.assetid: 3d36faae-147f-4173-b164-af953fd86eea +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS0465 +Introducing a 'Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor? + + This warning occurs when you create a class with a method whose signature is `public virtual void Finalize`. + + If such a class is used as a base class and if the deriving class defines a destructor, the destructor will override the base class `Finalize` method, not . + +## Example + The following sample generates CS0465. + +``` +// CS0465.cs +// compile with: /target:library +class A +{ + public virtual void Finalize() {} // CS0465 +} + +// OK +class B +{ + ~B() {} +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0467.md b/docs/csharp/language-reference/compiler-messages/cs0467.md new file mode 100644 index 0000000000000..fd12e103d09b9 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0467.md @@ -0,0 +1,81 @@ +--- +title: "Compiler Warning (level 2) CS0467 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0467" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0467" +ms.assetid: ae082998-afd6-4f82-9c87-6b429ba8fd57 +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Warning (level 2) CS0467 +Ambiguity between method 'method' and non-method 'non-method'.Using method group. + + Inherited members from different interfaces that have the same signature cause an ambiguity error. + +## Example + The following example generates CS0467. + +```cs +// CS0467.cs +interface IList +{ + int Count { get; set; } +} + +interface ICounter +{ + void Count(int i); +} + +interface IListCounter : IList, ICounter {} + +class Driver +{ + void Test(IListCounter x) + { + // The following line causes the warning. The assignment also + // causes an error because you can't assign a value to a method. + x.Count = 1; + x.Count(3); + // To resolve the warning, you can change the name of the method or + // the property. + + // You also can disambiguate by specifying IList or ICounter. + ((IList)x).Count = 1; + ((ICounter)x).Count(3); + } + + static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0504.md b/docs/csharp/language-reference/compiler-messages/cs0504.md new file mode 100644 index 0000000000000..9b0ac4ed7249c --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0504.md @@ -0,0 +1,55 @@ +--- +title: "Compiler Error CS0504 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0504" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0504" +ms.assetid: f2486ffd-aa85-4b40-a89c-a32530b85d1f +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0504 +The constant 'variable' cannot be marked static + + If a variable is [const](../../../csharp/language-reference/keywords/const.md), it is also [static](../../../csharp/language-reference/keywords/static.md). If you want a **const** and **static** variable, just declare that variable as **const**; if all you want is a **static** variable, just mark it **static**. + + The following sample generates CS0504: + +``` +// CS0504.cs +namespace x +{ + abstract public class clx + { + static const int i = 0; // CS0504, cannot be both static and const + abstract public void f(); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0507.md b/docs/csharp/language-reference/compiler-messages/cs0507.md new file mode 100644 index 0000000000000..3fa0f04d8051f --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0507.md @@ -0,0 +1,86 @@ +--- +title: "Compiler Error CS0507 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0507" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0507" +ms.assetid: ddbdb94c-38c3-4022-8d1c-68971d398b87 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0507 +'function1' : cannot change access modifiers when overriding 'access' inherited member 'function2' + + An attempt was made to change the access specification in a method override. + +## Example + The following sample generates CS0507. + +``` +// CS0507.cs +abstract public class clx +{ + virtual protected void f() {} +} + +public class cly : clx +{ + public override void f() {} // CS0507 + public static void Main() {} +} +``` + +## Example + CS0507 can also occur if a class attempts to override a method marked as `protected internal` defined in referenced metadata. In this situation, the overriding method should be marked as `protected`. + +``` +// CS0507_b.cs +// compile with: /target:library +abstract public class clx +{ + virtual protected internal void f() {} +} +``` + +## Example + The following sample generates CS0507. + +``` +// CS0507_c.cs +// compile with: /reference:cs0507_b.dll +public class cly : clx +{ + protected internal override void f() {} // CS0507 + // try the following line instead + // protected override void f() {} // OK + + public static void Main() {} +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0518.md b/docs/csharp/language-reference/compiler-messages/cs0518.md new file mode 100644 index 0000000000000..585f4235059d0 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0518.md @@ -0,0 +1,57 @@ +--- +title: "Compiler Error CS0518 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0518" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0518" +ms.assetid: b0b61cbb-c9a7-48c9-9e60-7cdd5ecb3e6c +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0518 +Predefined type 'type' is not defined or imported + + The main cause for this problem is that the project is not importing mscorlib.dll, which defines the entire System namespace. This can be caused by one of the following: + +- The [/nostdlib](../../../csharp/language-reference/compiler-options/nostdlib-compiler-option.md) option from the command line compiler has been specified. The /nostdlib option prevents the import of mscorlib.dll. Use this option if you want to define or create a user-specific System namespace. + +- An incorrect mscorlib.dll is referenced. + +- A corrupt Visual Studio .NET or .NET Framework common language runtime installation exists. + +- Residual components from an earlier installation that are incompatible with the latest installation remain. + + To resolve this problem, take one of the following actions: + +- Do not specify the /nostdlib option from the command line compiler. + +- Make sure that the project refers to the correct mscorlib.dll. + +- Reinstall the .NET Framework common language runtime (if the previous solutions do not solve the problem). \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0523.md b/docs/csharp/language-reference/compiler-messages/cs0523.md new file mode 100644 index 0000000000000..a66ce6aa377e3 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0523.md @@ -0,0 +1,57 @@ +--- +title: "Compiler Error CS0523 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0523" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0523" +ms.assetid: f91fb0ab-e1ef-4d6d-a3ef-5adc53a7e312 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0523 +Struct member 'struct2 field' of type 'struct1' causes a cycle in the struct layout + + The definitions of two structs include recursive references. Change the [struct](../../../csharp/language-reference/keywords/struct.md) definitions such that each does not define itself on the other. This limitation applies only to structs, since structs are value types. If using recursive references, declare your types as classes. + + The following sample generates CS0523: + +``` +// CS0523.cs +// compile with: /target:library +struct RecursiveLayoutStruct1 +{ + public RecursiveLayoutStruct2 field; +} + +struct RecursiveLayoutStruct2 +{ + public RecursiveLayoutStruct1 field; // CS0523 +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0545.md b/docs/csharp/language-reference/compiler-messages/cs0545.md new file mode 100644 index 0000000000000..3183d7d1c1d6c --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0545.md @@ -0,0 +1,79 @@ +--- +title: "Compiler Error CS0545 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0545" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0545" +ms.assetid: f8c50376-76c4-46ac-9ee1-76cc58005cea +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0545 +'function' : cannot override because 'property' does not have an overridable get accessor + + A try was made to define an override for a property accessor when the base class has no such definition to override. You can resolve this error by: + +- Adding a `set` accessor in the base class. + +- Removing the `set` accessor from the derived class. + +- Hiding the base class property by adding the [new](../../../csharp/language-reference/keywords/new.md) keyword to a property in a derived class. + +- Making the base class property [virtual](../../../csharp/language-reference/keywords/virtual.md). + + For more information, see [Using Properties](../../../csharp/programming-guide/classes-and-structs/using-properties.md). + +## Example + The following sample generates CS0545. + +``` +// CS0545.cs +// compile with: /target:library +// CS0545 +public class a +{ + public virtual int i + { + set {} + + // Uncomment the following line to resolve. + // get { return 0; } + } +} + +public class b : a +{ + public override int i + { + get { return 0; } + set {} // OK + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0552.md b/docs/csharp/language-reference/compiler-messages/cs0552.md new file mode 100644 index 0000000000000..04f872308f3f1 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0552.md @@ -0,0 +1,63 @@ +--- +title: "Compiler Error CS0552 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0552" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0552" +ms.assetid: ce5cfb26-8406-4ca0-adb7-55d1d03d8145 +caps.latest.revision: 6 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0552 +'conversion routine' : user defined conversion to/from interface + + You cannot create a user-defined conversion to or from an interface. If you need the conversion routine, resolve this error by making the interface a class or derive a class from the interface. + + The following sample generates CS0552: + +``` +// CS0552.cs +public interface ii +{ +} + +public class a +{ + // delete the routine to resolve CS0552 + public static implicit operator ii(a aa) // CS0552 + { + return new ii(); + } + + public static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0563.md b/docs/csharp/language-reference/compiler-messages/cs0563.md new file mode 100644 index 0000000000000..f28f300c8d646 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0563.md @@ -0,0 +1,68 @@ +--- +title: "Compiler Error CS0563 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0563" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0563" +ms.assetid: c1561e4e-7f00-41ff-abff-b8228aee66a4 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0563 +One of the parameters of a binary operator must be the containing type + + The method declaration for an [operator overload](../../../csharp/programming-guide/statements-expressions-operators/overloadable-operators.md) must follow certain guidelines. + +## Example + The following sample generates CS0563: + +``` +// CS0563.cs +public class iii +{ + public static implicit operator int(iii x) + { + return 0; + } + public static implicit operator iii(int x) + { + return null; + } + public static int operator +(int aa, int bb) // CS0563 + // Use the following line instead: + // public static int operator +(int aa, iii bb) + { + return 0; + } + public static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0570.md b/docs/csharp/language-reference/compiler-messages/cs0570.md new file mode 100644 index 0000000000000..e5be5ae949f41 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0570.md @@ -0,0 +1,88 @@ +--- +title: "Compiler Error CS0570 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0570" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0570" +ms.assetid: 6b378974-fdd9-451b-b595-6b5b19b4ab48 +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0570 +Property, indexer, or event 'name' is not supported by the language; try directly calling accessor method 'name!' + + This error occurs when using imported metadata that was generated by another compiler. Your code attempted to use a class member that the compiler cannot process. + +## Example + The following C++ program uses an attribute, RequiredAttributeAttribute, which may not be consumed by other languages. + +``` +// CPP0570.cpp +// compile with: /clr /LD + +using namespace System; +using namespace System::Runtime::CompilerServices; + +namespace CS0570_Server { + [RequiredAttributeAttribute(Int32::typeid)] + public ref struct Scenario1 { + int intVar; + }; + + public ref struct CS0570Class { + Scenario1 ^ sc1_field; + + property virtual Scenario1 ^ sc1_prop { + Scenario1 ^ get() { return sc1_field; } + } + + Scenario1 ^ sc1_method() { return sc1_field; } + }; +}; +``` + +## Example + The following sample generates CS0570. + +``` +// CS0570.cs +// compile with: /reference:CPP0570.dll +using System; +using CS0570_Server; + +public class C { + public static int Main() { + CS0570Class r = new CS0570Class(); + r.sc1_field = null; // CS0570 + object o = r.sc1_prop; // CS0570 + r.sc1_method(); // CS0570 + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0571.md b/docs/csharp/language-reference/compiler-messages/cs0571.md new file mode 100644 index 0000000000000..de4b4db0691ce --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0571.md @@ -0,0 +1,77 @@ +--- +title: "Compiler Error CS0571 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0571" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0571" +ms.assetid: 72a97e9c-3c78-47de-b477-dbd2c953d95d +caps.latest.revision: 6 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0571 +'function' : cannot explicitly call operator or accessor + + Certain operators have internal names. For example, **op_Increment** is the internal name of the ++ operator. You should not use or explicitly call such method names. + + The following sample generates CS0571: + +``` +// CS0571.cs +public class MyClass +{ + public static MyClass operator ++ (MyClass c) + { + return null; + } + + public static int prop + { + get + { + return 1; + } + set + { + } + } + + public static void Main() + { + op_Increment(null); // CS0571 + // use the increment operator as follows + // MyClass x = new MyClass(); + // x++; + + set_prop(1); // CS0571 + // try the following line instead + // prop = 1; + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0579.md b/docs/csharp/language-reference/compiler-messages/cs0579.md new file mode 100644 index 0000000000000..e5f08c65d8ea7 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0579.md @@ -0,0 +1,74 @@ +--- +title: "Compiler Error CS0579 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0579" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0579" +ms.assetid: 1a15af7e-60ad-4418-a493-15fdfe08e7db +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0579 +Duplicate 'attribute' attribute + + It is not possible to specify the same attribute more than once unless the attribute specifies **AllowMultiple=true** in its [AttributeUsage](../../../csharp/programming-guide/concepts/attributes/attributeusage.md). + +## Example + The following example generates CS0579. + +```cs +// CS0579.cs +using System; +public class MyAttribute : Attribute +{ +} + +[AttributeUsage(AttributeTargets.All,AllowMultiple=true)] +public class MyAttribute2 : Attribute +{ +} + +public class z +{ + [MyAttribute, MyAttribute] // CS0579 + public void zz() + { + } + + [MyAttribute2, MyAttribute2] // OK + public void zzz() + { + } + + public static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0592.md b/docs/csharp/language-reference/compiler-messages/cs0592.md new file mode 100644 index 0000000000000..37af7a6a2e70f --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0592.md @@ -0,0 +1,66 @@ +--- +title: "Compiler Error CS0592 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0592" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0592" +ms.assetid: 805c8cf0-eca2-4040-badd-a9c09ab5c747 +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0592 +Attribute 'attribute' is not valid on this declaration type. It is valid on 'type' declarations only. + + When you define an attribute, you define what constructs it can be applied to by specifying an `AttributeTargets` value. In the following example, the `MyAttribute` attribute can be applied to interfaces only, because the `AttributeUsage` attribute specifies `AttributeTargets.Iterface`. The error is generated because the attribute is applied to a class (class `A`). + +## Example + The following sample generates CS0592: + +``` +// CS0592.cs +using System; + +[AttributeUsage(AttributeTargets.Interface)] +public class MyAttribute : Attribute +{ +} + +[MyAttribute] +// Generates CS0592 because MyAttribute is not valid for a class. +public class A +{ + public static void Main() + { + } +} +``` + +## See Also + [Attributes](../../../csharp/programming-guide/concepts/attributes/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0616.md b/docs/csharp/language-reference/compiler-messages/cs0616.md new file mode 100644 index 0000000000000..0d658ca792621 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0616.md @@ -0,0 +1,79 @@ +--- +title: "Compiler Error CS0616 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0616" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0616" +ms.assetid: ed60f7bb-40cf-4a93-b823-e29e83df7bf7 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0616 +'class' is not an attribute class + + An attempt was made to use a non-attribute class in an attribute block. All the attribute types need to be inherited from . + +## Example + The following sample generates CS0616. + +``` +// CS0616.cs +// compile with: /target:library +[CMyClass(i = 5)] // CS0616 +public class CMyClass {} +``` + +## Example + The following sample shows how you might define an attribute: + +``` +// CreateAttrib.cs +// compile with: /target:library +using System; + +[AttributeUsage(AttributeTargets.Class|AttributeTargets.Interface)] +public class MyAttr : Attribute +{ + public int Name = 0; + public int Count = 0; + + public MyAttr (int iCount, int sName) + { + Count = iCount; + Name = sName; + } +} + +[MyAttr(5, 50)] +class Class1 {} + +[MyAttr(6, 60)] +interface Interface1 {} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0618.md b/docs/csharp/language-reference/compiler-messages/cs0618.md new file mode 100644 index 0000000000000..8e0a77847f7e1 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0618.md @@ -0,0 +1,69 @@ +--- +title: "Compiler Warning (level 2) CS0618 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0618" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0618" +ms.assetid: b6edf0a9-b186-4ed8-9e16-978659b89205 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 2) CS0618 +'member' is obsolete: 'text' + + A class member was marked with the `Obsolete` attribute, such that a warning will be issued when the class member is referenced. For more information, see [Common Attributes](http://msdn.microsoft.com/library/2f48a7ec-9683-4899-a1d2-a08be8fc558b). + + The following sample generates CS0618: + +``` +// CS0618.cs +// compile with: /W:2 +using System; + +public class C +{ + [Obsolete("Use newMethod instead", false)] // warn if referenced + public static void m2() + { + } + + public static void newMethod() + { + } +} + +class MyClass +{ + public static void Main() + { + C.m2(); // CS0618 + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0650.md b/docs/csharp/language-reference/compiler-messages/cs0650.md new file mode 100644 index 0000000000000..592c44a7aa76e --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0650.md @@ -0,0 +1,82 @@ +--- +title: "Compiler Error CS0650 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0650" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0650" +ms.assetid: c81719ad-343d-4622-8130-41fcb24e3fb5 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0650 +Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type. + + An array was declared incorrectly. In C#, unlike in C and C++, the square brackets follow the type, not the variable name. Also, realize that the syntax for a fixed size buffer differs from that of an array. + +## Example + The following example code generates CS0650. + +``` +// CS0650.cs +public class MyClass +{ + public static void Main() + { +// Generates CS0650. Incorrect array declaration syntax: + int myarray[2]; + + // Correct declaration. + int[] myarray2; + + // Declaration and initialization in one statement + int[] myArray3= new int[2] {1,2} + + // Access an array element. + myarray3[0] = 0; + } +} +``` + +## Example + The following example shows how to use the `fixed` keyword when you create a fixed size buffer: + +``` +// This code must appear in an unsafe block. +public struct MyArray +{ + public fixed char pathName[128]; +} + +``` + +## See Also + [Fixed Size Buffers](../../../csharp/programming-guide/unsafe-code-pointers/fixed-size-buffers.md) + [fixed Statement](../../../csharp/language-reference/keywords/fixed-statement.md) + [Arrays](../../../csharp/programming-guide/arrays/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0675.md b/docs/csharp/language-reference/compiler-messages/cs0675.md new file mode 100644 index 0000000000000..e6e0bda379bd0 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0675.md @@ -0,0 +1,61 @@ +--- +title: "Compiler Warning (level 3) CS0675 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0675" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0675" +ms.assetid: 7465dd8d-2543-44f6-b76b-fcae0ef2580d +caps.latest.revision: 6 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 3) CS0675 +Bitwise-or operator used on a sign-extended operand; consider casting to a smaller unsigned type first + + The compiler implicitly widened and sign-extended a variable, and then used the resulting value in a bitwise OR operation. This can result in unexpected behavior. + + The following sample generates CS0675: + +``` +// CS0675.cs +// compile with: /W:3 +using System; + +public class sign +{ + public static void Main() + { + int hi = 1; + int lo = 1; + long value = (((long)hi) << 32) | lo; // CS0675 + // try the following line instead + // long value = (((long)hi) << 32) | ((uint)lo); // correct + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0686.md b/docs/csharp/language-reference/compiler-messages/cs0686.md new file mode 100644 index 0000000000000..4638264d8f2d7 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0686.md @@ -0,0 +1,101 @@ +--- +title: "Compiler Error CS0686 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0686" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0686" +ms.assetid: 821ea0c9-87d8-4902-8f0b-dcad72312132 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0686 +Accessor 'accessor' cannot implement interface member 'member' for type 'type'. Use an explicit interface implementation. + + Suggested: This error can occur when implementing an interface that contains method names which conflict with the auto-generated methods associated with a property or event. The get/set methods for properties are generated as get_property and set_property, and the add/remove methods for events are generated as add_event and remove_event. If an interface contains either of these methods, a conflict occurs. To avoid this error, implement the methods using an explicit interface implementation. To do this, specify the function as: + +``` + + Interface.get_property() { /* */ } +Interface.set_property() { /* */ } +``` + +## Example + The following sample generates CS0686: + +``` +// CS0686.cs +interface I +{ + int get_P(); +} + +class C : I +{ + public int P + { + get { return 1; } // CS0686 + } +} +// But the following is valid: +class D : I +{ + int I.get_P() { return 1; } + public static void Main() {} +} +``` + +## Example + This error can also occur when declaring events. The event construct automatically generates the `add_``event` and `remove_``event` methods, which could conflict with the methods of the same name in an interface, as in the following sample: + +``` +// CS0686b.cs +using System; + +interface I +{ + void add_OnMyEvent(EventHandler e); +} + +class C : I +{ + public event EventHandler OnMyEvent + { + add { } // CS0686 + remove { } + } +} + +// Correct (using explicit interface implementation): +class D : I +{ + void I.add_OnMyEvent(EventHandler e) {} + public static void Main() {} +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0702.md b/docs/csharp/language-reference/compiler-messages/cs0702.md new file mode 100644 index 0000000000000..d49c5074ad623 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0702.md @@ -0,0 +1,54 @@ +--- +title: "Compiler Error CS0702 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0702" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0702" +ms.assetid: 55952b5b-66a6-4c53-ac53-2e90a363c335 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0702 +Constraint cannot be special class 'identifier' + + The following types may not be used as constraints: `System.Object,``System.Array`, `System.Delegate`, `System.Enum`, or `System.ValueType`. + +## Example + The following sample generates CS0702: + +``` +// CS0702.cs +class C where T : System.Array // CS0702 +{ +} +``` + +## See Also + [Constraints on Type Parameters](../../../csharp/programming-guide/generics/constraints-on-type-parameters.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0703.md b/docs/csharp/language-reference/compiler-messages/cs0703.md new file mode 100644 index 0000000000000..b771743637025 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0703.md @@ -0,0 +1,53 @@ +--- +title: "Compiler Error CS0703 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0703" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0703" +ms.assetid: 3f488412-248e-40ad-9d76-96cb3eb73778 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0703 +Inconsistent accessibility: constraint type 'identifier' is less accessible than 'identifier' + + A constraint may not force the generic parameter to be less accessible than the generic class itself. In the following example, while the generic class C\ is declared public, the constraint attempts to force T to implement an internal interface. Even if this were allowed, only clients with internal access would be able to create the parameter for the class, so in effect, the class could be used only by clients with internal access. + + To get rid of this error, make sure the access level of the generic class is not less restrictive than any classes or interfaces that appear in the bounds. + + The following sample generates CS0703: + +``` +// CS0703.cs +internal interface I {} +public class C where T : I // CS0703 – I is internal; C is public +{ +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0731.md b/docs/csharp/language-reference/compiler-messages/cs0731.md new file mode 100644 index 0000000000000..045c33c04e613 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0731.md @@ -0,0 +1,143 @@ +--- +title: "Compiler Error CS0731 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0731" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0731" +ms.assetid: b2df5d5c-b1cd-4620-881f-f5a492669784 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0731 +The type forwarder for type 'type' in assembly 'assembly' causes a cycle + + This error can only occur with improperly formed imported metadata. It cannot occur with only C# source. + +## Example + The following sample generates CS0731. The example consists of three files: + + 1. Circular.IL + + 2. Circular2.IL + + 3. CS0731.cs + + First compile the .IL files as libraries, and then compile the .cs code referencing the two files. + +``` +// Circular.il +// compile with: /DLL /out=Circular.dll +.assembly extern circular2 +{ + .ver 0:0:0:0 +} +.assembly extern circular3 +{ + .ver 0:0:0:0 +} +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 2:0:0:0 +} +.assembly Circular +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.class extern forwarder Circular.Referenced.TypeForwarder +{ + .assembly extern circular2 +} +.module Circular.dll +// MVID: {880C2329-C915-42A0-83E9-9D10C3E6DBD0} +.imagebase 0x00400000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x04E40000 +// ======== CLASS MEMBERS DECLARATION ========= +.class public abstract auto ansi sealed beforefieldinit User + extends [mscorlib]System.Object +{ + .method public hidebysig static class [circular2]Circular.Referenced.TypeForwarder + F() cil managed + { + .maxstack 1 + newobj instance void [circular2]Circular.Referenced.TypeForwarder::.ctor() + ret + } +} +``` + +``` +// Circular2.il +// compile with: /DLL /out=Circular2.dll +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 2:0:0:0 +} +.assembly extern Circular +{ + .ver 0:0:0:0 +} +.assembly circular2 +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.class extern forwarder Circular.Referenced.TypeForwarder +{ + .assembly extern Circular +} +.module circular2.dll +// MVID: {8B3BE5C8-DBE1-49C4-BC72-DF35F0387C21} +.imagebase 0x00400000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x04E40000 +``` + +``` +// CS0731.cs +// compile with: /reference:circular.dll /reference:circular2.dll +// CS0731 expected +class A { + public static void Main() { + User.F(); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0826.md b/docs/csharp/language-reference/compiler-messages/cs0826.md new file mode 100644 index 0000000000000..b36b19b9eec09 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0826.md @@ -0,0 +1,76 @@ +--- +title: "Compiler Error CS0826 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0826" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0826" +ms.assetid: baa68741-2813-4bdd-9312-dd45fdf10701 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0826 +No best type found for implicitly typed array. + + Array elements must all be the same type or implicitly convertible to the same type according to the type inference rules used by the compiler. The best type must be one of the types present in the array expression. Elements will not be converted to a new type such as `object`. For an implicitly typed array, the compiler must infer the array type based on the type of elements assigned to it. + +## To correct this error + +- Give the array an explicit type. + +- Give all array elements the same type. + +- Provide explicit casts on those elements that might be causing the problem. + +## Example + The following code generates CS0826 because the array elements are not all the same type, and the compiler's type inference logic does not find a single best type: + +``` +// cs0826.cs +public class C +{ + public static int Main() + { + var x = new[] { 1, "str" }; // CS0826 + + char c = 'c'; + short s1 = 0; + short s2 = -0; + short s3 = 1; + short s4 = -1; + + var array1 = new[] { s1, s2, s3, s4, c, '1' }; // CS0826 + return 1; + } +} + +``` + +## See Also + [Implicitly Typed Local Variables](../../../csharp/programming-guide/classes-and-structs/implicitly-typed-local-variables.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0834.md b/docs/csharp/language-reference/compiler-messages/cs0834.md new file mode 100644 index 0000000000000..f72aca2b12898 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0834.md @@ -0,0 +1,64 @@ +--- +title: "Compiler Error CS0834 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0834" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0834" +ms.assetid: f3d26696-eeb4-4ea3-9667-b8f51577567e +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0834 +A lambda expression must have an expression body to be converted to an expression tree. + + Lambdas that are translated to expression trees must be expression lambdas; statement lambdas and anonymous methods can only be converted to delegate types. + +## To correct this error + +1. Remove the statement from the lambda expression. + +## Example + The following example generates CS0834: + +``` +// cs0834.cs +using System; +using System.Linq; +using System.Linq.Expressions; + +public class C +{ + public static int Main() + { + Expression> e = x => { return x; }; // CS0834 + } +} + +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0840.md b/docs/csharp/language-reference/compiler-messages/cs0840.md new file mode 100644 index 0000000000000..186bc2cc2e80f --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0840.md @@ -0,0 +1,66 @@ +--- +title: "Compiler Error CS0840 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0840" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0840" +ms.assetid: f307083f-8d86-4142-a9fd-b735910687b2 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0840 +'Property name' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors. + + Unless a regular property is marked as `abstract` or `extern`, or is a member of a `partial` type, it must supply a body. Auto-implemented properties do not provide accessor bodies, but they must specify both accessors. To create a read-only auto-implemented property, make the set accessor `private`. + +## To correct this error + +1. Supply the missing body or accessor or else use the [abstract](../../../csharp/language-reference/keywords/abstract.md), [extern](../../../csharp/language-reference/keywords/extern.md), or [partial (Type)](../../../csharp/language-reference/keywords/partial-type.md) modifiers on it and/or its enclosing type. + +## Example + The following example generates CS0840: + +``` +// cs0840.cs +// Compile with /target:library +using System; +class Test +{ + public int myProp { get; } // CS0840 + + // to create a read-only property + // try the following line instead + public int myProp2 { get; private set; } + +} +``` + +## See Also + [Auto-Implemented Properties](../../../csharp/programming-guide/classes-and-structs/auto-implemented-properties.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0843.md b/docs/csharp/language-reference/compiler-messages/cs0843.md new file mode 100644 index 0000000000000..5c14594f4f5ac --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0843.md @@ -0,0 +1,70 @@ +--- +title: "Compiler Error CS0843 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0843" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0843" +ms.assetid: 5d9e01f5-9581-46e4-8d1b-9c3ffc438570 +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0843 +Backing field for automatically implemented property 'name' must be fully assigned before control is returned to the caller. Consider calling the default constructor from a constructor initializer. + + To assign a value to an automatically-implemented property from a constructor, you must first invoke the default constructor to create the object. + +## To correct this error + +1. Add a call to the default constructor in a constructor initializer as shown in the following example. Note the use of `: this()`. For more information, see [this](../../../csharp/language-reference/keywords/this.md). + +## Example + The following code generates CS0843: + +``` +// cs0843.cs +struct S +{ + public int AIProp { get; set; } + public S(int i){} //CS0843 + // Try the following lines instead. + // public S(int i) : this() + // { + // AIProp = i; + // } +} + +class Test +{ + static int Main() + { + return 1; + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs0845.md b/docs/csharp/language-reference/compiler-messages/cs0845.md new file mode 100644 index 0000000000000..24bf616137c53 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs0845.md @@ -0,0 +1,68 @@ +--- +title: "Compiler Error CS0845 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS0845" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS0845" +ms.assetid: ed1d5fd1-d525-416e-91ab-2ce1aff0f83b +caps.latest.revision: 5 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS0845 +An expression tree lambda may not contain a coalescing operator with a null literal left-hand side. + + Because null by itself does not have a type, the null coalescing operator cannot operate on it. + +## To correct this error + +1. Cast the null literal to an object. + +## Example + The following code generates CS0845: + +``` +// cs0845.cs +using System; +using System.Linq; +using System.Linq.Expressions; + +namespace ConsoleApplication1 +{ + class Program + { + static void Main(string[] args) + { + Expression> e = () => null ?? null; // CS0845 + // Try the following line instead. + // Expression> e = () => (object)null ?? null; + } + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1001.md b/docs/csharp/language-reference/compiler-messages/cs1001.md new file mode 100644 index 0000000000000..ea118138a8c00 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1001.md @@ -0,0 +1,96 @@ +--- +title: "Compiler Error CS1001 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1001" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1001" +ms.assetid: 327ad669-9c20-4fe8-a771-234878dbb90e +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1001 +Identifier expected + + You did not supply an identifier. An identifier is the name of a class, struct, namespace, method, variable and so on that you provide. + + The following example declares a simple class but does not give the class a name: + +``` +//cs1001.cs +public class //CS1001 + { + public int Num {get; set;} + void MethodA(){} + } +``` + + The following sample generates CS1001 because, when declaring an enum, you must specify members: + +``` +// CS1001.cs +public class clx +{ + enum Colors : int + { + 'a', 'b' // CS1001, 'a' is not a valid int identifier + // The following line shows examples of valid identifiers: + // Blue, Red, Orange + }; + + public static void Main() + { + } +} + +``` + + Parameter names are required even if the compiler doesn't use them, for example, in an interface definition. These parameters are required so that programmers who are consuming the interface know something about the what the parameters mean. + +``` +// CS1001-2.cs +// compile with: /target:library +interface IMyTest +{ + void TestFunc1(int, int); // CS1001 + // Use the following line instead: + // void TestFunc1(int a, int b); +} + +class CMyTest : IMyTest +{ + void IMyTest.TestFunc1(int a, int b) + { + } +} +``` + +## See Also + [Statements, Expressions, and Operators](../../../csharp/programming-guide/statements-expressions-operators/index.md) + [Types](../../../csharp/programming-guide/types/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1009.md b/docs/csharp/language-reference/compiler-messages/cs1009.md new file mode 100644 index 0000000000000..0b8ba64f8ab31 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1009.md @@ -0,0 +1,83 @@ +--- +title: "Compiler Error CS1009 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1009" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1009" +ms.assetid: 348f500c-0e4f-44d7-95a8-e215ac49940a +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1009 +Unrecognized escape sequence + + An unexpected character follows a backslash (\\) in a [string](../../../csharp/language-reference/keywords/string.md). The compiler expects one of the valid escape characters. For more information, see [Character Escapes](http://msdn.microsoft.com/library/f49cc9cc-db7d-4058-8b8a-422bc08b29b0). + + The following sample generates CS1009. + +```cs +// CS1009-a.cs +class MyClass +{ + static void Main() + { + // The following line causes CS1009. + string a = "\m"; + // Try the following line instead. + // string a = "\t"; + } +} +``` + + A common cause of this error is using the backslash character in a file name, as the following example shows. + +```cs +string filename = "c:\myFolder\myFile.txt"; +``` + + To resolve this error, use "\\\\" or the @-quoted string literal, as the following example shows. + +```cs +// CS1009-b.cs +class MyClass +{ + static void Main() + { + // The following line causes CS1009. + string filename = "c:\myFolder\myFile.txt"; + // Try one of the following lines instead. + // string filename = "c:\\myFolder\\myFile.txt"; + // string filename = @"c:\myFolder\myFile.txt"; + } +} +``` + +## See Also + [string](../../../csharp/language-reference/keywords/string.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1018.md b/docs/csharp/language-reference/compiler-messages/cs1018.md new file mode 100644 index 0000000000000..ea95edfe9adc8 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1018.md @@ -0,0 +1,71 @@ +--- +title: "Compiler Error CS1018 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1018" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1018" +ms.assetid: f6dc7f6a-57fd-4c9e-8699-add3218af983 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1018 +Keyword 'this' or 'base' expected + + The compiler encountered an incomplete constructor declaration. + +## Example + The following example generates CS1018, and suggests several ways to resolve the error: + +``` +// CS1018.cs +public class C +{ +} + +public class a : C +{ + public a(int i) + { + } + + public a () : // CS1018 + // possible resolutions: + // public a () resolves by removing the colon + // public a () : base() calls C's default constructor + // public a () : this(1) calls the assignment constructor of class a + { + } + + public static int Main() + { + return 1; + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1019.md b/docs/csharp/language-reference/compiler-messages/cs1019.md new file mode 100644 index 0000000000000..2af573a8ae5b6 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1019.md @@ -0,0 +1,91 @@ +--- +title: "Compiler Error CS1019 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1019" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1019" +ms.assetid: 11a3acd8-bcab-4ead-a91b-a1498ea1eab5 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Error CS1019 +Overloadable unary operator expected + + Something that looks like an overloaded unary operator has been declared, but the operator is missing or is in the wrong location in the signature. + + A *unary operator* is an operator that operates on a single operand. For example, `++` is a unary operator. You can overload some unary operators by using the `operator` keyword and specifying a single parameter of the type that the operator operates on. For example, if you want to overload the operator `++` for a user-defined class `Temperature` so that you can write `Temperature++`, you can define it in this way: + +```cs +public static Temperature operator ++ (Temperature temp) +{ + temp.Degrees++; + return temp; +} +``` + + When you receive this error, you have declared something that looks like an overloaded unary operator, except that the operator itself is missing or is in the wrong location in the signature. If you remove the `++` from the signature in the previous example, you will generate CS1019. + + The following code generates CS1019: + +```cs +// CS1019.cs +public class ii +{ + int i + { + get + { + return 0; + } + } +} + +public class a +{ + public int i; +// Generates CS1019: "ii" is not a unary operator. + public static a operator ii(a aa) + + // Use the following line instead: + //public static a operator ++(a aa) + { + aa.i++; + return aa; + } + + public static void Main() + { + } +} +``` + +## See Also + [Operators](../../../csharp/programming-guide/statements-expressions-operators/operators.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1026.md b/docs/csharp/language-reference/compiler-messages/cs1026.md new file mode 100644 index 0000000000000..db7f6a0d301fa --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1026.md @@ -0,0 +1,74 @@ +--- +title: "Compiler Error CS1026 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1026" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1026" +ms.assetid: 782c0570-19c2-425d-aa41-565d33aa9bc0 +caps.latest.revision: 5 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1026 +) expected + + An incomplete statement was found. + + A common cause of this error is placing a statement, rather than an expression, within an inline expression in an ASP.NET page. For example, the following is incorrect: + +``` +<%=new TimeSpan(DateTime.Now.Ticks - new DateTime(2001, 1, 1).Ticks).Days;%> +``` + + The following is correct: + +``` +<%=new TimeSpan(DateTime.Now.Ticks - new DateTime(2001, 1, 1).Ticks).Days %> +``` + + It is interpreted as follows: + +``` +<% Response.Write(new TimeSpan(DateTime.Now.Ticks - new DateTime(2001, 1, 1).Ticks).Days); %> +``` + + The following example generates CS1026: + +``` +// CS1026.cs +#if (a == b // CS1026, add closing ) +#endif + +class x +{ + public static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1029.md b/docs/csharp/language-reference/compiler-messages/cs1029.md new file mode 100644 index 0000000000000..13bbcc100ecb0 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1029.md @@ -0,0 +1,54 @@ +--- +title: "Compiler Error CS1029 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1029" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1029" +ms.assetid: 61bd4d44-9bfc-42bb-a9f0-a0683da53640 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1029 +\#error: 'text' + + Displays the text of an error defined with the [#error](../../../csharp/language-reference/preprocessor-directives/preprocessor-error.md) directive. + + The following sample shows how to create a user-defined error: + +``` +// CS1029.cs +class Sample +{ + static void Main() + { + #error Let's give an error here // CS1029 + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1058.md b/docs/csharp/language-reference/compiler-messages/cs1058.md new file mode 100644 index 0000000000000..b9088f82bcaa2 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1058.md @@ -0,0 +1,70 @@ +--- +title: "Compiler Warning (level 1) CS1058 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1058" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1058" +ms.assetid: ed50590c-f130-47c3-976d-322a6c8f996d +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1058 +A previous catch clause already catches all exceptions. All exceptions thrown will be wrapped in a System.Runtime.CompilerServices.RuntimeWrappedException + + This attribute causes CS1058 if a `catch()` block has no specified exception type after a `catch (System.Exception e)` block. The warning advises that the `catch()` block will not catch any exceptions. + + A `catch()` block after a `catch (System.Exception e)` block can catch non-CLS exceptions if the `RuntimeCompatibilityAttribute` is set to false in the AssemblyInfo.cs file: `[assembly: RuntimeCompatibilityAttribute(WrapNonExceptionThrows = false)]`. If this attribute is not set explicitly to false, all thrown non-CLS exceptions are wrapped as Exceptions and the `catch (System.Exception e)` block catches them. For more information, see [How to: Catch a non-CLS Exception](../../../csharp/programming-guide/exceptions/how-to-catch-a-non-cls-exception.md). + +## Example + The following example generates CS1058. + +``` +// CS1058.cs +// CS1058 expected +using System.Runtime.CompilerServices; + +// the following attribute is set to true by default in the C# compiler +// set to false in your source code to resolve CS1058 +[assembly: RuntimeCompatibilityAttribute(WrapNonExceptionThrows = true)] + +class TestClass +{ + static void Main() + { + try {} + + catch (System.Exception e) { + System. Console.WriteLine("Caught exception {0}", e); + } + + catch {} // CS1058. This line will never be reached. + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1060.md b/docs/csharp/language-reference/compiler-messages/cs1060.md new file mode 100644 index 0000000000000..86e54ebfe6012 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1060.md @@ -0,0 +1,85 @@ +--- +title: "Compiler Warning (level 1) CS1060 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1060" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1060" +ms.assetid: af389239-672b-449e-84b5-edb52e320013 +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1060 +Use of possibly unassigned field 'name'. Struct instance variables are initially unassigned if struct is unassigned. + + Struct members are initialized to their default value if you do not explicitly initialize them. The default value for class types (and other reference types) is null. If the class is not initialized before any attempt to access it, a `NullReferenceException` will be thrown at runtime. The compiler cannot determine definitively whether the class member will be initialized or not, and so CS1060 is a warning and not an error. + +## To correct this error + +1. Provide a constructor for the `struct` that initializes all its members. + +## Example + The following code generates CS1060 because the class type `U` is a member of the `struct S` but is never initialized. + +``` +// cs1060.cs +namespace CS1060 +{ + public class U + { + public int i; + } + + public struct S + { + public U u; + // Add constructor to correct the error. + //public S(int val) + //{ + // u = new U() { i = val }; + //} + } + public class Test + { + static void Main() + { + S s; + s.u.i = 5; // CS1060 + + //Try these lines instead, and uncomment the constructor in S + // S s = new S(0); + // s.u.i = 5; + + } + } +} +``` + +## See Also + [Structs](../../../csharp/programming-guide/classes-and-structs/structs.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1061.md b/docs/csharp/language-reference/compiler-messages/cs1061.md new file mode 100644 index 0000000000000..50d7ff65fda95 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1061.md @@ -0,0 +1,86 @@ +--- +title: "Compiler Error CS1061 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1061" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1061" +ms.assetid: 10ba0509-d541-43da-acf5-eaa7987e41d4 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1061 +'type' does not contain a definition for 'member' and no extension method 'name' accepting a first argument of type 'type' could be found (are you missing a using directive or an assembly reference?). + + This error occurs when you try to call a method or access a class member that does not exist. + +## Example + The following example generates CS1061 because `TestClass1` does not have a `DisplaySomething` method. It does have a method that is called `WriteSomething`. Perhaps that is what the author of this source code meant to write. + +```cs +// cs1061.cs +public class TestClass1 +{ + // TestClass1 has one method, called WriteSomething. + public void WriteSomething(string s) + { + System.Console.WriteLine(s); + } +} + +public class TestClass2 +{ + // TestClass2 has one method, called DisplaySomething. + public void DisplaySomething(string s) + { + System.Console.WriteLine(s); + } +} + +public class TestTheClasses +{ + public static void Main() + { + TestClass1 tc1 = new TestClass1(); + TestClass2 tc2 = new TestClass2(); + // The following call fails because TestClass1 does not have + // a method called DisplaySomething. + tc1.DisplaySomething("Hello"); // CS1061 + + // To correct the error, change the method call to either + // tc1.WriteSomething or tc2.DisplaySomething. + tc1.WriteSomething("Hello from TestClass1"); + tc2.DisplaySomething("Hello from TestClass2"); + } +} +``` + +## See Also + [Classes and Structs](../../../csharp/programming-guide/classes-and-structs/index.md) + [Extension Methods](../../../csharp/programming-guide/classes-and-structs/extension-methods.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1112.md b/docs/csharp/language-reference/compiler-messages/cs1112.md new file mode 100644 index 0000000000000..1d02a37b8adb7 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1112.md @@ -0,0 +1,61 @@ +--- +title: "Compiler Error CS1112 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1112" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1112" +ms.assetid: 72c5f497-8572-41c7-8243-0d5670daca3f +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1112 +Do not use 'System.Runtime.CompilerServices.ExtensionAttribute'. Use the 'this' keyword instead. + + This error is generated when the is used on a non-static class that contains extension methods. If this attribute is used on a static class, another error, such as CS0708: "Cannot declare instance members in a static class," might occur. + + In C#, extension methods must be defined in a static class and the first parameter of the method is modified with the `this` keyword. Do not use the attribute at all in the source code. For more information, see [Extension Methods](../../../csharp/programming-guide/classes-and-structs/extension-methods.md). + +## To correct this error + +1. Remove the attribute and apply the `this` modifier to the first parameter of the method. + +## Example + The following example generates CS1112: + +``` +// cs1112.cs +[System.Runtime.CompilerServices.ExtensionAttribute] // CS1112 +public class Extensions +{ + public bool A(bool b) { return b; } +} + +class A { } +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1501.md b/docs/csharp/language-reference/compiler-messages/cs1501.md new file mode 100644 index 0000000000000..122d169aed203 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1501.md @@ -0,0 +1,87 @@ +--- +title: "Compiler Error CS1501 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1501" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1501" +ms.assetid: 99a59646-e2c8-4ee5-9785-4a2c1ae77458 +caps.latest.revision: 17 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Error CS1501 +No overload for method 'method' takes 'number' arguments + + A call was made to a class method, but no definition of the method takes the specified number of arguments. + +## Example + The following sample generates CS1501. + +```cs +using System; + +namespace ConsoleApplication1 +{ + class Program + { + static void Main(string[] args) + { + ExampleClass ec = new ExampleClass(); + ec.ExampleMethod(); + ec.ExampleMethod(10); + // The following line causes compiler error CS1501 because + // ExampleClass does not contain an ExampleMethod that takes + // two arguments. + ec.ExampleMethod(10, 20); + } + } + + // ExampleClass contains two overloads for ExampleMethod. One of them + // has no parameters and one has a single parameter. + class ExampleClass + { + public void ExampleMethod() + { + Console.WriteLine("Zero parameters"); + } + + public void ExampleMethod(int i) + { + Console.WriteLine("One integer parameter."); + } + + //// To fix the error, you must add a method that takes two arguments. + //public void ExampleMethod (int i, int j) + //{ + // Console.WriteLine("Two integer parameters."); + //} + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1502.md b/docs/csharp/language-reference/compiler-messages/cs1502.md new file mode 100644 index 0000000000000..dc85a5a5304ec --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1502.md @@ -0,0 +1,73 @@ +--- +title: "Compiler Error CS1502 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1502" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1502" +ms.assetid: f302f00a-5fe1-4e42-b91c-f185d6311671 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1502 +The best overloaded method match for 'name' has some invalid arguments + + This error occurs when the argument types being passed to the method do not match the parameter types of that method. If the called method is overloaded, then none of the overloaded versions has a signature that matches the argument types being passed. + + To resolve this problem, do one of the following: + +- Double-check the types of the arguments being passed. Make sure that they match the arguments of the method being called. + +- If appropriate, convert any mismatched parameters using the class. + +- If appropriate, cast any mismatched parameters to match the type that the method is expecting. + +- If appropriate, define another overloaded version of the method to match the parameter types that are being sent. + + The following sample generates CS1502: + +``` +// CS1502.cs +namespace x +{ + public class a + { + public a(char i) + // try the following constructor instead + // public a(int i) + { + } + + public static void Main() + { + a aa = new a(2222); // CS1502 + } + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1519.md b/docs/csharp/language-reference/compiler-messages/cs1519.md new file mode 100644 index 0000000000000..169b3c1c702f9 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1519.md @@ -0,0 +1,71 @@ +--- +title: "Compiler Error CS1519 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1519" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1519" +ms.assetid: 186cef8e-c6c7-49aa-8b43-f6c2cb628414 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1519 +Invalid token 'token' in class, struct, or interface member declaration + + This error is generated whenever a token is encountered in a location where it does not belong. A *token* is a keyword; an identifier (the name of a class, struct, method, and so on); a string, character, or numeric literal value such as 108, "Hello", or 'A'; or an operator or punctuator such as `==` or `;`. + + Any [class](../../../csharp/language-reference/keywords/class.md), struct, or interface member declaration that contains invalid modifiers before the type will generate this error. To fix the error, remove the invalid modifiers. + + The following sample generates CS1519 in five places because tokens are placed in locations where they are not valid: + +```cs +// CS1519.cs +// Generates CS1519 because a class name cannot be a number: +class Test 42 +{ +// Generates CS1519 because of 'j' following 'I' +// with no comma between them: + int i j; +// Generates CS1519 because of "checked" on void method: + checked void f4(); + +// Generates CS1519 because of "num": + void f5(int a num){} + +// Generates CS1519 because of namespace inside class: + namespace; + +} +``` + +## See Also + [Classes](../../../csharp/programming-guide/classes-and-structs/classes.md) + [Structs](../../../csharp/programming-guide/classes-and-structs/structs.md) + [Interfaces](../../../csharp/programming-guide/interfaces/index.md) + [Methods](../../../csharp/programming-guide/classes-and-structs/methods.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1540.md b/docs/csharp/language-reference/compiler-messages/cs1540.md new file mode 100644 index 0000000000000..6bdcd633981c8 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1540.md @@ -0,0 +1,103 @@ +--- +title: "Compiler Error CS1540 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1540" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1540" +ms.assetid: f35bbeb9-e2b2-4644-a7e6-cc2dbce1bd44 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Error CS1540 +Cannot access protected member 'member' via a qualifier of type 'type1'; the qualifier must be of type 'type2' (or derived from it) + + A derived [class](../../../csharp/language-reference/keywords/class.md) cannot access protected members of its base class through an instance of the base class. An instance of the base class declared in the derived class might, at run time, be an instance of another type that is derived from the same base but is not otherwise related to the derived class. Because protected members can be accessed only by derived types, any attempts to access protected members that might not be valid at run time are marked by the compiler as not valid. + + In the `Employee` class in the following example, `emp2` and `emp3` both have type `Person` at compile time, but `emp2` has type `Manager` at run time. Because `Employee` is not derived from `Manager`, it cannot access the protected members of the base class, `Person`, through an instance of the `Manager` class. The compiler cannot determine what the run-time type of the two `Person` objects will be. Therefore, both the call from `emp2` and the call from `emp3` cause compiler error CS1540. + +```cs +using System; +using System.Text; + +namespace CS1540 +{ + class Program1 + { + static void Main() + { + Employee.PreparePayroll(); + } + } + + class Person + { + protected virtual void CalculatePay() + { + Console.WriteLine("CalculatePay in Person class."); + } + } + + class Manager : Person + { + protected override void CalculatePay() + { + Console.WriteLine("CalculatePay in Manager class."); + + } + } + + class Employee : Person + { + public static void PreparePayroll() + { + Employee emp1 = new Employee(); + Person emp2 = new Manager(); + Person emp3 = new Employee(); + // The following line calls the method in the Employee base class, + // Person. + emp1.CalculatePay(); + + // The following lines cause compiler error CS1540. The compiler + // cannot determine at compile time what the run-time types of + // emp2 and emp3 will be. + //emp2.CalculatePay(); + //emp3.CalculatePay(); + + } + } +} +``` + +## See Also + [Inheritance](../../../csharp/programming-guide/classes-and-structs/inheritance.md) + [Polymorphism](../../../csharp/programming-guide/classes-and-structs/polymorphism.md) + [Access Modifiers](../../../csharp/programming-guide/classes-and-structs/access-modifiers.md) + [Abstract and Sealed Classes and Class Members](../../../csharp/programming-guide/classes-and-structs/abstract-and-sealed-classes-and-class-members.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1546.md b/docs/csharp/language-reference/compiler-messages/cs1546.md new file mode 100644 index 0000000000000..db98dbf2936b3 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1546.md @@ -0,0 +1,83 @@ +--- +title: "Compiler Error CS1546 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1546" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1546" +ms.assetid: 15fe2cdc-954f-4c67-80fd-9903c464f361 +caps.latest.revision: 14 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1546 +Property, indexer, or event 'property' is not supported by the language; try directly calling accessor method 'accessor' + + Your code is consuming an object that has a default indexed property and tried to use the indexed syntax. To resolve this error, call the property's accessor method. For more information on indexers and properties, see [Indexers](../../../csharp/programming-guide/indexers/index.md). + + The following sample generates CS1546. + +## Example + This code sample consists of a .cpp file, which compiles to a .dll, and a .cs file, which uses that .dll. The following code is for the .dll file, and defines a property to be accessed by the code in the .cs file. + +``` +// CPP1546.cpp +// compile with: /clr /LD +using namespace System; +public ref class MCPP +{ +public: + property int Prop [int,int] + { + int get( int i, int b ) + { + return i; + } + } +}; +``` + +## Example + This is the C# file. + +``` +// CS1546.cs +// compile with: /r:CPP1546.dll +using System; +public class Test +{ + public static void Main() + { + int i = 0; + MCPP mcpp = new MCPP(); + i = mcpp.Prop(1,1); // CS1546 + // Try the following line instead: + // i = mcpp.get_Prop(1,1); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1548.md b/docs/csharp/language-reference/compiler-messages/cs1548.md new file mode 100644 index 0000000000000..d358a48a430c9 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1548.md @@ -0,0 +1,50 @@ +--- +title: "Compiler Error CS1548 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1548" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1548" +ms.assetid: 63a467fa-d85f-4876-a8c9-2ae5fdebebab +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1548 +Cryptographic failure while signing assembly 'assembly' — 'reason' + + CS1548 occurs when assembly signing fails. This is usually due to an invalid key file name, an invalid key file path, or a corrupt key file. + + To fully sign an assembly, you must provide a valid key file that contains information about the public and private keys. To delay sign an assembly, you must select the **Delay sign only** check box and provide a valid key file that contains information about the public key information. The private key is not necessary when an assembly is delay-signed. + + For more information, see [How to: Sign an Assembly (Visual Studio)](http://msdn.microsoft.com/en-us/f468a7d3-234c-4353-924d-8e0ae5896564), [/keyfile (C# Compiler Options)](../../../csharp/language-reference/compiler-options/keyfile-compiler-option.md) and [/delaysign (C# Compiler Options)](../../../csharp/language-reference/compiler-options/delaysign-compiler-option.md). + + When creating an assembly, the C# compiler calls into a utility called al.exe. If there is a failure in the assembly creation, the reason for the failure is reported by al.exe. See [Al.exe Tool Errors and Warnings](http://msdn.microsoft.com/en-us/7f125d49-0a03-47a6-9ba9-d61a679a7d4b) and search that topic for the text reported by the compiler in 'reason'. + +## See Also + [How to: Sign an Assembly (Visual Studio)](http://msdn.microsoft.com/en-us/f468a7d3-234c-4353-924d-8e0ae5896564) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1564.md b/docs/csharp/language-reference/compiler-messages/cs1564.md new file mode 100644 index 0000000000000..fb9a3dfc1b02e --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1564.md @@ -0,0 +1,66 @@ +--- +title: "Compiler Error CS1564 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1564" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1564" +ms.assetid: 32206075-a14b-4c24-bd78-257104078f83 +caps.latest.revision: 6 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1564 +Conflicting options specified: Win32 resource file; Win32 manifest. + + If you use the **/Win32res** compiler option, you must include the custom Win32 manifest (if it is required) in the resource file. You cannot provide a custom Win32 manifest separately from a Win32 resource file. Use the **/win32manifest** option only if you are not specifying a win32 resource file. + +## To correct this error + +1. Add the win32 manifest to the win32 resource file and remove the **/win32manifest** compiler option. + +## Example + The following example produces CS1564 if it is compiled with the **/Win32res** option and no manifest is included in the resource file. + +``` +// cs1564.cs +// Compile with: /Win32res +public class Test +{ + static int Main(string[] args) + { + return 1; + } +} +``` + + The C# 3.0 compiler adds a default win32Manifest to all binaries. + +## See Also + [/win32manifest (C# Compiler Options)](../../../csharp/language-reference/compiler-options/win32manifest-compiler-option.md) + [/win32res (C# Compiler Options)](../../../csharp/language-reference/compiler-options/win32res-compiler-option.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1567.md b/docs/csharp/language-reference/compiler-messages/cs1567.md new file mode 100644 index 0000000000000..29325246f0f87 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1567.md @@ -0,0 +1,43 @@ +--- +title: "Compiler Error CS1567 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1567" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1567" +ms.assetid: 837b9855-191b-4384-ad45-52960906679c +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1567 +Error generating Win32 resource: 'file' + + Your compilation either used the [/win32icon](../../../csharp/language-reference/compiler-options/win32icon-compiler-option.md) compiler option or did not use [/win32res](../../../csharp/language-reference/compiler-options/win32res-compiler-option.md), which causes the compiler to generate a file that contains resource information, but the compiler was unable to create the file due to insufficient disk space or some other error. + + If you are unable to resolve the file-generation problem, you could use [/win32res](../../../csharp/language-reference/compiler-options/win32res-compiler-option.md), which does not generate a file that contains resource information. \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1579.md b/docs/csharp/language-reference/compiler-messages/cs1579.md new file mode 100644 index 0000000000000..91faf3b4c74f0 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1579.md @@ -0,0 +1,112 @@ +--- +title: "Compiler Error CS1579 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1579" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1579" +ms.assetid: 1eba84ce-58df-4fe3-9134-e26efefdc4ab +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1579 +foreach statement cannot operate on variables of type 'type1' because 'type2' does not contain a public definition for 'identifier' + + To iterate through a collection using the [foreach](../../../csharp/language-reference/keywords/foreach-in.md) statement, the collection must meet the following requirements: + +- It must be an interface, class or struct. + +- It must include a public method that returns a type. + +- The return type must contain a public property named , and a public method named . + +- For more information, see [How to: Access a Collection Class with foreach](../../../csharp/programming-guide/classes-and-structs/how-to-access-a-collection-class-with-foreach.md). + +## Example + In this sample, [foreach](../../../csharp/language-reference/keywords/foreach-in.md) is not able to iterate through the collection because there is no `public` method in `MyCollection`. + + The following sample generates CS1579. + +``` +// CS1579.cs +using System; +public class MyCollection +{ + int[] items; + public MyCollection() + { + items = new int[5] {12, 44, 33, 2, 50}; + } + + // Delete the following line to resolve. + MyEnumerator GetEnumerator() + + // Uncomment the following line to resolve: + // public MyEnumerator GetEnumerator() + { + return new MyEnumerator(this); + } + + // Declare the enumerator class: + public class MyEnumerator + { + int nIndex; + MyCollection collection; + public MyEnumerator(MyCollection coll) + { + collection = coll; + nIndex = -1; + } + + public bool MoveNext() + { + nIndex++; + return(nIndex < collection.items.GetLength(0)); + } + + public int Current + { + get + { + return(collection.items[nIndex]); + } + } + } + + public static void Main() + { + MyCollection col = new MyCollection(); + Console.WriteLine("Values in the collection are:"); + foreach (int i in col) // CS1579 + { + Console.WriteLine(i); + } + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1591.md b/docs/csharp/language-reference/compiler-messages/cs1591.md new file mode 100644 index 0000000000000..a5b847dccc551 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1591.md @@ -0,0 +1,57 @@ +--- +title: "Compiler Warning (level 4) CS1591 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1591" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1591" +ms.assetid: 53c8599e-3e83-4d17-998b-05c934704283 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 4) CS1591 +Missing XML comment for publicly visible type or member 'Type_or_Member' + + The [/doc](../../../csharp/language-reference/compiler-options/doc-compiler-option.md) compiler option was specified, but one or more constructs did not have comments. + + The following sample generates CS1591: + +``` +// CS1591.cs +// compile with: /W:4 /doc:x.xml + +/// text +public class Test +{ + // /// text + public static void Main() // CS1591, remove "//" from previous line + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1598.md b/docs/csharp/language-reference/compiler-messages/cs1598.md new file mode 100644 index 0000000000000..1cfeae30b39dc --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1598.md @@ -0,0 +1,41 @@ +--- +title: "Compiler Warning (level 1) CS1598 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1598" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1598" +ms.assetid: de8d473e-0c18-4236-af24-a832b47fbfb1 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1598 +XML parser could not be loaded for the following reason: 'reason'. The XML documentation file 'file' will not be generated. + + The [/doc](../../../csharp/language-reference/compiler-options/doc-compiler-option.md) option was specified, but the compiler could not find and load msxml3.dll. Make sure that the file msxml3.dll is installed and registered. \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1607.md b/docs/csharp/language-reference/compiler-messages/cs1607.md new file mode 100644 index 0000000000000..a4796db12630c --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1607.md @@ -0,0 +1,49 @@ +--- +title: "Compiler Warning (level 1) CS1607 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1607" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1607" +ms.assetid: 7ad8e1a4-40c2-41cc-b4ee-cc4d7beb4372 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1607 +Assembly generation -- reason + + A warning was generated from the assembly-creation phase of the compilation. + + If you are building a 64-bit application on a 32-bit operating system, you must ensure that 64-bit versions of all referenced assemblies are installed on the target operating system. + + All x86-specific common language runtime (CLR) assemblies have 64-bit counterparts (every CLR assembly will exist on all operating systems). Therefore, you can safely ignore CS1607 for CLR assemblies. + + You can ignore this warning if you encounter it when you create a . The informational version is a string that attaches additional version information to an assembly; this information is not used at run time. Although you can specify any text, a warning message appears on compilation if the string is not in the format that is used by the assembly version number, or if it is in that format but contains wildcard characters. This warning is harmless. + + For more information, see [Al.exe Tool Errors and Warnings](http://msdn.microsoft.com/en-us/7f125d49-0a03-47a6-9ba9-d61a679a7d4b). \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1610.md b/docs/csharp/language-reference/compiler-messages/cs1610.md new file mode 100644 index 0000000000000..b1be3450e3cd2 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1610.md @@ -0,0 +1,45 @@ +--- +title: "Compiler Warning (level 4) CS1610 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1610" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1610" +ms.assetid: dc78dbcc-d5a0-4776-953c-1fe72b6fd5ea +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 4) CS1610 +Unable to delete temporary file 'file' used for default Win32 resource -- resource + + When using the [/win32res](../../../csharp/language-reference/compiler-options/win32res-compiler-option.md) compiler option and when your **%TEMP%** directory does not have DELETE permission, this warning indicates that the compiler could not delete a temporary file that it created. + + Make sure that you have read/write/delete permissions for the **%TEMP%** directory. + + If necessary, you can manually delete these files and there will be no harm to C# or any of your programs. \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1612.md b/docs/csharp/language-reference/compiler-messages/cs1612.md new file mode 100644 index 0000000000000..912470543ad89 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1612.md @@ -0,0 +1,112 @@ +--- +title: "Compiler Error CS1612 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1612" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1612" +ms.assetid: ef5db985-030a-4f15-b53f-e92c9297c6a3 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1612 +Cannot modify the return value of 'expression' because it is not a variable + + An attempt was made to modify a value type that is produced as the result of an intermediate expression but is not stored in a variable. This error can occur when you attempt to directly modify a struct in a generic collection, as shown in the following example: + +```cs +List list = {…}; +list[0].Name = "MyStruct42"; //CS1612 +``` + + To modify the struct, first assign it to a local variable, modify the variable, then assign the variable back to the item in the collection. + +```cs +List list = {…}; +MyStruct ms = list[0]; +ms.Name = "MyStruct42"; +list[0] = ms; +``` + + This error occurs because value types are copied on assignment. When you retrieve a value type from a property or indexer, you are getting a copy of the object, not a reference to the object itself. The copy that is returned is not stored by the property or indexer because they are actually methods, not storage locations (variables). You must store the copy into a variable that you declare before you can modify it. + + The error does not occur with reference types because a property or indexer in that case returns a reference to an existing object, which is a storage location. + + If you are defining the class or struct, you can resolve this error by modifying your property declaration to provide access to the members of a struct. If you are writing client code, you can resolve the error by creating your own instance of the struct, modifying its fields, and then assigning the entire struct back to the property. As a third alternative, you can change your struct to a class. + +## Example + CS1612 also occurs when you attempt to access the member of a struct through a property on an enclosing class that is returning the entire struct, as shown in the following example: + +```cs +// CS1612.cs +using System; + +public struct MyStruct +{ + public int Width; +} + +public class ListView +{ + MyStruct ms; + public MyStruct Size + { + get { return ms; } + set { ms = value; } + } +} + +public class MyClass +{ + public MyClass() + { + ListView lvi; + lvi = new ListView(); + lvi.Size.Width = 5; // CS1612 + + // You can use the following lines instead. + // MyStruct ms; + // ms.Width = 5; + // lvi.Size = ms; // CS1612 + } + + public static void Main() + { + MyClass mc = new MyClass(); + // Keep the console open in debug mode. + Console.WriteLine("Press any key to exit."); + Console.ReadKey(); + } +} +``` + +## See Also + [Structs](../../../csharp/programming-guide/classes-and-structs/structs.md) + [Value Types](../../../csharp/language-reference/keywords/value-types.md) + [Reference Types](../../../csharp/language-reference/keywords/reference-types.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1614.md b/docs/csharp/language-reference/compiler-messages/cs1614.md new file mode 100644 index 0000000000000..a0faf4c59a4ff --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1614.md @@ -0,0 +1,84 @@ +--- +title: "Compiler Error CS1614 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1614" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1614" +ms.assetid: 787eef18-74a6-49d9-9f34-f0881aca8dff +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1614 +'name' is ambiguous; between 'attribute1' and 'attribute2'. use either '@attribute' or 'attributeAttribute' + + The compiler has encountered an ambiguous attribute specification. + + For convenience, the C# compiler allows you to specify **ExampleAttribute** as just `[Example]`. However, ambiguity arises if an attribute class named `Example` exists along with **ExampleAttribute**, because the compiler cannot tell if `[Example]` refers to the `Example` attribute or the **ExampleAttribute** attribute. To clarify, use `[@Example]` for the `Example` attribute and `[ExampleAttribute]` for **ExampleAttribute**. + + The following sample generates CS1614: + +``` +// CS1614.cs +using System; + +// Both of the following classes are valid attributes with valid +// names (MySpecial and MySpecialAttribute). However, because the lookup +// rules for attributes involves auto-appending the 'Attribute' suffix +// to the identifier, these two attributes become ambiguous; that is, +// if you specify MySpecial, the compiler can't tell if you want +// MySpecial or MySpecialAttribute. + +public class MySpecial : Attribute { + public MySpecial() {} +} + +public class MySpecialAttribute : Attribute { + public MySpecialAttribute() {} +} + +class MakeAWarning { + [MySpecial()] // CS1614 + // Ambiguous: MySpecial or MySpecialAttribute? + public static void Main() { + } + + [@MySpecial()] // This isn't ambiguous, it binds to the first attribute above. + public static void NoWarning() { + } + + [MySpecialAttribute()] // This isn't ambiguous, it binds to the second attribute above. + public static void NoWarning2() { + } + + [@MySpecialAttribute()] // This is also legal. + public static void NoWarning3() { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1616.md b/docs/csharp/language-reference/compiler-messages/cs1616.md new file mode 100644 index 0000000000000..404c68e5fc1cf --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1616.md @@ -0,0 +1,65 @@ +--- +title: "Compiler Warning (level 1) CS1616 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1616" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1616" +ms.assetid: 7fb99eba-8da3-4c1b-81a3-bc4a57822e45 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1616 +Option 'option' overrides attribute 'attribute' given in a source file or added module + + This warning occurs if the assembly attributes or found in source conflict with the [/keyfile](../../../csharp/language-reference/compiler-options/keyfile-compiler-option.md) or [/keycontainer](../../../csharp/language-reference/compiler-options/keycontainer-compiler-option.md) command line option or key file name or key container specified in the Project Properties. + + For the example below, assume you have a key file named `cs1616.snk`. This file could be generated with the command line: + +``` +sn –k CS1616.snk +``` + + The following sample generates CS1616: + +``` +// CS1616.cs +// compile with: /keyfile:cs1616.snk +using System.Reflection; + +// To fix the error, remove the next line +[assembly: AssemblyKeyFile("cs1616b.snk")] // CS1616 + +class C +{ + public static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1640.md b/docs/csharp/language-reference/compiler-messages/cs1640.md new file mode 100644 index 0000000000000..4fc12ad4e8281 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1640.md @@ -0,0 +1,82 @@ +--- +title: "Compiler Error CS1640 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1640" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1640" +ms.assetid: 1393668e-05e9-4dc2-9203-3d9c2933406f +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1640 +foreach statement cannot operate on variables of type 'type' because it implements multiple instantiations of 'interface', try casting to a specific interface instantiation + + The type inherits from two or more instances of IEnumerator\, which means there is not a unique enumeration of the type that `foreach` could use. Specify the type of IEnumerator\ or use another looping construct. + +## Example + The following sample generates CS1640: + +``` +// CS1640.cs + +using System; +using System.Collections; +using System.Collections.Generic; + +public class C : IEnumerable, IEnumerable, IEnumerable +{ + IEnumerator IEnumerable.GetEnumerator() + { + yield break; + } + + IEnumerator IEnumerable.GetEnumerator() + { + yield break; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return (IEnumerator)((IEnumerable)this).GetEnumerator(); + } +} + +public class Test +{ + public static int Main() + { + foreach (int i in new C()){} // CS1640 + + // Try specifing the type of IEnumerable + // foreach (int i in (IEnumerable)new C()){} + return 1; + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1644.md b/docs/csharp/language-reference/compiler-messages/cs1644.md new file mode 100644 index 0000000000000..5ed149f14fad3 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1644.md @@ -0,0 +1,49 @@ +--- +title: "Compiler Error CS1644 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1644" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1644" +ms.assetid: f51e2064-29e1-4a22-bbe3-577fa52df6bc +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1644 +Feature 'feature' is not part of the standardized ISO C# language specification, and may not be accepted by other compilers + + This error occurs if you specified the [/langversion](../../../csharp/language-reference/compiler-options/langversion-compiler-option.md) option ISO-1 and the code you are compiling uses features that are not part of the ISO 1.0 standard. To resolve this error, do not use any of the C# 2.0 compiler features such as generics or anonymous methods with the ISO-1 compatibility option. + + The following sample generates CS1644: + +``` +// CS1644.cs +// compile with: /langversion:ISO-1 /target:library +class C {} // CS1644 +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1656.md b/docs/csharp/language-reference/compiler-messages/cs1656.md new file mode 100644 index 0000000000000..94f8e330ab30b --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1656.md @@ -0,0 +1,141 @@ +--- +title: "Compiler Error CS1656 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1656" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1656" +ms.assetid: b5463a12-d685-4dae-9f88-08383e271b7a +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1656 +Cannot assign to 'variable' because it is a 'read-only variable type' + + This error occurs when an assignment to variable occurs in a read-only context. Read-only contexts include [foreach](../../../csharp/language-reference/keywords/foreach-in.md) iteration variables, [using](../../../csharp/language-reference/keywords/using-statement.md) variables, and [fixed](../../../csharp/language-reference/keywords/fixed-statement.md) variables. To resolve this error, avoid assignments to a statement variable in `using` blocks, `foreach` statements, and `fixed` statements. + +## Example + The following example generates error CS1656 because it tries to replace complete elements of a collection inside a `foreach` loop. One way to work around the error is to change the `foreach` loop to a [for](../../../csharp/language-reference/keywords/for.md) loop. Another way, not shown here, is to modify the members of the existing element; this is possible with classes, but not with structs. + +``` +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace CS1656_2 +{ + + class Book + { + public string Title; + public string Author; + public double Price; + public Book(string t, string a, double p) + { + Title=t; + Author=a; + Price=p; + + } + } + + class Program + { + private List list; + static void Main(string[] args) + { + Program prog = new Program(); + prog.list = new List(); + prog.list.Add(new Book ("The C# Programming Language", + "Hejlsberg, Wiltamuth, Golde", + 29.95)); + prog.list.Add(new Book ("The C++ Programming Language", + "Stroustrup", + 29.95)); + prog.list.Add(new Book ("The C Programming Language", + "Kernighan, Ritchie", + 29.95)); + foreach(Book b in prog.list) + { + // Cannot modify an entire element in a foreach loop + // even with reference types. + // Use a for or while loop instead + if (b.Title == "The C Programming Language") + // Cannot assign to 'b' because it is a 'foreach + // iteration variable' + b = new Book("Programming Windows, 5th Ed.", "Petzold", 29.95); //CS1656 + } + + //With a for loop you can modify elements + //for(int x = 0; x < prog.list.Count; x++) + //{ + // if(prog.list[x].Title== "The C Programming Language") + // prog.list[x] = new Book("Programming Windows, 5th Ed.", "Petzold", 29.95); + //} + //foreach(Book b in prog.list) + // Console.WriteLine(b.Title); + + } + } +} +``` + +## Example + The following sample demonstrates how CS1656 can be generated in other contexts besides a `foreach` loop: + +``` +// CS1656.cs +// compile with: /unsafe +using System; + +class C : IDisposable +{ + public void Dispose() { } +} + +class CMain +{ + unsafe public static void Main() + { + using (C c = new C()) + { + // Cannot assign to 'c' because it is a 'using variable' + c = new C(); // CS1656 + } + + int[] ary = new int[] { 1, 2, 3, 4 }; + fixed (int* p = ary) + { + // Cannot assign to 'p' because it is a 'fixed variable' + p = null; // CS1656 + } + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1658.md b/docs/csharp/language-reference/compiler-messages/cs1658.md new file mode 100644 index 0000000000000..919035f1060e2 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1658.md @@ -0,0 +1,69 @@ +--- +title: "Compiler Warning (level 1) CS1658 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1658" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1658" +ms.assetid: e67b033d-4c88-4552-b3cd-dfc34546502b +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1658 +'warning text'. See also error 'error code' + + The compiler emits this warning when it overrides an error with a warning. For information about the problem, refer to the error mentioned. To find the appropriate error from within the Visual Studio IDE, use the index. For example, if the text above reads "See also error 'CS1037'," look for CS1037 in the index. + +## Example + The following example generates CS1658. + +``` +// CS1658.cs +// compile with: /doc:x.xml +// CS1584 expected +/// +/// +public class C +{ + /// // CS1658 + public static void M() + { + } + + /// + /// + public void F(params object[] o) + { + } + + static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1674.md b/docs/csharp/language-reference/compiler-messages/cs1674.md new file mode 100644 index 0000000000000..c2da041543138 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1674.md @@ -0,0 +1,100 @@ +--- +title: "Compiler Error CS1674 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1674" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1674" +ms.assetid: 7a018629-35f4-406a-8a5f-1cee7343da6d +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1674 +'T': type used in a using statement must be implicitly convertible to 'System.IDisposable' + + The [using Statement](../../../csharp/language-reference/keywords/using-statement.md) is intended to be used to ensure the disposal of an object at the end of the `using` block, thus, only types which are disposable may be used in such a statement. For example, value types are not disposable, and type parameters which are not constrained to be classes may not be assumed to be disposable. + +## Example + The following sample generates CS1674. + +``` +// CS1674.cs +class C +{ + public static void Main() + { + int a = 0; + a++; + + using (a) {} // CS1674 + } +} +``` + +## Example + The following sample generates CS1674. + +``` +// CS1674_b.cs +using System; +class C { + public void Test() { + using (C c = new C()) {} // CS1674 + } +} + +// OK +class D : IDisposable { + void IDisposable.Dispose() {} + public void Dispose() {} + + public static void Main() { + using (D d = new D()) {} + } +} +``` + +## Example + The following case illustrates the need for a class type constraint to guarantee that an unknown type parameter is disposable. The following sample generates CS1674. + +``` +// CS1674_c.cs +// compile with: /target:library +using System; +public class C +// Add a class type constraint that specifies a disposable class. +// Uncomment the following line to resolve. +// public class C where T : IDisposable +{ + public void F(T t) + { + using (t) {} // CS1674 + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1683.md b/docs/csharp/language-reference/compiler-messages/cs1683.md new file mode 100644 index 0000000000000..781d0436297f7 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1683.md @@ -0,0 +1,41 @@ +--- +title: "Compiler Warning (level 1) CS1683 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1683" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1683" +ms.assetid: b3bd2729-a9e3-4b00-9937-d8d859fe87ef +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1683 +Reference to type 'Type Name' claims it is defined in this assembly, but it is not defined in source or any added modules + + This error can occur when you are importing an assembly that contains a reference back to the assembly you are currently compiling, but the assembly being compiled contains nothing matching the reference. One way to get to this situation is to compile your assembly, which initially does contain the member that the assembly being imported is referencing. Then you update your assembly, mistakenly removing the members that the imported assembly is referencing. \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1685.md b/docs/csharp/language-reference/compiler-messages/cs1685.md new file mode 100644 index 0000000000000..e23ac68f20536 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1685.md @@ -0,0 +1,43 @@ +--- +title: "Compiler Warning (level 1) CS1685 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1685" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1685" +ms.assetid: b115dd93-a749-4549-83d3-9cdc92a8ef31 +caps.latest.revision: 10 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1685 +The predefined type 'System.type name' is defined in multiple assemblies in the global alias; using definition from 'File Name' + + This error occurs when a predefined system type such as System.int32 is found in two assemblies. One way this can happen is if you are referencing mscorlib from two different places, such as trying to run the.Net Framework versions 1.0 and 1.1 side-by-side. + + The compiler will use the definition from only one of the assemblies. The compiler searches only global aliases, does not search libraries defined **/reference**. If you have specified **/nostdlib**, the compiler will search for , and in the future start all searches for predefined types in the file where it found . \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1690.md b/docs/csharp/language-reference/compiler-messages/cs1690.md new file mode 100644 index 0000000000000..11c87a2fbb311 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1690.md @@ -0,0 +1,64 @@ +--- +title: "Compiler Warning (level 1) CS1690 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1690" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1690" +ms.assetid: bc76efe0-4304-4449-8c11-950667aa8ac9 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1690 +Accessing a member on 'member' may cause a runtime exception because it is a field of a marshal-by-reference class + + This warning occurs when you try to call a method, property, or indexer on a member of a class that derives from , and the member is a value type. Objects that inherit from `MarshalByRefObject` are typically intended to be marshaled by reference across an application domain. If any code ever attempts to directly access the value-type member of such an object across an application domain, a runtime exception will occur. To resolve the warning, first copy the member into a local variable and call the method on that variable. + + The following sample generates CS1690: + +``` +// CS1690.cs +using System; + +class WarningCS1690: MarshalByRefObject +{ + int i = 5; + + public static void Main() + { + WarningCS1690 e = new WarningCS1690(); + e.i.ToString(); // CS1690 + + // OK + int i = e.i; + i.ToString(); + e.i = i; + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1691.md b/docs/csharp/language-reference/compiler-messages/cs1691.md new file mode 100644 index 0000000000000..61babff13c904 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1691.md @@ -0,0 +1,63 @@ +--- +title: "Compiler Warning (level 1) CS1691 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1691" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1691" +ms.assetid: 7f0fea4d-4215-446c-a249-57daa7e967d2 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1691 +'number' is not a valid warning number + + A number that was passed to the [#pragma warning](../../../csharp/language-reference/preprocessor-directives/preprocessor-pragma-warning.md) preprocessor directive was not a valid warning number. Verify that the number represents a warning, not an error or another sequence of characters. + +## Example + The following example generates CS1691. + +``` +// CS1691.cs +public class C +{ + int i = 1; + public static void Main() + { + C myC = new C(); +#pragma warning disable 151 // CS1691 +// Try the following line instead: +// #pragma warning disable 1645 + myC.i++; +#pragma warning restore 151 // CS1691 +// Try the following line instead: +// #pragma warning restore 1645 + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1699.md b/docs/csharp/language-reference/compiler-messages/cs1699.md new file mode 100644 index 0000000000000..d8e5388199754 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1699.md @@ -0,0 +1,75 @@ +--- +title: "Compiler Warning (level 1) CS1699 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1699" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1699" +ms.assetid: acf4b57d-8534-4417-9324-65415b5676ae +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1699 +Use command line option "compiler_option" or appropriate project settings instead of "attribute_name" + + In order to sign an assembly, it is necessary to specify a key file. Prior to [!INCLUDE[csprcsext](../../../csharp/language-reference/compiler-messages/includes/csprcsext_md.md)], you specified the key file using CLR attributes in source code. These attributes are now deprecated. + + Beginning in [!INCLUDE[csprcsext](../../../csharp/language-reference/compiler-messages/includes/csprcsext_md.md)], you should use the **Signing Page** of the **Project Designer** or the Assembly Linker to specify the key file. + + The **Signing Page** of the **Project Designer** is the preferred method; for more information, see [Signing Page, Project Designer](/visualstudio/ide/reference/signing-page-project-designer) and [Managing Assembly and Manifest Signing](/visualstudio/ide/managing-assembly-and-manifest-signing). + + The [How to: Sign an Assembly with a Strong Name](http://msdn.microsoft.com/library/2c30799a-a826-46b4-a25d-c584027a6c67) uses the following compiler options: + +- [/keyfile (C# Compiler Options)](../../../csharp/language-reference/compiler-options/keyfile-compiler-option.md) instead of the attribute. + +- [/keycontainer (C# Compiler Options)](../../../csharp/language-reference/compiler-options/keycontainer-compiler-option.md) instead of. + +- [/delaysign (C# Compiler Options)](../../../csharp/language-reference/compiler-options/delaysign-compiler-option.md) instead of . + + These attributes have been deprecated for the following reasons: + +- There were security issues due to the attributes being embedded in the binary files produced by the compiler. Everyone who had your binary also had the keys stored in it. + +- There were usability issues due to the fact that the path specified in the attributes was relative to the current working directory, which could change in the integrated development environment (IDE), or to the output directory. Thus, most times the key file is likely to be ..\\\\..\\\mykey.snk. Attributes also make it more difficult for the project system to properly sign satellite assemblies. When you use the compiler options instead of these attributes, you can use a fully qualified path and file name for the key without anything being embedded in the output file; the project system and source code control system can properly manipulate that full path when projects are moved around; the project system can maintain a project-relative path to the key file, and still pass a full path to the compiler; other build programs can more easily sign outputs by passing the proper path directly to the compiler instead of generating a source file with the correct attributes. + +- Using attributes with friend assemblies can hamper compiler efficiency. When you use attributes, the compiler does not know what the key is when it has to decide whether or not to grant friendship and so it has to guess. At the end of compilation, the compiler is able to verify the guess once it finally knows the key. When the key file is specified with a compiler option, the compiler can immediately decide whether to grant friendship. + +## Example + The following sample generates CS1699. To resolve the error, remove the attribute and compile with **/delaysign**. + +``` +// CS1699.cs +// compile with: /target:library +[assembly:System.Reflection.AssemblyDelaySign(true)] // CS1699 +``` + +## See Also + [Signing Page, Project Designer](/visualstudio/ide/reference/signing-page-project-designer) + [Managing Assembly and Manifest Signing](/visualstudio/ide/managing-assembly-and-manifest-signing) + [How to: Sign an Assembly with a Strong Name](http://msdn.microsoft.com/library/2c30799a-a826-46b4-a25d-c584027a6c67) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1700.md b/docs/csharp/language-reference/compiler-messages/cs1700.md new file mode 100644 index 0000000000000..78e545978b90e --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1700.md @@ -0,0 +1,54 @@ +--- +title: "Compiler Warning (level 3) CS1700 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1700" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1700" +ms.assetid: fcd38d68-e34b-4f87-8290-444e66886597 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 3) CS1700 +Assembly reference Assembly Name is invalid and cannot be resolved + + This warning indicates that an attribute, such as , was not specified correctly. + + For more information, see [Friend Assemblies](http://msdn.microsoft.com/library/df0c70ea-2c2a-4bdc-9526-df951ad2d055). + +## Example + The following sample generates CS1700. + +``` +// CS1700.cs +// compile with: /target:library +using System.Runtime.CompilerServices; +[assembly:InternalsVisibleTo("app2, Retargetable=f")] // CS1700 +[assembly:InternalsVisibleTo("app2")] // OK +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1701.md b/docs/csharp/language-reference/compiler-messages/cs1701.md new file mode 100644 index 0000000000000..7bc82a5f22286 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1701.md @@ -0,0 +1,110 @@ +--- +title: "Compiler Warning (level 2) CS1701 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1701" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1701" +ms.assetid: adbaf99e-c283-49a7-b940-4c9b84ebcb03 +caps.latest.revision: 15 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 2) CS1701 +Assuming assembly reference "Assembly Name #1" matches "Assembly Name #2", you may need to supply runtime policy + + The two assemblies differ in release and/or version number. For unification to occur, you must specify directives in the application's .config file, and you must provide the correct strong name of an assembly, as demonstrated in the following example code. + +## Example + The following multifile sample references an assembly using two different external aliases. This first sample builds the older version of the code that creates assembly CS1701_d. + +``` +// CS1701_a.cs +// compile with: /target:library /out:cs1701_d.dll /keyfile:mykey.snk +using System.Reflection; +[assembly:AssemblyVersion("1.0")] +public class A { + public void M1() {} +} + +public class C1 {} +``` + +## Example + This is the code that creates the newer version of assembly CS1701_d. Note that it compiles into a different directory than the older version, necessary since the output files have the same names. + +``` +// CS1701_b.cs +// compile with: /target:library /out:c:\\cs1701_d.dll /keyfile:mykey.snk +using System.Reflection; +[assembly:AssemblyVersion("2.0")] +public class A { + public void M2() {} + public void M1() {} +} + +public class C2 {} +public class C1 {} +``` + +## Example + This sample sets up the external aliases A1 and A2. + +``` +// CS1701_c.cs +// compile with: /target:library /reference:A2=c:\\cs1701_d.dll /reference:A1=cs1701_d.dll + +extern alias A1; +extern alias A2; +// using System; +using a1 = A1::A; +using a2 = A2::A; + +public class Ref { + public static a1 A1() { return new a1(); } + public static a2 A2() { return new a2(); } + + public static A1::C1 M1() { return new A1::C1(); } + public static A2::C2 M2() { return new A2::C2(); } +} +``` + +## Example + This sample calls methods using two different aliases of A. The following sample generates C1701. + +``` +// CS1701_d.cs +// compile with: /reference:c:\\CS1701_d.dll /reference:CS1701_c.dll +// CS1701 expected +class Tester { + public static void Main() { + Ref.A1().M1(); + Ref.A2().M2(); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1703.md b/docs/csharp/language-reference/compiler-messages/cs1703.md new file mode 100644 index 0000000000000..bd700c0ed8ed8 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1703.md @@ -0,0 +1,73 @@ +--- +title: "Compiler Error CS1703 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1703" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1703" +ms.assetid: b17738e9-ed35-46b0-88b8-763ce24211d1 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1703 +An assembly with the same simple name 'name' has already been imported. Try removing one of the references or sign them to enable side-by-side. + + The compiler removes references that have the same path and file name, but it is possible that the same file exists in two places, or that you forgot to change the version number. This error points out that two references have the same assembly identity and thus the compiler has no way of distinguishing between them in metadata. Either remove one of the redundant references, or make the references unique somehow, such as by incrementing the assembly version number. + + The following code generates error CS1703. + +## Example + This code creates assembly A in the .\bin1 directory. + + Save this example in a file named CS1703a1.cs, and compile it with the following flags: `/t:library /out:.\bin1\cs1703.dll /keyfile:key.snk` + +``` +using System; +public class A { } +``` + +## Example + This code creates a copy of assembly A in the .\bin2 directory. + + Save this example in a file named CS1703a2.cs, and compile it with the following flags: `/t:library /out:.\bin2\cs1703.dll /keyfile:key.snk` + +``` +using System; +public class A { } +``` + +## Example + This code references the assembly A in the two prior modules. + + Save this example in a file named CS1703ref.cs, and compile it with the following flags: `/t:library /r:A2=.\bin2\cs1703.dll /r:A1=.\bin1\cs1703.dll` + +``` +extern alias A1; +extern alias A2; +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1704.md b/docs/csharp/language-reference/compiler-messages/cs1704.md new file mode 100644 index 0000000000000..92e1082fe6280 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1704.md @@ -0,0 +1,70 @@ +--- +title: "Compiler Error CS1704 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1704" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1704" +ms.assetid: da5e89d5-bbb7-47e9-92f6-b03b1602dee4 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1704 +An assembly with the same simple name 'Assembly Name' has already been imported. Try removing one of the references or sign them to enable side-by-side. + + This error points out that two references have the same assembly identity because the assemblies in question lack strong names, they were not signed, and thus the compiler has no way of distinguishing between them in metadata. Thus, the run time ignores the version and culture assembly name properties. The user should remove the redundant reference, rename one of the references, or provide a strong name for them. + +## Example + This sample creates an assembly and saves it to the root directory. + +``` +// CS1704_a.cs +// compile with: /target:library /out:c:\\cs1704.dll +public class A {} +``` + +## Example + This sample creates an assembly with the same name as the previous sample, but saves it to a different location. + +``` +// CS1704_b.cs +// compile with: /target:library /out:cs1704.dll +public class A {} +``` + +## Example + This sample attempts to reference both assemblies. The following sample generates CS1704. + +``` +// CS1704_c.cs +// compile with: /target:library /r:A2=cs1704.dll /r:A1=c:\\cs1704.dll +// CS1704 expected +extern alias A1; +extern alias A2; +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1705.md b/docs/csharp/language-reference/compiler-messages/cs1705.md new file mode 100644 index 0000000000000..a6755d861f873 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1705.md @@ -0,0 +1,174 @@ +--- +title: "Compiler Error CS1705 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1705" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1705" +ms.assetid: 3612a542-0256-4fed-b020-41691ef5a052 +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1705 +Assembly 'AssemblyName1' uses 'TypeName' which has a higher version than referenced assembly 'AssemblyName2' + + You are accessing a type that has a higher version number than the version number in a referenced assembly. Typically, this error is caused by the accidental use of two versions of the same assembly. + + For example, suppose that you have two assemblies, Asmb1 and Asmb2. Assembly Asmb1 references version 1.0 of assembly Asmb2. Assembly Asmb1 also uses a class `MyClass` that was added to assembly Asmb2 in version 2.0. The compiler has unification rules for binding references, and a reference to `MyClass` in version 2.0 cannot be satisfied by version 1.0. + +## Example + The following more detailed example consists of four code modules: + +- Two DLLs that are identical except for a version attribute. + +- A third DLL that references the first two. + +- A client that references only version 1.0 of the identical DLLs, but accesses a class from version 2.0. + + The following code creates the first of the identical DLLs. For information about how to generate a key file, see [/keyfile (C# Compiler Options)](../../../csharp/language-reference/compiler-options/keyfile-compiler-option.md). + +```cs +// CS1705a.cs + +// Compile by using the following command: +// csc /target:library /out:C:\\CS1705.dll /keyfile:mykey.snk CS1705a.cs + +// The DLL is created in the C:\ directory. + +// The AssemblyVersion attribute specifies version 1.0 for this DLL. + +[assembly:System.Reflection.AssemblyVersion("1.0")] +public class Class1 +{ + public void Method1() {} +} +``` + +## Example + The following code defines version 2.0 of the assembly, as specified by the attribute. + +```cs +// CS1705b.cs + +// Compile by using the following command: +// csc /target:library /out:CS1705.dll /keyfile:mykey.snk CS1705b.cs + +// The DLL is created in the current directory. + +// The AssemblyVersion attribute specifies version 2.0 for this DLL. + +[assembly:System.Reflection.AssemblyVersion("2.0")] +public class Class1 +{ + public void Method1() { } +} + +``` + +## Example + The following code references the two DLL versions that are defined in the preceding code. `AssemblyA` refers to the DLL created by CS1705a.cs (version 1.0). `AssemblyB` refers to the DLL created by CS1705b.cs (version 2.0). In `ClassC`, two methods are defined. The first, `Return1A`, returns an object of type `Class1A`, which is an alias for `Class1` from version 1.0 of the DLL. The second, `Return1B`, returns an object of type `Class1B`, which is an alias for `Class1` from version 2.0 of the DLL. The definition of `Return1A` creates a dependency on version 1.0; the definition of `Return1B` creates a dependency on version 2.0. + +```cs +// CS1705c.cs + +// Compile by using the following command. AssemblyA refers to the DLL created by +// CS1705a.cs (version 1.0). AssemblyB refers to the DLL created by CS1705b.cs +// (version 2.0). +// csc /target:library /r:AssemblyA=C:\\CS1705.dll /r:AssemblyB=CS1705.dll CS1705c.cs + +extern alias AssemblyA; +extern alias AssemblyB; + +// Class1A is an alias for type Class1 from VS1705a.cs, which is in version 1.0 +// of the assembly. Class1B is an alias for type Class1 from CS1705b.cs, which +// is in version 2.0 of the assembly. + +using Class1A = AssemblyA::Class1; +using Class1B = AssemblyB::Class1; + +// Method Return1A in ClassC returns an object of type Class1A, which is +// Class1 from version 1.0 of the DLL. Method Return1B returns an object +// of type Class1B, which is Class1 from version 2.0 of the DLL. + +public class ClassC +{ + // The following line creates a dependency on version 1.0 of CS1705.dll. + // This is not the source of the problem when ClassC is accessed from + // CS1705d.cs because CS1705d.cs references version 1.0 of the DLL. + // Therefore, type Class1A and the assembly have the same version. + public static Class1A Return1A() { return new Class1A(); } + + // The following line creates a dependency on version 2.0 of CS1705.dll. + // This causes compiler error CS1705 when ClassC is accessed from + // CS1705d.cs, because CS1705d.cs does not reference version 2.0 of the + // DLL. Class1B is the alias for Class1 in version 2.0, and CS1705d.cs + // references version 1.0. + public static Class1B Return1B() { return new Class1B(); } +} + +``` + +## Example + The following code generates compiler error CS1705. It references the DLL created by CS1705a.cs (version 1.0). However, in the `Main` method, the code accesses `ClassC` from CS1705c.cs. `ClassC` uses a type that is defined in CS1705b.cs (version 2.0). This causes compiler error CS1705 because the type has a version number for CS1705.dll that is higher than the referenced version of CS1705.dll. + +```cs +// CS1705d.cs + +// Compile by using the following command: +// csc /reference:C:\\CS1705.dll /reference:CS1705c.dll CS1705d.cs + +// C:\\CS1705.dll is version 1.0 of the assembly. + +class Tester +{ + static void Main() + { + // Return1A returns a type defined in version 1.0. + ClassC.Return1A().Method1(); + // Return1B returns a type defined in version 2.0. + ClassC.Return1B().Method1(); + } +} + +``` + + You can resolve the error in one of the following ways: + +- Update the code so that all files use the same version of the DLL. + +- Add a reference to version 2.0 of the DLL to CS1705d.cs by using the following command to compile: + + `csc /reference:C:\\CS1705.dll /reference:CS1705.dll /reference:CS1705c.dll CS1705d.cs` + + Although the program compiles when you use this command, it still does not run. To enable the program to run, you can provide an application configuration file that includes a [\ element](http://msdn.microsoft.com/library/14e95627-dd79-4b82-ac85-e682aa3a31d8) that uses [\](http://msdn.microsoft.com/library/cea4d187-6398-4da4-af09-c1abc6a349c1) and [\](http://msdn.microsoft.com/library/d48a3983-2297-43ff-a14d-1f29d3995822) child elements to specify the location of version 1.0 of the DLL. For more information about configuration files, see [Configuring Apps](http://msdn.microsoft.com/library/86bd26d3-737e-4484-9782-19b17f34cd1f). + +## See Also + [extern alias](../../../csharp/language-reference/keywords/extern-alias.md) + [:: Operator](../../../csharp/language-reference/operators/namespace-alias-qualifer.md) + [Command-line Building With csc.exe](../../../csharp/language-reference/compiler-options/command-line-building-with-csc-exe.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1708.md b/docs/csharp/language-reference/compiler-messages/cs1708.md new file mode 100644 index 0000000000000..a238b872afa12 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1708.md @@ -0,0 +1,85 @@ +--- +title: "Compiler Error CS1708 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1708" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1708" +ms.assetid: df2fc580-2de5-4dd0-9ba3-b41248de5f41 +caps.latest.revision: 14 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Error CS1708 +Fixed size buffers can only be accessed through locals or fields + + A new feature in C# 2.0 is the ability to define an in-line array inside of a `struct`. Such arrays can only be accessed via local variables or fields, and may not be referenced as intermediate values on the left-hand side of an expression. Also, the arrays cannot be accessed by fields that are `static` or `readonly`. + + To resolve this error, define an array variable, and assign the in-line array to the variable. Or, remove the `static` or `readonly` modifier from the field representing the in-line array. + +## Example + The following sample generates CS1708. + +```cs +// CS1708.cs +// compile with: /unsafe +using System; + +unsafe public struct S +{ + public fixed char name[10]; +} + +public unsafe class C +{ + public S UnsafeMethod() + { + S myS = new S(); + return myS; + } + + static void Main() + { + C myC = new C(); + myC.UnsafeMethod().name[3] = 'a'; // CS1708 + // Uncomment the following 2 lines to resolve: + // S myS = myC.UnsafeMethod(); + // myS.name[3] = 'a'; + + // The field cannot be static. + C._s1.name[3] = 'a'; // CS1708 + + // The field cannot be readonly. + myC._s2.name[3] = 'a'; // CS1708 + } + + static readonly S _s1; + public readonly S _s2; +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1716.md b/docs/csharp/language-reference/compiler-messages/cs1716.md new file mode 100644 index 0000000000000..fe65e45063133 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1716.md @@ -0,0 +1,74 @@ +--- +title: "Compiler Error CS1716 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1716" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1716" +ms.assetid: c9e65274-0cc3-41a6-967c-ac1804ecf3ba +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1716 +Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead. + + This error arises in an unsafe code section that contains a fixed-size array declaration similar to a field declaration. Do not use this attribute. Instead, use the keyword `fixed`. + +## Example + The following example generates CS1716. + +``` +// CS1716.cs +// compile with: /unsafe +using System; +using System.Runtime.CompilerServices; + +public struct UnsafeStruct +{ + [FixedBuffer(typeof(int), 4)] // CS1716 + unsafe public int aField; + // Use this single line instead of the above two lines. + // unsafe public fixed int aField[4]; +} + +public class TestUnsafe +{ + static int Main() + { + UnsafeStruct us = new UnsafeStruct(); + unsafe + { + if (us.aField[0] == 0) + return us.aField[1]; + else + return us.aField[2]; + } + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1721.md b/docs/csharp/language-reference/compiler-messages/cs1721.md new file mode 100644 index 0000000000000..7b35da6b2f392 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1721.md @@ -0,0 +1,66 @@ +--- +title: "Compiler Error CS1721 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1721" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1721" +ms.assetid: f02dc9b1-8e38-4562-b013-4d752ad79061 +caps.latest.revision: 12 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1721 +Class 'class' cannot have multiple base classes: 'class_1' and 'class_2' + + The most common cause of this error message is attempting to use multiple inheritance. A class in C# may only inherit directly from one class. However, a class can implement any number of interfaces. + +## Example + The following example shows one way in which SC1721 is generated, and then shows two possible ways to avoid the error. + +``` +// CS1721.cs +public class A {} +public class B {} +public class MyClass : A, B {} // CS1721 + +// One possible fix is to use the following approach instead: +public class A {} +public class B : A {} +public class C : B {} + +// Another possible fix is to use interfaces instead of base classes: +public class A {} +public interface B {} +public class C : A, B {} + +``` + +## See Also + [Polymorphism](../../../csharp/programming-guide/classes-and-structs/polymorphism.md) + [Interfaces](../../../csharp/programming-guide/interfaces/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1726.md b/docs/csharp/language-reference/compiler-messages/cs1726.md new file mode 100644 index 0000000000000..513fe75912433 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1726.md @@ -0,0 +1,72 @@ +--- +title: "Compiler Error CS1726 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1726" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1726" +ms.assetid: 02b71f22-72f5-42b5-bc9e-1d5dc480cce0 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1726 +Friend assembly reference 'reference' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations. + + A strong name signed assembly can only grant friend assembly access, made with the , to other strongly signed assemblies. + + To resolve CS1726, either sign (give a strong name to) the assembly to which you want to grant friend access, or don't grant friend access. + + For more information, see [Friend Assemblies](http://msdn.microsoft.com/library/df0c70ea-2c2a-4bdc-9526-df951ad2d055). + +## Example + The following sample generates CS1726. + +``` + +// Save this code as CS1726.cs + +// Run the following command to create CS1726.key: +// sn -k CS1726.key + +// Then compile by using the following command: +// csc /keyfile:CS1726.key /target:library CS1726.cs + +using System.Runtime.CompilerServices; + +// The following line causes compiler error CS1726. +[assembly: InternalsVisibleTo("UnsignedAssembly")] + +// To get rid of the error, try the following line instead. +//[assembly: InternalsVisibleTo("SignedAssembly, PublicKey=0024000004800000940000000602000000240000525341310004000001000100031d7b6f3abc16c7de526fd67ec2926fe68ed2f9901afbc5f1b6b428bf6cd9086021a0b38b76bc340dc6ab27b65e4a593fa0e60689ac98dd71a12248ca025751d135df7b98c5f9d09172f7b62dabdd302b2a1ae688731ff3fc7a6ab9e8cf39fb73c60667e1b071ef7da5838dc009ae0119a9cbff2c581fc0f2d966b77114b2c4")] + +class A { } +``` + +## See Also + [How to: Create Signed Friend Assemblies](http://msdn.microsoft.com/library/f5542300-58b4-4e1c-b809-8df11e95e69b) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1729.md b/docs/csharp/language-reference/compiler-messages/cs1729.md new file mode 100644 index 0000000000000..9e53a5f098e13 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1729.md @@ -0,0 +1,100 @@ +--- +title: "Compiler Error CS1729 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1729" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1729" +ms.assetid: 69d24ae0-eaca-4fbf-a5f3-70791f43f97a +caps.latest.revision: 13 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1729 +'type' does not contain a constructor that takes 'number' arguments. + + This error occurs when you either directly or indirectly invoke the constructor of a class but the compiler cannot find any constructors with the same number of parameters. In the following example, the `test` class has no constructors that take any arguments. It therefore has only a default constructor that takes zero arguments. Because in the second line in which the error is generated, the derived class declares no constructors of its own, the compiler provides a default constructor. That constructor invokes a parameterless constructor in the base class. Because the base class has no such constructor, CS1729 is generated. + +## To correct this error + +1. Adjust the number of parameters in the call to the constructor. + +2. Modify the class to provide a constructor with the parameters you must call. + +3. Provide a parameterless constructor in the base class. + +## Example + The following example generates CS1729: + +```cs +// cs1729.cs +class Test +{ + static int Main() + { + // Class Test has only a default constructor, which takes no arguments. + Test test1 = new Test(2); // CS1729 + // The following line resolves the error. + Test test2 = new Test(); + + // Class Parent has only one constructor, which takes two int parameters. + Parent exampleParent1 = new Parent(10); // CS1729 + // The following line resolves the error. + Parent exampleParent2 = new Parent(10, 1); + + return 1; + } +} + +public class Parent +{ + // The only constructor for this class has two parameters. + public Parent(int i, int j) { } +} + +// The following declaration causes a compiler error because class Parent +// does not have a constructor that takes no arguments. The declaration of +// class Child2 shows how to resolve this error. +public class Child : Parent { } // CS1729 + +public class Child2 : Parent +{ + // The constructor for Child2 has only one parameter. To access the + // constructor in Parent, and prevent this compiler error, you must provide + // a value for the second parameter of Parent. The following example provides 0. + public Child2(int k) + : base(k, 0) + { + // Add the body of the constructor here. + } +} +``` + +## See Also + [Inheritance](../../../csharp/programming-guide/classes-and-structs/inheritance.md) + [Constructors](../../../csharp/programming-guide/classes-and-structs/constructors.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1762.md b/docs/csharp/language-reference/compiler-messages/cs1762.md new file mode 100644 index 0000000000000..e2bee61bc1501 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1762.md @@ -0,0 +1,54 @@ +--- +title: "Compiler Warning (level 1) CS1762 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1762" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1762" +ms.assetid: 181d9063-e8a1-413d-8f0d-d05018642136 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1762 +A reference was created to embedded interop assembly '\' because of an indirect reference to that assembly from assembly '\'. Consider changing the 'Embed Interop Types' property on either assembly. + + You have added a reference to an assembly (assembly1) that has the `Embed Interop Types` property set to `True`. This instructs the compiler to embed interop type information from that assembly. However, the compiler cannot embed interop type information from that assembly because another assembly that you have referenced (assembly2) also references that assembly (assembly1) and has the `Embed Interop Types` property set to `False`. + +> [!NOTE] +> Setting the `Embed Interop Types` property on an assembly reference to `True` is equivalent to referencing the assembly by using the `/link` option for the command-line compiler. + +### To address this warning + +- To embed interop type information for both assemblies, set the `Embed Interop Types` property on all references to assembly1 to `True`. For more information about how to set that property, see [Walkthrough: Embedding Types from Managed Assemblies](http://msdn.microsoft.com/library/b28ec92c-1867-4847-95c0-61adfe095e21). + +- To remove the warning, you can set the `Embed Interop Types` property of assembly1 to `False`. In this case, a primary interop assembly (PIA) provides interop type information. + +## See Also + [/link (C# Compiler Options)](../../../csharp/language-reference/compiler-options/link-compiler-option.md) + [Programming with Primary Interop Assemblies](http://msdn.microsoft.com/en-us/306fa1d6-0703-4004-9e93-d0a57f1be81e) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1919.md b/docs/csharp/language-reference/compiler-messages/cs1919.md new file mode 100644 index 0000000000000..8b935491f2989 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1919.md @@ -0,0 +1,67 @@ +--- +title: "Compiler Error CS1919 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1919" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1919" +ms.assetid: 5d1e468b-ddec-4edd-a8b1-9c65c2332778 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1919 +Unsafe type 'type name' cannot be used in object creation. + + The `new` operator creates objects only on the managed heap. However, you can create objects in unmanaged memory indirectly by using the interoperability capabilities of the language to call native methods that return pointers. + +## To correct this error + +1. Use a safe type in the new object creation expression. For example, use `char` or `int` instead of `char*` or `int*`. + +2. If you must create objects in unmanaged memory, use a Win32 or COM method or else write your own function in C or C++ and call it from C#. + +## Example + The following example generates CS1919 because a pointer type is unsafe: + +``` +// cs1919.cs +// Compile with: /unsafe +unsafe public class C +{ + public static int Main() + { + var col1 = new int* { }; // CS1919 + var col2 = new char* { }; // CS1919 + return 1; + } +} +``` + +## See Also + [Interoperability](../../../csharp/programming-guide/interop/interoperability.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1921.md b/docs/csharp/language-reference/compiler-messages/cs1921.md new file mode 100644 index 0000000000000..c86c927a8b0ce --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1921.md @@ -0,0 +1,65 @@ +--- +title: "Compiler Error CS1921 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1921" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1921" +ms.assetid: 0e8326dc-4ad9-49b6-948c-d37f10e6abaf +caps.latest.revision: 6 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1921 +The best overloaded method match for 'method' has wrong signature for the initializer element. The initializable Add must be an accessible instance method. + + This error is generated when you try to use a collection initializer with a class that has no public non-static `Add` method. If the `Add` method is not accessible because of its protection level (`private`, `protected`, `internal`) then you will get CS0122, so that this error probably means that the method is defined as `static`. + +## Example + The following example generates CS1921: + +``` +// cs1921.cs +using System.Collections; +public class C : CollectionBase +{ + public static void Add(int i) + { + } +} +public class Test +{ + public static void Main() + { + var collection = new C { 1, 2, 3 }; // CS1921 + } +} +``` + +## See Also + [Object and Collection Initializers](../../../csharp/programming-guide/classes-and-structs/object-and-collection-initializers.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1926.md b/docs/csharp/language-reference/compiler-messages/cs1926.md new file mode 100644 index 0000000000000..dfc3620fb9d80 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1926.md @@ -0,0 +1,70 @@ +--- +title: "Compiler Error CS1926 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1926" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1926" +ms.assetid: 58cc8385-8d92-4cee-8941-d05e128e3674 +caps.latest.revision: 5 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1926 +Error reading Win32 manifest file 'filename' -- 'error'. + + This error is generated when the following conditions are true: + +1. The **/win32manifest** option is specified either on the command line or by right-clicking the **Project** icon in **Solution Explorer**, pointing to **Add**, clicking **New Item**, and then clicking **Application Manifest File**. + +2. The file is either corrupted or missing. + +## To correct this error + +1. Remove the option. + +2. Replace, repair, or regenerate the file. + +## Example + The following example generates CS1926 when it is compiled with a corrupted for missing win32 manifest file: + +``` +// cs1926.cs +// Compile with: /win32manifest: ../../app.manifest +// CS1926 +class Test +{ + public static int Main() + { + return 1; + } +} +``` + +## See Also + [/win32manifest (C# Compiler Options)](../../../csharp/language-reference/compiler-options/win32manifest-compiler-option.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1933.md b/docs/csharp/language-reference/compiler-messages/cs1933.md new file mode 100644 index 0000000000000..c47e8718cdbfc --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1933.md @@ -0,0 +1,66 @@ +--- +title: "Compiler Error CS1933 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1933" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1933" +ms.assetid: 80d719d3-1b39-44ec-90fd-039ae5570f01 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1933 +Expression cannot contain query expressions + + Some variables cannot be initialized with a query expression. Constants cannot be initialized with query expressions because constants may only be initialized with some combination of literals, named constants, and mathematical operators. + +## To correct this error + +1. Remove the modifier from the query variable. + +## Example + The following example generates CS1933: + +``` +// cs1933.cs +using System.Linq; +using System.Collections; + +class P +{ + const IEnumerable e = from x in new[] { 1, 2, 3 } select x; // CS1933 + static int Main() + { + return 1; + } +} +``` + +## See Also + [LINQ Query Expressions](../../../csharp/programming-guide/linq-query-expressions/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1936.md b/docs/csharp/language-reference/compiler-messages/cs1936.md new file mode 100644 index 0000000000000..33da25092cf0f --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1936.md @@ -0,0 +1,71 @@ +--- +title: "Compiler Error CS1936 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1936" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1936" +ms.assetid: 980161b5-5bd7-4cb5-8b66-9bcbb062a8e6 +caps.latest.revision: 6 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1936 +Could not find an implementation of the query pattern for source type 'type'. 'method' not found. + + In order to query a source type, that type must implement the standard query operator methods that you are invoking in the query. The implementation can be either in the form of class members or extension methods that are brought into scope with the appropriate `using` directive. + +## To correct this error + +- Make sure that you are querying a collection of objects, not an individual object. + +- Make sure that you have specified the necessary `using` directives. + +## Example + The following example produces CS1936: + +``` +// cs1936.cs +using System.Collections; +using System.Linq; +class Test +{ + static int Main() + { + object obj; + IEnumerable e = from x in obj // CS1936 + select x; + return 0; + } +} +``` + + This error typically occurs when you accidentally try to query an object of some type instead of a collection of those objects. + +## See Also + [Standard Query Operators Overview](http://msdn.microsoft.com/library/24cda21e-8af8-4632-b519-c404a839b9b2) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1941.md b/docs/csharp/language-reference/compiler-messages/cs1941.md new file mode 100644 index 0000000000000..8738721c3a869 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1941.md @@ -0,0 +1,72 @@ +--- +title: "Compiler Error CS1941 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1941" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1941" +ms.assetid: 503054d6-9553-4a2a-9b68-4ccfdeccca22 +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1941 +The type of one of the expressions in the 'clause' clause is incorrect. Type inference failed in the call to 'method'. + + Type inference in query expressions flows from the type of the elements in the data source(s). + +## To correct this error + +1. If it is not immediately obvious why the error is occurring, examine the query carefully and trace the type of the result of each clause from the data source to the point where the error is occurring. + +## Example + The following code generates CS1941 because the `equals` operator is being asked to compare an `int` to a `string`. + +``` +// cs1941.cs +using System.Collections; +using System.Linq; +class Test +{ + static int Main() + { + var nums = new[] { 1, 2, 3, 4, 5, 6 }; + var words = new string[] { "lake", "mountain", "sky" }; + IEnumerable e = from n in nums + join w in words on n equals w // CS1941 + select w; + return 0; + } +} +``` + + The method in which type inference fails is the method that the query clause is translated to at compile time. + +## See Also + [LINQ Query Expressions](../../../csharp/programming-guide/linq-query-expressions/index.md) + [Type Relationships in LINQ Query Operations](../../../csharp/programming-guide/concepts/linq/type-relationships-in-linq-query-operations.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1942.md b/docs/csharp/language-reference/compiler-messages/cs1942.md new file mode 100644 index 0000000000000..98d69a34731fa --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1942.md @@ -0,0 +1,66 @@ +--- +title: "Compiler Error CS1942 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1942" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1942" +ms.assetid: afbe5e8e-1944-416e-916b-39e2c373814b +caps.latest.revision: 5 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1942 +The type of the expression in the 'clause' clause is incorrect. Type inference failed in the call to 'method'. + + This error is typically generated when the range variable has been given an incorrect explicit type. + +## To correct this error + +1. If the range variable is explicitly typed, make sure that the type is either the same as, or implicitly convertible from, the type of the elements in the collection it iterates. If the range variable is preceded with the `var` keyword, remove `var`. + +## Example + The following code generates CS1942: + +``` +// cs1942.cs +class Program + { + static void Main(string[] args) + { + var x = from var i in Enumerable.Range(1, 100) // CS1949 + select i; //CS1942 + } + } +``` + + CS1942 is related to CS1949 because the use of `var` with a range variable causes the underlying `Cast` operation to fail because `var` is not a type. + +## See Also + [var](../../../csharp/language-reference/keywords/var.md) + [LINQ Query Expressions](../../../csharp/programming-guide/linq-query-expressions/index.md) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1943.md b/docs/csharp/language-reference/compiler-messages/cs1943.md new file mode 100644 index 0000000000000..34bb8f08b8e9e --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1943.md @@ -0,0 +1,69 @@ +--- +title: "Compiler Error CS1943 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1943" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1943" +ms.assetid: eb3e36b7-1372-471c-8cfb-a955a86c379e +caps.latest.revision: 5 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1943 +An expression of type 'type' is not allowed in a subsequent from clause in a query expression with source type 'type'. Type inference failed in the call to 'method'. + + All range variables must represent queryable types. + +## To correct this error + +1. Make sure that the type is a queryable type that implements `IEnumerable`, `IEnumerable` or a derived interface, or any other type which has a query pattern defined for it. + +2. If the type is a non-generic `IEnumerable`, provide an explicit type on the range variable. + +## Example + The following code generates CS1943: + +``` +// cs1943.cs +using System.Linq; +class Test +{ + class TestClass + { } + static void Main() + { + int[] nums = { 0, 1, 2, 3, 4, 5 }; + TestClass tc = new TestClass(); + + var x = from n in nums + from s in tc // CS1943 + select n + s; + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1946.md b/docs/csharp/language-reference/compiler-messages/cs1946.md new file mode 100644 index 0000000000000..3acd86379f3a6 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1946.md @@ -0,0 +1,70 @@ +--- +title: "Compiler Error CS1946 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1946" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1946" +ms.assetid: 4ccef263-1ae8-4065-ab46-25d14a38e24e +caps.latest.revision: 7 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS1946 +An anonymous method expression cannot be converted to an expression tree. + + An anonymous method represents a set of statements but an expression tree must not contain a statement. Therefore an anonymous method cannot be represented by an expression tree. + +## To correct this error + +1. Change the anonymous method to a lambda expression. + +## Example + The following example generates CS1946: + +``` +// cs1946.cs +using System; + using System.Linq.Expressions; + + public delegate void D(); + + class Test + { + static void Main() + { + Expression tree = delegate() { }; //CS1946 + // Try using a lambda expression instead. + // Expression tree = (x) => x + 1; + } + } +``` + +## See Also + [Anonymous Methods](../../../csharp/programming-guide/statements-expressions-operators/anonymous-methods.md) + [Expression Trees](http://msdn.microsoft.com/library/fb1d3ed8-d5b0-4211-a71f-dd271529294b) \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs1956.md b/docs/csharp/language-reference/compiler-messages/cs1956.md new file mode 100644 index 0000000000000..96505f895fcfe --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs1956.md @@ -0,0 +1,84 @@ +--- +title: "Compiler Warning (level 1) CS1956 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS1956" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS1956" +ms.assetid: 841f8b2b-692b-49ae-a587-a40797cf9797 +caps.latest.revision: 9 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS1956 +Member 'name' implements interface member 'name' in type 'type'. There are multiple matches for the interface member at run-time. It is implementation dependent which method will be called. + + This warning can be generated when two interface methods are differentiated only by whether a particular parameter is marked with `ref` or with `out`. It is best to change your code to avoid this warning because it is not obvious or guaranteed which method is called at runtime. + + Although C# distinguishes between `out` and `ref`, the CLR sees them as the same. When deciding which method implements the interface, the CLR just picks one. + +### To avoid this warning + +1. Give the compiler some way to differentiate the methods. For example, you can give them different names or provide an additional parameter on one of them. + +## Example + The following code generates CS1956 because the two `Test` methods in `Base` differ only by the `ref`/`out` modifier on the first parameter. + +```cs +// cs1956.cs +class Base +{ + // This is the method that should be called. + public virtual int Test(out T x) // CS1956 + { + x = default(T); + return 0; + } + + // This is the "last" method and is the one that ends up being called + public virtual int Test(ref S x) + { + return 1; + } +} + +interface IFace +{ + int Test(out int x); +} + +class Derived : Base, IFace +{ + static int Main() + { + IFace x = new Derived(); + int y; + return x.Test(out y); + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs2032.md b/docs/csharp/language-reference/compiler-messages/cs2032.md new file mode 100644 index 0000000000000..d1ceedb01c073 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs2032.md @@ -0,0 +1,63 @@ +--- +title: "Compiler Error CS2032 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS2032" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS2032" +ms.assetid: 534e2d2f-d209-43dd-abc9-e5ea5b01efc4 +caps.latest.revision: 14 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Error CS2032 +Character 'character' is not allowed on the command-line or in response files + + Response files and the command line options for csc.exe cannot contain ASCII control characters in the range 0-31 or the pipe (`|`) character. + + Compiler error CS2032 is difficult to demonstrate from the command line because the command line processor and the integrated development environment (IDE) filter out characters that are not valid. The following procedure generates the error by using a [response file](../../../csharp/language-reference/compiler-options/response-file-compiler-option.md). + +### To generate this error + +1. In the **My Documents** folder, create a text file that is named CS2032.rsp, and then enter the following compiler options in it: + + ```cs + /target:exe /out:cs|2032.exe cs2032.cs + ``` + +2. In the **My Documents** folder, create a text file that is named cs2032.cs and that contains whatever you want. + +3. Open **Start**, and then choose **All Programs**, **Microsoft Visual Studio 2010**, **Visual Studio Tools**, **Visual Studio Command Prompt**. + + The **Visual Studio Command Prompt** window opens. + +4. In the **Visual Studio Command Prompt** window, change the current directory to C:\Users\\*YourUsername*\Documents. + +5. Run the following command from the **Visual Studio Command Prompt**: `csc @cs2032.rsp` + +6. The CS2032 error message appears because the response file, CS2032.rsp, contains a pipe character. \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs3003.md b/docs/csharp/language-reference/compiler-messages/cs3003.md new file mode 100644 index 0000000000000..d8e7b8dcb2728 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs3003.md @@ -0,0 +1,57 @@ +--- +title: "Compiler Warning (level 1) CS3003 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS3003" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS3003" +ms.assetid: 1845508d-e97f-4bef-b94c-9f14cfc8bdb3 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS3003 +Type of 'variable' is not CLS-compliant + + A [public](../../../csharp/language-reference/keywords/public.md), [protected](../../../csharp/language-reference/keywords/protected.md), or `protected internal` variable must be of a type that is compliant with the Common Language Specification (CLS). For more information on CLS Compliance, see [Language Independence and Language-Independent Components](https://msdn.microsoft.com/library/12a7a7h3). + +## Example + The following example generates CS3003: + +``` +// CS3003.cs + +[assembly:System.CLSCompliant(true)] +public class a +{ + public ushort a1; // CS3003, public variable + public static void Main() + { + } +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs3007.md b/docs/csharp/language-reference/compiler-messages/cs3007.md new file mode 100644 index 0000000000000..fdbc110bf768f --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs3007.md @@ -0,0 +1,60 @@ +--- +title: "Compiler Warning (level 1) CS3007 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS3007" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS3007" +ms.assetid: 9c6bf776-3099-4ab5-ae89-4068ec722f79 +caps.latest.revision: 11 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS3007 +Overloaded method 'method' differing only by unnamed array types is not CLS-compliant + + This error occurs if you have an overloaded method that takes a jagged array and the only difference between the method signatures is the element type of the array. To avoid this error, consider using a rectangular array rather than a jagged array; use an additional parameter to disambiguate the function call; rename one or more of the overloaded methods; or, if CLS Compliance is not needed, remove the attribute. For more information on CLS Compliance, see [Language Independence and Language-Independent Components](https://msdn.microsoft.com/library/12a7a7h3). + +## Example + The following example generates CS3007: + +``` +// CS3007.cs +[assembly: System.CLSCompliant(true)] +public struct S +{ + public void F(int[][] array) { } + public void F(byte[][] array) { } // CS3007 + // Try this instead: + // public void F1(int[][] array) {} + // public void F2(byte[][] array) {} + // or + // public void F(int[,] array) {} + // public void F(byte[,] array) {} +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs3009.md b/docs/csharp/language-reference/compiler-messages/cs3009.md new file mode 100644 index 0000000000000..9bfecc99644a6 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs3009.md @@ -0,0 +1,61 @@ +--- +title: "Compiler Warning (level 1) CS3009 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS3009" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS3009" +ms.assetid: 41a1d2c4-d558-4066-8f3f-e9d2d69298a8 +caps.latest.revision: 8 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "cs-cz" + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "pl-pl" + - "pt-br" + - "ru-ru" + - "tr-tr" + - "zh-cn" + - "zh-tw" +--- +# Compiler Warning (level 1) CS3009 +'type': base type 'type' is not CLS-compliant + + A base type was marked as not having to be compliant with the Common Language Specification (CLS) in an assembly that was marked as being CLS compliant. Either remove the attribute that specifies the assembly is CLS compliant or remove the attribute that indicates the type is not CLS compliant. For more information on CLS Compliance, see [Writing CLS-Compliant Code](http://msdn.microsoft.com/en-us/4c705105-69a2-4e5e-b24e-0633bc32c7f3) and [Language Independence and Language-Independent Components](https://msdn.microsoft.com/library/12a7a7h3). + +## Example + The following example generates CS3009: + +``` +// CS3009.cs + +using System; + +[assembly:CLSCompliant(true)] +[CLSCompliant(false)] +public class B +{ +} + +public class C : B // CS3009 +{ + public static void Main () {} +} +``` \ No newline at end of file diff --git a/docs/csharp/language-reference/compiler-messages/cs4014.md b/docs/csharp/language-reference/compiler-messages/cs4014.md new file mode 100644 index 0000000000000..b85b96be90b6e --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/cs4014.md @@ -0,0 +1,258 @@ +--- +title: "Compiler Warning (level 1) CS4014 | Microsoft Docs" +ms.custom: "" +ms.date: "2015-07-20" +ms.prod: "visual-studio-dev14" +ms.reviewer: "" +ms.suite: "" +ms.technology: + - "devlang-csharp" +ms.tgt_pltfrm: "" +ms.topic: "error-reference" +f1_keywords: + - "CS4014" +dev_langs: + - "CSharp" +helpviewer_keywords: + - "CS4014" +ms.assetid: b9e7c029-eaa9-48d7-8b3c-9823772c9acb +caps.latest.revision: 26 +author: "BillWagner" +ms.author: "wiwagn" +manager: "wpickett" +translation.priority.ht: + - "de-de" + - "es-es" + - "fr-fr" + - "it-it" + - "ja-jp" + - "ko-kr" + - "ru-ru" + - "zh-cn" + - "zh-tw" +translation.priority.mt: + - "cs-cz" + - "pl-pl" + - "pt-br" + - "tr-tr" +--- +# Compiler Warning (level 1) CS4014 +Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. + + The current method calls an async method that returns a or a and doesn’t apply the [await](../../../csharp/language-reference/keywords/await.md) operator to the result. The call to the async method starts an asynchronous task. However, because no `await` operator is applied, the program continues without waiting for the task to complete. In most cases, that behavior isn't what you expect. Usually other aspects of the calling method depend on the results of the call or, minimally, the called method is expected to complete before you return from the method that contains the call. + + An equally important issue is what happens to exceptions that are raised in the called async method. An exception that's raised in a method that returns a or is stored in the returned task. If you don't await the task or explicitly check for exceptions, the exception is lost. If you await the task, its exception is rethrown. + + As a best practice, you should always await the call. + + You should consider suppressing the warning only if you're sure that you don't want to wait for the asynchronous call to complete and that the called method won't raise any exceptions. In that case, you can suppress the warning by assigning the task result of the call to a variable. + + The following example shows how to cause the warning, how to suppress it, and how to await the call. + +```cs + +async Task CallingMethodAsync() +{ + resultsTextBox.Text += "\r\n Entering calling method."; + // Variable delay is used to slow down the called method so that you can + // distinguish between awaiting and not awaiting in the program's output. + // You can adjust the value to produce the output that this topic shows + // after the code. + var delay = 5000; + + // Call #1. + // Call an async method. Because you don't await it, its completion + // isn't coordinated with the current method, CallingMethodAsync. + // The following line causes warning CS4014. + CalledMethodAsync(delay); + + // Call #2. + // To suppress the warning without awaiting, you can assign the + // returned task to a variable. The assignment doesn't change how + // the program runs. However, recommended practice is always to + // await a call to an async method. + + // Replace Call #1 with the following line. + //Task delayTask = CalledMethodAsync(delay); + + // Call #3 + // To contrast with an awaited call, replace the unawaited call + // (Call #1 or Call #2) with the following awaited call. Best + // practice is to await the call. + + //await CalledMethodAsync(delay); + + // If the call to CalledMethodAsync isn't awaited, CallingMethodAsync + // continues to run and, in this example, finishes its work and returns + // to its caller. + resultsTextBox.Text += "\r\n Returning from calling method."; +} + +async Task CalledMethodAsync(int howLong) +{ + resultsTextBox.Text += + "\r\n Entering called method, starting and awaiting Task.Delay."; + + // Slow the process down a little so that you can distinguish between + // awaiting and not awaiting in the program's output. Adjust the value + // for howLong if necessary. + await Task.Delay(howLong); + resultsTextBox.Text += + "\r\n Task.Delay is finished--returning from called method."; +} +``` + + In the example, if you choose Call #1 or Call #2, the unawaited async method (`CalledMethodAsync`) finishes after both its caller (`CallingMethodAsync`) and the caller's caller (`startButton_Click`) are complete. The last line in the following output shows you when the called method finishes. Entry to and exit from the event handler that calls `CallingMethodAsync` in the full example are marked in the output. + +``` + +Entering the Click event handler. + Entering calling method. + Entering called method, starting and awaiting Task.Delay. + Returning from calling method. +Exiting the Click event handler. + Task.Delay is finished--returning from called method. +``` + + You can also suppress compiler warnings by using [#pragma warning](../../../csharp/language-reference/preprocessor-directives/preprocessor-pragma-warning.md) directives. + +## Example + The following Windows Presentation Foundation (WPF) application contains the methods from the previous example. The following steps set up the application. + +1. Create a WPF application, and name it `AsyncWarning`. + +2. In the Visual Studio Code Editor, choose the **MainWindow.xaml** tab. + + If the tab isn't visible, open the shortcut menu for MainWindow.xaml in **Solution Explorer**, and then choose **View Code**. + +3. Replace the code in the **XAML** view of MainWindow.xaml with the following code. + + ```cs + + +