Razor errors within vscode insiders not vscode
- Dominant language
- TypeScript
- Stars
- 3.1k
- Forks
- 737
- Avg merge
- 17h 56m
- Merged PRs (30d)
- 21
Description
## Update ##
The fix was to serialize the data into a JSON string and then parse it in the JavaScript. So I think VSCode Insiders was correct to give me the errors in the problems tab and perhaps the normal VSCode should have done the same.
Basically user error on my part. I'll leave the issue open in case there is anything that needs to be done but I wouldn't mind if it was closed.
```cshtml
@{
// serialize into a JSON string to be parsed later by javascript
var componentsJson = Html.Raw(Json.Serialize(Model.Products.ToDictionary(x => x.Id, x => x.Components.Select(c => new { c.Id, c.Name, c.HasPrintedPages, c.PrintedPagesDivisor }))));
}
@section Scripts {
function bindProductSelectEvent() {
// other code
// this now works:
var components = JSON.parse('@componentsJson');
// other code
}
}
```
## Issue Description ##
I originally logged this issue here https://github.com/microsoft/vscode/issues/184146
The bug is that within a .cshtml page some c# is mixed within a JavaScript function and that c# line shows errors and red line squigglys and shows as errors within the visual studio code insiders problems tab.
This is only with vscode-insiders not normal vscode.
On vscode nothing shows in the problems tab and no red squiggly underlines etc
The bug appears on two computers I work on.
I created the [initial issue](https://github.com/microsoft/vscode/issues/184146) on the first and I'm creating this issue on the second.
Both have the same version of visual studio code and visual studio code insiders and both have the same version of the c# extension. All extensions are up to date and reloaded.
The line of code causing the issue is :
```razor
var components = @Html.Raw(Json.Serialize(Model.Products.ToDictionary(x => x.Id, x => x.Components.Select(c => new { c.Id, c.Name, c.HasPrintedPages, c.PrintedPagesDivisor }))));
```
This code is within a larger razor pages script block within a javascript function
```razor
@section Scripts {
function bindProductSelectEvent() {
// other code
// the issue:
var components = @Html.Raw(Json.Serialize(Model.Products.ToDictionary(x => x.Id, x => x.Components.Select(c => new { c.Id, c.Name, c.HasPrintedPages, c.PrintedPagesDivisor }))));
// other code
}
}
```
Here are the messages in the problems tab:
```bash
Decorators are not valid here.
[{
"resource": "/Users/solrevdev/Dropbox/Projects/solution/project/src/web/Pages/Quotes/Create.cshtml",
"owner": "_generated_diagnostic_collection_name_#2",
"severity": 8,
"message": "Decorators are not valid here.",
"source": "javascript",
"startLineNumber": 174,
"startColumn": 38,
"endLineNumber": 174,
"endColumn": 198
}]
',' expected.
[{
"resource": "/Users/solrevdev/Dropbox/Projects/solution/project/src/web/Pages/Quotes/Create.cshtml",
"owner": "_generated_diagnostic_collection_name_#2",
"severity": 8,
"message": "',' expected.",
"source": "javascript",
"startLineNumber": 174,
"startColumn": 139,
"endLineNumber": 174,
"endColumn": 140
}]
',' expected.
[{
"resource": "/Users/solrevdev/Dropbox/Projects/solution/project/src/web/Pages/Quotes/Create.cshtml",
"owner": "_generated_diagnostic_collection_name_#2",
"severity": 8,
"message": "',' expected.",
"source": "javascript",
"startLineNumber": 174,
"startColumn": 145,
"endLineNumber": 174,
"endColumn": 146
}]
',' expected.
[{
"resource": "/Users/solrevdev/Dropbox/Projects/solution/project/src/web/Pages/Quotes/Create.cshtml",
"owner": "_generated_diagnostic_collection_name_#2",
"severity": 8,
"message": "',' expected.",
"source": "javascript",
"startLineNumber": 174,
"startColumn": 153,
"endLineNumber": 174,
"endColumn": 154
}]
',' expected.
[{
"resource": "/Users/solrevdev/Dropbox/Projects/solution/project/src/web/Pages/Quotes/Create.cshtml",
"owner": "_generated_diagnostic_collection_name_#2",
"severity": 8,
"message": "',' expected.",
"source": "javascript",
"startLineNumber": 174,
"startColumn": 172,
"endLineNumber": 174,
"endColumn": 173
}]
Expression expected.
[{
"resource": "/Users/solrevdev/Dropbox/Projects/solution/project/src/web/Pages/Quotes/Create.cshtml",
"owner": "_generated_diagnostic_collection_name_#2",
"severity": 8,
"message": "Expression expected.",
"source": "javascript",
"startLineNumber": 174,
"startColumn": 198,
"endLineNumber": 174,
"endColumn": 198
}]
```
### Screenshot ###
Details

### OmniSharp log ###
Post the output from Output-->OmniSharp log here
```bash
Starting OmniSharp server at 03/06/2023, 09:42:52
Target: /Users/solrevdev/Dropbox/Projects/solution/project/psys.sln
OmniSharp server started with .NET 7.0.302
.
Path: /Users/solrevdev/.vscode-insiders/extensions/ms-dotnettools.csharp-1.25.8-darwin-x64/.omnisharp/1.39.7-beta.18-net6.0/OmniSharp.dll
PID: 62003
[info]: OmniSharp.Stdio.Host
Starting OmniSharp on Unknown 0.0 (Unknown)
[info]: OmniSharp.Services.DotNetCliService
Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
Using the 'dotnet' on the PATH.
[info]: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 1 MSBuild instance(s)
1: .NET Core SDK 7.0.302 17.6.1 - "/usr/local/share/dotnet/sdk/7.0.302/"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: .NET Core SDK 7.0.302 17.6.1 - "/usr/local/share/dotnet/sdk/7.0.302/"
[info]: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in '/Users/solrevdev/Dropbox/Projects/solution/project'.
[info]: OmniSharp.Cake.CakeProjectSystem
Did not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
Detecting projects in '/Users/solrevdev/Dropbox/Projects/solution/project/psys.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
Queue project update for '/Users/solrevdev/Dropbox/Projects/solution/project/src/web/web.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in '/Users/solrevdev/Dropbox/Projects/solution/project'.
[info]: OmniSharp.Script.ScriptProjectSystem
Did not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
Configuration finished.
[info]: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location '/Users/solrevdev/Dropbox/Projects/solution/project' on host 61370.
[info]: OmniSharp.MSBuild.ProjectManager
Loading project: /Users/solrevdev/Dropbox/Projects/solution/project/src/web/web.csproj
[info]: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file '/Users/solrevdev/Dropbox/Projects/solution/project/src/web/web.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
Adding project '/Users/solrevdev/Dropbox/Projects/solution/project/src/web/web.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
Update project: web
[info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
Solution initialized -> queue all documents for code analysis. Initial document count: 106.
```
### C# log ###
C# Log
```bash
Getting latest OmniSharp version information
Downloading package 'Latest OmniSharp Version Information' (1 KB).................... Done!
Installing OmniSharp Version = 1.39.7-beta.18...
Platform: darwin, x86_64
Downloading package 'OmniSharp for OSX (.NET 6 / x64), Version = 1.39.7-beta.18' (45263 KB).................... Done!
Installing package 'OmniSharp for OSX (.NET 6 / x64), Version = 1.39.7-beta.18'
Finished
```
## Environment information ##
**VSCode version**: 1.79.0-insider
**C# Extension**: 1.25.8
Mono Information
OmniSharp using mono: 6.12.0
Dotnet Information
.NET SDK:
Version: 7.0.302
Commit: 990cf98a27
Runtime Environment:
OS Name: Mac OS X
OS Version: 12.6
OS Platform: Darwin
RID: osx.12-x64
Base Path: /usr/local/share/dotnet/sdk/7.0.302/
Host:
Version: 7.0.5
Architecture: x64
Commit: 8042d61b17
.NET SDKs installed:
7.0.302 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.25 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Visual Studio Code Extensions
|Extension|Author|Version|
|---|---|---|
|add-reference|adrianwilczynski|1.0.2|
|asp-net-core-switcher|adrianwilczynski|2.0.2|
|aspnet-helper|schneiderpat|0.6.4|
|atlascode|atlassian|3.0.3|
|auto-close-tag|formulahendry|0.5.14|
|auto-rename-tag|formulahendry|0.1.10|
|auto-using|Fudge|0.7.15|
|aws-toolkit-vscode|amazonwebservices|1.76.0|
|bash-debug|rogalmic|0.3.9|
|bash-ide-vscode|mads-hartmann|1.37.0|
|better-cpp-syntax|jeff-hykin|1.17.2|
|blazor-snippet-pack|adrianwilczynski|2.6.1|
|blazorsnippets|ScottSauber|1.5.1|
|blazorwasm-companion|ms-dotnettools|1.1.4|
|cake-vscode|cake-build|2.1.1|
|cmake|twxs|0.0.17|
|cmake-tools|ms-vscode|1.14.31|
|code-spell-checker|streetsidesoftware|2.20.4|
|copilot-chat|GitHub|0.1.2023060101|
|copilot-labs|GitHub|0.14.884|
|copilot-nightly|GitHub|1.88.136|
|cpptools-extension-pack|ms-vscode|1.3.0|
|cpptools-themes|ms-vscode|2.0.0|
|csharp|ms-dotnettools|1.25.8|
|csharp-extensions|raits|0.0.6|
|csharp-interpolated-string-converter|corylulu|0.1.6|
|csharp-to-typescript|adrianwilczynski|1.12.1|
|csharpextensions|kreativ-software|1.7.3|
|csharpier-vscode|csharpier|1.3.6|
|docs-markdown|docsmsft|1.0.1|
|docs-yaml|docsmsft|1.0.0|
|dotenv|mikestead|1.0.1|
|dotnet|leo-labs|1.3.0|
|dotnet-interactive-vscode|ms-dotnettools|1.0.4258030|
|dotnet-test-explorer|formulahendry|0.7.8|
|doxdocgen|cschlosser|1.4.0|
|EditorConfig|EditorConfig|0.16.4|
|editorconfiggenerator|nepaul|0.2.1|
|explorer-exclude|PeterSchmalfeldt|1.3.2|
|gc-excelviewer|GrapeCity|4.2.57|
|gistfs|vsls-contrib|0.4.1|
|git-graph|mhutchie|1.30.0|
|github-markdown-preview|bierner|0.3.0|
|github-vscode-theme|GitHub|6.3.4|
|gitignore|codezombiech|0.9.0|
|gitlens|eamodio|13.6.0|
|html-css-class-completion|Zignd|1.20.0|
|intellicode-api-usage-examples|VisualStudioExptTeam|0.2.7|
|isort|ms-python|2022.8.0|
|jupyter|ms-toolsai|2023.5.1001541100|
|jupyter-keymap|ms-toolsai|1.1.1|
|jupyter-renderers|ms-toolsai|1.0.15|
|libman|adrianwilczynski|1.0.1|
|live-sass|glenn2223|6.0.5|
|live-server|ms-vscode|0.4.8|
|LogFileHighlighter|emilast|2.16.0|
|markdown-all-in-one|yzhang|3.5.1|
|markdown-checkbox|bierner|0.4.0|
|markdown-emoji|bierner|0.3.0|
|markdown-footnotes|bierner|0.1.1|
|markdown-mermaid|bierner|1.18.1|
|markdown-pdf|yzane|1.4.4|
|markdown-preview-github-styles|bierner|2.0.2|
|markdown-yaml-preamble|bierner|0.1.0|
|mono-debug|ms-vscode|0.16.3|
|msbuild-project-tools|tintoy|0.4.9|
|namespace|adrianwilczynski|1.1.2|
|netcore-editorconfiggenerator|doggy8088|0.1.1|
|netcore-extension-pack|doggy8088|1.8.0|
|netcore-snippets|doggy8088|6.0.3|
|nuget-reverse-package-search|jesschadwick|0.1.68|
|nugetpackagemanagergui|aliasadidev|2.0.6|
|partial-diff|ryu1kn|1.4.3|
|path-intellisense|christian-kohler|2.8.4|
|pdf|tomoki1207|1.2.2|
|powershell|ms-vscode|2023.5.0|
|prettier-vscode|esbenp|9.13.0|
|preview-pdf|analytic-signal|1.0.0|
|pylint|ms-python|2023.4.0|
|python|ms-python|2023.8.0|
|quicktype-refresh|doggy8088|1.0.2|
|quokka-vscode|WallabyJs|1.0.542|
|rainbow-csv|mechatroner|3.7.0|
|razor-snippets-for-asp-net-core|aledev29|0.0.3|
|remote-containers|ms-vscode-remote|0.294.0|
|remote-explorer|ms-vscode|0.4.0|
|remote-server|ms-vscode|1.1.0|
|remote-ssh|ms-vscode-remote|0.102.0|
|remote-ssh-edit|ms-vscode-remote|0.86.0|
|remote-wsl|ms-vscode-remote|0.79.2|
|rest-client|humao|0.25.1|
|roslynator|josefpihrt-vscode|4.3.0|
|shell-format|foxundermoon|7.2.5|
|sort-lines|Tyriar|1.10.1|
|split-html-attributes|dannyconnell|1.0.10|
|sqlite-viewer|qwtel|0.3.10|
|sqltools|mtxr|0.27.1|
|supersharp|craigthomas|0.1.4|
|svg|jock|1.5.2|
|swagger-viewer|Arjun|3.1.2|
|t4-support|zbecknell|0.7.0|
|TextTemplating|jacknq|0.17.0|
|transformer|dakara|1.12.1|
|user-secrets|adrianwilczynski|2.0.1|
|vagrant|bbenoist|0.5.0|
|vetur|octref|0.37.3|
|visual-nuget|fullstackspider|0.2.1|
|volar|Vue|1.6.4|
|VS-code-vagrantfile|marcostazi|0.0.7|
|vscode-commitizen|KnisterPeter|1.1.0|
|vscode-coverage-gutters|ryanluker|2.10.4|
|vscode-coverlet|urbanoanderson|1.1.5|
|vscode-css-peek|pranaygp|4.2.0|
|vscode-docker|ms-azuretools|1.25.1|
|vscode-dotnet-runtime|ms-dotnettools|1.6.0|
|vscode-drawio|hediet|1.6.6|
|vscode-edge-devtools|ms-edgedevtools|2.1.1|
|vscode-edit-csv|janisdd|0.7.6|
|vscode-eslint|dbaeumer|2.4.0|
|vscode-faker|deerawan|2.0.0|
|vscode-fileutils|sleistner|3.10.1|
|vscode-github-actions|github|0.25.7|
|vscode-html-css|ecmel|1.13.1|
|vscode-icons|vscode-icons-team|12.4.0|
|vscode-jupyter-cell-tags|ms-toolsai|0.1.8|
|vscode-jupyter-slideshow|ms-toolsai|0.1.5|
|vscode-language-pack-en-GB|MS-CEINTL|1.54.1|
|vscode-mysql-client2|cweijan|6.4.8|
|vscode-nuget-gallery|patcx|0.0.24|
|vscode-nuget-package-manager|jmrog|1.1.6|
|vscode-nupkg|eridem|1.0.1|
|vscode-openapi|42Crunch|4.17.0|
|vscode-proto3|zxh404|0.5.5|
|vscode-pylance|ms-python|2023.5.50|
|vscode-remote-extensionpack|ms-vscode-remote|0.24.0|
|vscode-sort-json|richie5um2|1.20.0|
|vscode-surround|yatki|1.5.0|
|vscode-svgviewer|cssho|2.0.0|
|vscode-trello-viewer|Ho-Wan|0.6.0|
|vscode-typescript-vue-plugin|Vue|1.6.5|
|vscode-versionlens|pflannery|1.5.0|
|vscode-wakatime|WakaTime|24.0.10|
|vscode-yaml|redhat|1.13.0|
|vscodeintellicode|VisualStudioExptTeam|1.2.30|
|wrapSelection|konstantin|0.10.0|
|xml|DotJoshJohnson|2.5.1|;
## Environment data
`dotnet --info` output:
```bash
dotnet --info
.NET SDK:
Version: 7.0.302
Commit: 990cf98a27
Runtime Environment:
OS Name: Mac OS X
OS Version: 12.6
OS Platform: Darwin
RID: osx.12-x64
Base Path: /usr/local/share/dotnet/sdk/7.0.302/
Host:
Version: 7.0.5
Architecture: x64
Commit: 8042d61b17
.NET SDKs installed:
7.0.302 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.25 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
/Users/solrevdev/Dropbox/Projects/solution/project/global.json
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
```
VS Code version:
```bash
Version: 1.79.0-insider (Universal)
Commit: 506cd5056d875ccdbea2e9a41ba7b9f19103d599
Date: 2023-06-02T20:40:50.615Z
Electron: 22.5.5
Chrome: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin x64 21.6.0
```
C# Extension version:
```bash
v1.25.8
```
## Additional Info
This bug appears on my two dev machines macmini 2020 m1 and a macmini 2014 intel
This is my macmini 2014 intel. The other's details is in the closed issue:
https://github.com/microsoft/vscode/issues/184146
```bash
OS: macOS 12.6.6 21G646 x86_64
Host: Macmini7,1
Kernel: 21.6.0
Uptime: 15 hours, 40 mins
Packages: 353 (brew)
Shell: zsh 5.8.1
Resolution: 1920x1080
DE: Aqua
WM: Quartz Compositor
WM Theme: Blue (Light)
Terminal: Apple_Terminal
Terminal Font: CaskaydiaCoveNerdFontComplete-Regular
CPU: Intel i5-4278U (4) @ 2.60GHz
GPU: Intel Iris
Memory: 9737MiB / 16384MiB
```
Contributor guide
Assessment
This issue has not been assessed yet.