Context(?) for razor and codebehind files break at random occasions
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
Rather frequently the context breaks in razor components and the codebehind making it impossible to work on a project.
Most references to codebehind member or other components as well as inherited member are flagged as errors.
This also applies to first party content like the various input components or when inheriting from `ComponentBase`.
The project is still build and executable, but building, rebuilding or cleaning doesn't resolve the issue.
There is a way to temporarily "fix" the issue:
1. Close your IDE
2. Delete the `obj` and `bin` directory that is located in the project that isn't working
3. Start your IDE and build the project
This doesn't work all of the time and I have to repeat these steps multiple times.
### Expected Behavior
The IDE should be aware of the context for components like everyone expects it without breaking and needing to manually fix it like described in the **Anything else?** section.
### Steps To Reproduce
I can't reproduce the issue.
It happens at seemingly random situations like restarting visual studio or opening the project for the first time on the next day.
It seems to be more likely to happen, if you use `@code` sections in a razor file.
### Exceptions (if any)
_No response_
### .NET Version
8.0.204
### Anything else?
> [!NOTE]
> I'm a junior developer and I might have used weird descriptions and words. Please bear with me, I haven't worked in the .NET ecosystem during my [Ausbildung](https://korea.ahk.de/en/ausbildung/about-ausbildung/what-is-ausbildung) and just got my first .NET job!
> [!NOTE]
> When I am talking about "Context" I don't really know how to name it. Initially I wrote "Intellisense" everywhere where "context" is written, but I recently had to start using ReSharper and I still have the same issues with it. If I understand it correctly ReSharper replaces Intellisense in VS and therefore it can't be an issue related to Intellisense, right?
I use Visual Studio 22 (17.9.6)
I have created a [reddit post](https://www.reddit.com/r/Blazor/comments/1gweghf/is_this_vs2_issue_working_better_with_rider/) when my team asked if anyone wants to use rider and according to the answers it seems to happen in Rider too, but I cant confirm that myself.
Output for `dotnet --info`:
```
.NET SDK:
Version: 8.0.204
Commit: c338c7548c
Workload version: 8.0.200-manifests.7d36c14f
Laufzeitumgebung:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.204\
Installierte .NET-Workloads:
[maui-windows]
Installationsquelle: VS 17.9.34728.123
Manifestversion: 8.0.7/8.0.100
Manifestpfad: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.7\WorkloadManifest.json
Installationstyp: Msi
[maccatalyst]
Installationsquelle: VS 17.9.34728.123
Manifestversion: 17.2.8004/8.0.100
Manifestpfad: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.2.8004\WorkloadManifest.json
Installationstyp: Msi
[ios]
Installationsquelle: VS 17.9.34728.123
Manifestversion: 17.2.8004/8.0.100
Manifestpfad: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.2.8004\WorkloadManifest.json
Installationstyp: Msi
[android]
Installationsquelle: VS 17.9.34728.123
Manifestversion: 34.0.52/8.0.100
Manifestpfad: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.52\WorkloadManifest.json
Installationstyp: Msi
Host:
Version: 8.0.4
Architecture: x64
Commit: 2d7eea2529
.NET SDKs installed:
8.0.102 [C:\Program Files\dotnet\sdk]
8.0.204 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
```
If this turns out to be an duplicate, then I am sorry. I assumed this issue is known when reading about it on forums, but I don't seem to find an issue describing this. Maybe I haven't found anything because English isn't my first language and as mentioned above I don't have much experience in the ecosystem. I might have phrased it wrong while searching.
Contributor guide
Assessment
This issue has not been assessed yet.