1

I am trying to host my application in Azure but getting below error:

Compiler Error Message: CS1056: Unexpected character '$' Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2623.0

I have used string concatenation using '$' sign. This works fine in my local machine, but throws the compilation error.

How to set the right framework version in Azure and avoid the above exception.

Thanks, Sharath

Sharath
  • 171
  • 1
  • 4
  • 18
  • What kind of application and how did you publish to Azure? A lot can go wrong, and first check if you have Roslyn properly configured in `web.config`. – Lex Li Apr 15 '18 at 16:00
  • Hi Lex, It is Kentico CMS application. But I deployed whole site packages from my local machine to Azure using FTP. I can't see anything related Rolyn in my application, I will check again. – Sharath Apr 18 '18 at 03:23

2 Answers2

1

Lex should get credit for sending this in the correct direction. I want to confirm that this is the correct path and fixes the issue and give a little more detail. I was having the same issue and error message "Compiler Error Message: CS1056: Unexpected character '$'" when trying to deploy a ASP.NET app to Microsoft Azure App Service and indeed the solution was to add the Roslyn compiler to the project. It appears by default the built in compiler used on Microsoft Azure App Service only supports up to C# 5 language features and Roslyn is needed to compile and use the C# 6 features. Note I am deploying CS files for my project and not compiled DLL files.

Install Roslyn In Project

  1. In Visual Studio 2017 Select "Tools" -> "NuGet Package Manager" -> "Manage NuGet Packages for Solution..."
  2. From the tabs select "Browse" and then search for "Microsoft.CodeDom.Providers.DotNetCompilerPlatform"
  3. Select "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" from the search results then over on the right check the project name you want to add it to and then click the "Install" button.
  4. Rebuild your Solution and make sure it still builds.

Deploy with Roslyn

  1. You will notice installing the DotNetCompilerPlatform package added a section to your Web.config file that looks something like this, make sure this section gets added to your deployed Web.config:

      <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers></system.codedom>
    
  2. You will also notice installing the DotNetCompilerPlatform package and building your solution added some files to your Bin folder, make sure these files (including the whole "roslyn" folder and all the files in it) get put in the Bin folder of your deploy: Bin folder files to deploy

That was all it took to get my website back up and running with C# 6 language features, hope it helps.

dan-iel
  • 801
  • 8
  • 4
  • I also found that after doing the above steps that I needed to update any packages in nuget package manager that were listed. Note: I did this after installing Roslyn. – Jason R Jul 02 '20 at 02:24
0

You can install Microsoft.Dotnet.Compilers package and then compile your site again.

Refer this page - Project builds fine with Visual Studio but fails from the command line

Manoj Choudhari
  • 5,277
  • 2
  • 26
  • 37