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
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
In Visual Studio 2017 Select "Tools" -> "NuGet Package Manager" -> "Manage NuGet Packages for Solution..."
From the tabs select "Browse" and then search for "Microsoft.CodeDom.Providers.DotNetCompilerPlatform"
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.
Rebuild your Solution and make sure it still builds.
Deploy with Roslyn
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=\"Web\" /optionInfer+"/>
</compilers></system.codedom>
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.
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
Related
I have an older codebase that uses an ASP.NET Web Site (not an ASP.NET Web App) and am trying to construct a Pipeline for it on Azure DevOps.
After running into some difficulty when the process reaches aspnet_compiler.exe, I created a simple test solution containing a single ASP.NET Web Forms Site, generated from the template in VS2019. I then created a Pipeline using the ASP.NET template and ran it, which ended in familiar failure. The test solution and the real solution are failing at the same spot, so at least I have pinpointed the problem... unfortunately, I don't know how to address it.
The full log for the build step is at the bottom of my post, but here's where I'm stuck specifically:
Project "D:\a\9\s\Hello.sln" (1) is building "D:\a\9\s\WebSite1_1_.metaproj" (2) on node 1 (default targets).
Build:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /localhost_51752 -p WebSite1\ -u -f PrecompiledWeb\localhost_51752\
##[error]WebSite1\web.config(116,0): Error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.
D:\a\9\s\WebSite1\web.config(116): error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located. [D:\a\9\s\WebSite1_1_.metaproj]
I should note that this doesn't appear to be related to the Microsoft.CodeDom.Providers.DotNetCompilerPlatform assembly specifically. In my actual ASP.NET Web Site (not this little test one I'm working with here), this same "Error ASPCONFIG: ... * could not be located." error occurs if the site's web.config contains this, for example:
<compilation debug="true" defaultLanguage="c#" targetFramework="4.8">
<assemblies>
<add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
In that case, it will throw the same error, but about Microsoft.Web.Infrastructure instead. Clearly, aspnet_compiler.exe is unable to find my references, but I don't know what's missing -- are the references not being copied somewhere, or is the process not looking for them in the right place, or... ?
Here is the entire Azure DevOps Pipeline build log:
##[section]Starting: Build solution
==============================================================================
Task : Visual Studio build
Description : Build with MSBuild and set the Visual Studio version property
Version : 1.166.2
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
==============================================================================
##[command]"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -latest -format json
##[command]"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -products Microsoft.VisualStudio.Product.BuildTools -latest -format json
##[command]"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -latest -format json
##[command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" "D:\a\9\s\Hello.sln" /nologo /nr:false /dl:CentralLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.166.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=f1e19740-d1c0-4435-a66d-d2b7ccec211f|SolutionDir=D:\a\9\s"*ForwardingLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.166.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="D:\a\9\a\\" /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="15.0" /p:_MSDeployUserAgent="VSTS_ab00089e-3c64-4607-ad03-57473b1db76f_build_3_0"
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 8/28/2020 6:48:44 PM.
Project "D:\a\9\s\Hello.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "release|any cpu".
Project "D:\a\9\s\Hello.sln" (1) is building "D:\a\9\s\WebSite1_1_.metaproj" (2) on node 1 (default targets).
Build:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /localhost_51752 -p WebSite1\ -u -f PrecompiledWeb\localhost_51752\
##[error]WebSite1\web.config(116,0): Error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.
D:\a\9\s\WebSite1\web.config(116): error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located. [D:\a\9\s\WebSite1_1_.metaproj]
Done Building Project "D:\a\9\s\WebSite1_1_.metaproj" (default targets) -- FAILED.
Done Building Project "D:\a\9\s\Hello.sln" (default targets) -- FAILED.
Build FAILED.
"D:\a\9\s\Hello.sln" (default target) (1) ->
"D:\a\9\s\WebSite1_1_.metaproj" (default target) (2) ->
(Build target) ->
D:\a\9\s\WebSite1\web.config(116): error ASPCONFIG: The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located. [D:\a\9\s\WebSite1_1_.metaproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:09.47
##[error]Process 'msbuild.exe' exited with code '1'.
##[section]Finishing: Build solution
Web Sites seem to need a little extra love to work in an Azure DevOps Pipeline, but they can work. Here's where I landed...
The Pipeline environment doesn't have Visual Studio installed. Make certain that your *.refresh files are pointing to downloaded packages (i.e. stuff NuGet automatically puts in your packages directory), not to the Visual Studio shared packages directory.
In a new Web Site project, for example, the content of Bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll.refresh defaults to:
..\..\..\Program Files (x86)\Microsoft Visual Studio\Shared\Packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
...but should be:
..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
NuGet has no idea it needs to restore packages for a Web Site because there's no *.csproj to tell it so. Add a custom NuGet restore task (where "WebSite1" is the directory your Web Site is in):
steps:
- task: NuGetCommand#2
displayName: 'NuGet Restore for Web Site'
inputs:
command: custom
arguments: 'restore $(Build.SourcesDirectory)\WebSite1\packages.config -SolutionDirectory $(Build.SourcesDirectory)'
NuGet won't run the install PowerShell script to put all the Roslyn files in your Bin directory prior to running aspnet_compiler.exe. You have to do that yourself with a Copy files task:
steps:
- task: CopyFiles#2
displayName: 'Copy Roslyn files'
inputs:
SourceFolder: '$(Build.SourcesDirectory)\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\tools\RoslynLatest'
TargetFolder: '$(Build.SourcesDirectory)\WebSite1\Bin\roslyn'
Current project:
ASP.NET 4.6.2
MVC 5
Visual Studio 2015 Community v14.0.25431.01 Update 3
Installed the CodeDOM Providers for .NET Compiler nuget package via Project -> Install C# 6
Confirmed that I do have the compiler element in my Web.Config and that it is referencing C# 6
My Razor code:
#if(Session["Type"]?.ToString() == "Insurance") {
<text>policy of insurance</text>
} else if(Session["Type"]?.ToString() == "Warranty") {
<text>policy of warranty</text>
} else {
<text>protection policy</text>
}
Visual Studio explicitly flags this with an error,
Feature 'null propagating operator' is not available in C# 5. Please
use language version 6 or greater.
And Visual Studio is explicitly using C# 6:
When I try to run the page itself, I get an error:
CS1525: Invalid expression term '.'
which shows that it is explicitly going after the period following the question mark.
This project was explicitly started as a C# 6 project, and I am quite confused as to why it is derping back to C#5.
Another strange issue: this is working just fine both in debug as well as on my local test setup (I publish to the filesystem, view using local IIS), but when I upload to the server (which has many, many other C#6 sites) it craps out. This is the first razor-side quirk I have ever run across that actually throws an error this badly.
I was having a similar problem and found that I was missing the following from my Web.config file:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.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=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
I am deploying an ASP.NET MVC 4 application on IIS 7.5 on a Windows 2008 R2 machine.
The app works alright locally in the Visual Studio Web development server.
But when deployed, I get a 504 http status code.
The app runs in a custom application pool under the ApplicationPoolIdentity identity and in Integrated mode. The app pool is enabled to run both 32-bit and 64-bit applications and targets v4 of the .NET framework.
The app assemblies were build targeting "Any CPU".
When I deploy the application and attempt to access it, in addition to receiving the 504 Http status code, I also see this in the event viewer.
Event Data
HRESULT 0x8007000d
PhysicalPath \\?\C:\Windows\Microsoft.NET\Framework\v4.0.30319\CONFIG\web.config
Type 3
Message Unrecognized element 'providerOption'
LineNumber 53
PreviousLine <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
ErrorLine <providerOption name="CompilerVersion" value="v4.0"/>
NextLine <providerOption name="WarnAsError" value="false"/>
The above configuration pertains to CodeDOM, a set of classes in the System.CodeDom namespace in the System.dll assembly that ASP.NET uses to generate our "code behind" classes.
The CodeDOM configuration has changed from v2 of the .NET framework to v3.5.
I missed the part where the above error gives me the path of the web.config it is complaining about. The path is C:\Windows\Microsoft.NET\Framework\v4.0.30319\CONFIG\web.config and that file did have this <providerOption> element.
I commented that out. This error is now gone.
However, I still have other issues to deal with but this one goes away. So, anyone else in the future who faces this error might use this answer as help.
I'm working on a web site project on vb.net - asp.net 4 - visual studio 2010.
I need to implement a part of code that is used only when debug compilation is chosen within visual studio, e.g.:
' do something
#if DEBUGCONST
' debug mode! do something else
#end if
' proceed as usual..
Unfortunately this is not a web application project, therefore it doesn't come with a complete "property page" (where you can change compilers constant easily).
Googling for an answer, I found:
http://msdn.microsoft.com/en-us/library/a15ebt6c%28v=vs.100%29.aspx
..and I changed my web.config in this way:
<system.codedom>
<compilers>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" compilerOptions="/define:DEBUGCONST"></compiler>
</compilers>
</system.codedom>
Unfortunately, even if it compiles fine, the DEBUGCONST is never defined and the "debug code" is never executed.
Is there something I'm missing?
Thank you in advance for any help!
I have my gui which has this in its webconfig:
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
**<providerOption name="CompilerVersion" value="v3.5"/>**
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
Now when i go in the IIS and within the website properties select the asp.net version of v2.0.50727 (as i can see no higher version).. everything works fine
but now when i use another server of win 2003 i get an error
Configuration Error
Description: An error occurred during the processing of a
configuration file required to service this request. Please review the
specific error details below and modify your configuration file
appropriately.
Parser Error Message: Child nodes not allowed.
at this line:
i saw some answers which said that the server must not have v3.5... but i have selected v2.0.50727 so why do i need v3.5, also then how did it work in the previous server..
Please help..
thanks
As far as ASP.Net is concerned, 3.5 is mostly just a set of extensions for the 2.0 runtime. You still use a .Net 2.0 App Pool to run web apps built with .Net 3.5. However, you do need to make sure that .Net 3.5 is installed on the server, or the extensions won't be available.