NOTE: This appears to be a problem with the compiler that's used with SSDT projects, it's apparently fixed in the 2017 RC. My problem is similar to one described here.
I've got some code which refuses to let me write it as an expression-bodied function member. In short, I want to do this:
void foo() => bar();
But the IDE throws a tantrum and demands I write it like this:
void foo() { bar(); }
I mean sure, it's two extra characters but I'm not sure why it's complaining, the errors don't make sense either. It gives me the following 3 errors:
- CS0000: ; expected
- CS0000: Method must have a return type.
- CS0000: Identifier expected.
The full code looks like this.
public static void foo() => bar("some param"); // Errors on this line.
static void bar(string myParam) { //20 lines of code }
I've tested this in the C# interactive window and everything compiles and runs correctly. I can't find any unprintable characters in the code.
This is using VS 2015 community with the target framework being 4.6.1
Full code:
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
public partial class Triggers
{
private const string ConnectionString = "context connection = true";
private const string ReadInsertedTable = @"
SELECT ID,
(
SELECT *
FROM inserted AS b
WHERE a.ID = b.ID
FOR XML RAW, ELEMENTS XSINIL
)
FROM inserted AS a
";
[SqlTrigger(Name = "Person_Insert", Target = "Person", Event = "FOR INSERT")]
public static void Person_Insert() => AuditInsert(TableName); // All errors here.
private const string TableName = "Person";
private static void AuditInsert(string tableName)
{
using (var readConnection = new SqlConnection(ConnectionString))
using (var writeConnection = new SqlConnection(ConnectionString))
{
using (var readCommand = new SqlCommand(ReadInsertedTable, readConnection))
{
readConnection.Open();
using (var reader = readCommand.ExecuteReader())
{
SqlContext.Pipe.Send((reader));
}
}
}
}
}
Update: Code compiles using the msbuild utility but still fails in Visual Studio.
Microsoft.Net.Compilers
. Then add it to the project and click INSTALL. Do the same forMicrosoft.CodeDom.Providers.DotNetCompilerPlatform
. Close NUGET and rebuild your project. – Costumier