C# Error Cs1518
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. MSDN Library MSDN Library MSDN Library MSDN Library Design Tools Development Tools and Languages Mobile and Embedded Development .NET Development Office development Online Services Open Specifications patterns & practices Servers and Enterprise Development Speech Technologies Web Development Windows Desktop App Development TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. Compiler Error CS1518 Other Versions Visual Studio 2008 Visual Studio 2005 Visual Studio .NET 2003 Expected class, delegate, enum, interface, or structA declaration was found that is not supported in a namespace. Inside a namespace, the compiler accepts only classes, structs, enums, interfaces, namespaces, and delegates.ExampleThe following sample generates CS1518: Copy // CS1518.cs namespace x { sealed class c1 {}; // OK namespace f2 {}; // OK sealed f3 {}; // CS1518 } Show: Inherited Protected Print Export (0) Print Export (0) Share IN THIS ARTICLE Is this page helpful? Yes No Additional feedback? 1500 characters remaining Submit Skip this Thank you! We appreciate your feedback. Dev centers Windows Office Visual Studio Microsoft Azure More... Learning resources Microsoft Virtual Academy Channel 9 MSDN Magazine Community Forums Blogs Codeplex Support Self support Programs BizSpark (for startups) Microsoft Imagine (for students) United States (English) Newsletter Privacy & cookies Terms of use Trademarks © 2016 Microsoft © 2016 Microsoft
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up CS1518: Expected class, https://msdn.microsoft.com/en-us/library/8tfcb4de.aspx delegate, enum, interface, or struct up vote -1 down vote favorite I am trying to write a new XSLT package. The code that I am using is public virtual string CustomShowInventoryTable(String sProductID, String sVariantID) { StringBuilder results = new StringBuilder(""); if (AppLogic.AppConfigBool("ShowInventoryTable")) { results.Append(AppLogic.GetInventoryTable(ProductID, VariantID, true, ThisCustomer.SkinID, true, false)); } return results.ToString(); } The error I am getting is Compiler Error Message: CS1518: Expected http://stackoverflow.com/questions/21910568/cs1518-expected-class-delegate-enum-interface-or-struct class, delegate, enum, interface, or struct I have tried checking the ( and ) within the file but I still get this compiled error. c# xslt share|improve this question edited Feb 20 '14 at 15:00 helderdarocha 14.5k31535 asked Feb 20 '14 at 14:21 Jennifer Larsson 713 1 The compiler should tell you which line, and which column of that line, it's complaining about. Which line is that? (And in this case what's happening before that, since this message usually means your {} braces are not matched properly.) –keshlam Feb 20 '14 at 14:25 Its this linepublic virtual string CustomShowInventoryTable(String sProductID, String sVariantID) –Jennifer Larsson Feb 20 '14 at 14:27 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted I believe that you have a couple of typos in your code: It should be public virtual String, not string. Or maybe string sProductID, string sVariantID instead of String, depending on which language you're working with. AppLogic.GetInventoryTable(ProductID, VariantID - are those variables defined? The ones that your method receive have different names, sProductID and sVariantID... share|improve this answer answered Feb 20 '14 at 14:40 A
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and http://stackoverflow.com/questions/16800130/errors-when-compiling-expected-class-delegate-enum-interface-or-struct policies of this site About Us Learn more about Stack Overflow the https://bytes.com/topic/c-sharp/answers/669488-trying-declare-extern-function company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes c# error a minute: Sign up Errors when compiling: “Expected class, delegate, enum, interface, or struct” up vote 2 down vote favorite What is wrong with this code? This program is meant to copy a file and email it to a email address, but it doesn't. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; c# error cs1518 using System.Net.Mail; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { } } public void email_send() { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("your mail@gmail.com"); mail.To.Add("to_mail@gmail.com"); mail.Subject = "Test Mail - 1"; mail.Body = "mail with attachment"; System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment("c:/textfile.txt"); mail.Attachments.Add(attachment); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("your mail@gmail.com", "your password"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } } This shows the following compiler errors: Expected class, delegate, enum, interface, or struct Expected class, delegate, enum, interface, or struct Expected class, delegate, enum, interface, or struct Expected class, delegate, enum, interface, or struct Expected class, delegate, enum, interface, or struct Expected class, delegate, enum, interface, or struct Type or namespace definition, or end-of-file expected Expected class, delegate, enum, interface, or struct What can I do about this? c# compiler-errors share|improve this question edited May 28 '13 at 19:49 CodeCaster 76.4k982134 asked May 28 '13 at 19:41 user2429934 11112 add a comment| 4 Answers
your question and get tips & solutions from a community of 418,461 IT Pros & Developers. It's quick & easy. Trying to declare an extern function P: n/a =?Utf-8?B?UmljaGFyZEBub3NwYW0ubm9zcGFt?= I'm trying to declare CreateFile as an extern from the dll like so: .... using System.Runtime.InteropServices; [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError=true)] internal static extern IntPtr CreateFile( String filename, UInt32 desiredAccess, UInt32 shareMode, IntPtr attributes, // Really, this is the SECURITY_ATTRIBUTES pointer UInt32 creationDisposition, UInt32 flagsAndAttributes, IntPtr templateFile); namespace CsharpPipes { .... I get an error on the "IntPtr" that says: error CS1518: Expected class, delegate, enum, interface, or struct with F1 help text of: A declaration was found that is not supported in a namespace. Inside a namespace, the compiler accepts only classes, structs, enums, interfaces, namespaces, and delegates. I assumed my declaration was outside a namespace(?) What's the proper syntax to declare CreateFile? Thanks in advance. Richard Jun 27 '07 #1 Post Reply Share this Question 4 Replies P: n/a Jon Skeet [C# MVP] On Jun 27, 3:46 pm, Rich...@nospam.nospam