Using static statement not working in C# 7.3 on Dotnet framework 4.72

Viewed 93

I'm converting an old application over from VB.Net to C# and got most of the converting done, but ran into an error message that should not be there (can't use "using static ..." in a couple of files, but it works fine everywhere else).

Sometimes it builds the entire solution without an error (until I run it), sometimes not. I presume this is a bug carried over since Visual Studio 2015.

The error is:

CS8026 Feature 'using static' is not available in C# 5. Please use language version 6 or greater.

I know it's a bug as DotNetFW 4.72 uses C#7.3. But I need a workaround, patch, hack or something.

I've tried changing the C# version in the Advanced settings for the application Build, but it's greyed out with the text "Automatically selected based on framework version".

I followed some steps to edit the proj file, with no luck (it DID work for every project in the solution where this same error popped up, but not the webforms project).

All projects in the solution use the same version of DNFW (4.72).

I've cleaned and rebuilt the solution, closed VS and reopened it, rebooted the computer (sometimes that helps) and am out of ideas. There's got to be a trick to force C# version 7.3 to work, somewhere, but I can't find it. What can I try next?

using System;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using static AppCore.Core.Xutilities;  <-- this is the problem, but only occurs on the web application

The same using statements work on the other 3 console apps and 1 web api app.

Update

Okay- the closest I am to an answer is here. A user suggested a fix, but the suggestion is too vague - so I'm experimenting. But at least I know it's truly a VS bug! :)

1 Answers

Okay, the solution is to add the Nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform and make sure it's version 3.6

  • this wasn't a bug, per se, just an artifact from changing versions over time (the initial solution was made with VS2012 and has been upgraded every version since - but it was previously a VB.Net app which is why it worked before translating to C#) Works like a charm!
Related