I have two identical ASP.Net 4.6 MVC project, project 1 is using roslyn complier within the site which is working fine.
c:\windows\system32\inetsrv>C:\Websites1\bin\roslyn\csc.exe Microsoft (R) Visual C# Compiler version 1.2.0.60325
With the second project I'm getting the error below, it's using the complier from .Net framework.
c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" Microsoft (R) Visual C# Compiler version 4.6.1590.0
Line 6: @if (!Model?.Item?.IsDerived(Templates.PageMetadata.ID) ?? true)
Line 7: {
Line 8: return;
c:\Website2\Views\metadata.cshtml(6,17): error CS1525: Invalid expression term '.'
c:\Website2\Views\metadata.cshtml(6,18): error CS1003: Syntax error, ':' expected
c:\Website2\Views\metadata.cshtml(6,23): error CS1525: Invalid expression term '.'
c:\Website2\Views\metadata.cshtml(6,24): error CS1003: Syntax error, ':' expected
c:\Website2\Views\metadata.cshtml(6,68): error CS1002: ; expected
c:\Website2\Views\metadata.cshtml(6,68): error CS1525: Invalid expression term ')'
c:\Website2\Views\metadata.cshtml(6,69): error CS1002: ; expected
I've used Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform on both project.
My question is why is the second project not using roslyn complier and is there a way to force it to use the roslyn complier within the site?
I've also tried Microsoft.Net.Compilers nuget package.
Compiler Error Message: CS1525: Invalid expression term ';' Thanks for the post. This error is a common error in the mvc view, that indicates some syntax or expression mistake when you coding in view template. Without any code, I cannot know which code caused this type error. I suggest you check below solutions in below similar issues.
Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML. It's just that ASP.NET MVC has implemented a view engine that allows us to use Razor inside of an MVC application to produce HTML.
ASP.NET MVC - Razor. In this chapter, we will look at the Razor view engine in ASP.NET MVC applications and some of the reasons why Razor exists. Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language.
If you're still having issues, something else could be wrong with the surrounding code in your Razor page, or your project isn't referencing the proper assemblies? Try running the same code inside a new, blank ASP.NET project. Thank you.
Got it working now after adding the following to the web.config
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /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.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
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