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:
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.
This will have something to do with Roslyn. Try to run this:
Non-roslyn: https://dotnetfiddle.net/LJm1Fj
Roslyn: https://dotnetfiddle.net/aMUsj0
I suspect there's something wrong either with your project file or your Visual Studio installation because VS2015 should use Roslyn-based compiler by default.
I'd try:
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
and targets <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
C:\Program Files (x86)\MSBuild\14.0\bin\csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /platform:anycpu32bitpreferred /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:"C:\Program Files (x86)\Reference ... Using shared compilation with compiler from directory: C:\Program Files (x86)\MSBuild\14.0\bin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With