_Imports.razor referencing

I have put a lot of commonly required injections into my app’s Imports.razor file, e.g.

@inject UserSession userSession

If I look at the output from Radzen Blazor for Visual Studio, I get a large number of messages like this:

C:\Software Projects\Tbi\Tbi.App\Components\Pages\SupportArea\ImportFromOldTB.razor.cs(3854,52): error CS0103: The name 'userSession' does not exist in the current context

The app will run, but it makes finding any “real” issues so much slower. Am I doing something wrong in using Imports in this way?

Cheers

Reg

Hi @SolutionJ,

We could not reproduce the design-time errors with a similar setup, so we need a bit more info:

  • Which _Imports.razor contains the @inject? Is there another _Imports.razor in a subfolder of the failing page?
  • Is ImportFromOldTB.razor a linked file or does it live outside the project folder?
  • Target framework and Radzen Blazor for Visual Studio version?
  • Do the errors appear only for pages with a .razor.cs file, and do they show up on load or after editing?

A minimal solution that reproduces the problem would help most.

Hi,

Which *Imports.razor file: It sits in folder C:\Software Projects\Tbi\Tbi.App\Components

There is no* Imports.razor file in any subfolder. There is another such file in a different project of the solution.

ImportFromOldTB.razor is in the same project, located in C:\Software Projects\Tbi\Tbi.App\Components\Pages\SupportArea

Target framework is 10.0, VS Community 18.9.2, Radzen 11.2.8

All errors listed are in .razor.cs files.

My solution has 4 projects, the errors are occuring in the two that have pages.

I can provide the full solution if that would help…

Can you also show me a screenshot where you see this error?

I can provide the full solution if that would help…

This would help a lot. You can share it with info@radzen.com after uploading it to some cloud storage (onedrive, google drive etc). Otherwise our mail server could reject it.

Hi,

Ok, I have done that. The text file includes all the messages I see when I open any page…

cheers

Reg

Thank you for the solution and the output. The errors come from a design-time compilation in which the Razor source generator produced nothing, which is why only the .razor.cs files report CS0103/CS0115 while your real build works. This usually means the design-time build picked a different .NET SDK than Visual Studio. Two quick things would confirm it:

  1. Open a command prompt in C:\Software Projects\Tbi and paste the output of:
    dotnet --list-sdks
    dotnet --version

  2. Create a file named global.json next to Tbi.sln with this content, restart Visual Studio and open a page in the Radzen designer:
    {
    "sdk": {
    "version": "10.0.400"
    }
    }
    Tell us whether the errors are gone.

Hi,

Thanks for getting back to me. Both commands you suggested I run returned 10.4.400. I created the json file as suggested, restarted VS, and opened a page in my app, but I’m afraid the errors are still there; loads of “no suitable method found to override”, loads of “does not exist in the current context”

Hi @SolutionJ,

Can you please paste the full output of running dotnet --info? We still haven't found the exact cause of this issue on your system and this could help.

Something else popped out. There is a chance you are using an old version of Radzen Blazor for Visual Studio. There were known issues with .NET SDK 10.0.400 which are addressed in latest versions. The current version is 1.44.0

.NET SDK:
Version: 10.0.400
Commit: 14fbf8d527
Workload version: 10.0.400-manifests.b0ae88bd
MSBuild version: 18.9.6+14fbf8d52

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26200
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.400\

.NET workloads installed:
[wasm-tools-net9]
Installation Source: VS 18.9.12120.119
Manifest Version: 10.0.111/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.workload.mono.toolchain.net9\10.0.111\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: VS 18.9.12120.119
Manifest Version: 10.0.20/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maui\10.0.20\WorkloadManifest.json
Install Type: Msi

[wasm-tools]
Installation Source: VS 18.9.12120.119
Manifest Version: 10.0.111/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.workload.mono.toolchain.current\10.0.111\WorkloadManifest.json
Install Type: Msi

[maccatalyst]
Installation Source: VS 18.9.12120.119
Manifest Version: 26.5.10301/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maccatalyst\26.5.10301\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: VS 18.9.12120.119
Manifest Version: 26.5.10301/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.ios\26.5.10301\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 18.9.12120.119
Manifest Version: 36.1.69/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.android\36.1.69\WorkloadManifest.json
Install Type: Msi

Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.11
Architecture: x64
Commit: e2f47b0110

.NET SDKs installed:
10.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 9.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.11 [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:
DOTNET_CLI_UI_LANGUAGE [en-US]
DOTNET_GCHeapCount [2]
DOTNET_GCNoAffinitize [1]
DOTNET_MULTILEVEL_LOOKUP [0]
DOTNET_TC_CallCountThreshold [1000]
DOTNET_ThreadPool_UnfairSemaphoreSpinLimit [0]
DOTNET_gcConcurrent [0]
Detected COMPlus_* environment variable(s). Consider transitioning to DOTNET_* equivalent.

global.json file:
C:\Software Projects\Tbi\global.json

Re the version, my mind’s gone blank. I can see no project reference for Radzen Blazor for Visual Studio at all…?

However, having updated Radzen Blazor Studio, and opened my app in that, the errors have disappeared.

In Visual Studio, though, the errors are still there. Can you please remind me how I would upgrade Radzen Blazor for Visualt Studio?

Open the Extensions / Manage extensions menu in Visual Studio and then switch to the Installed tab. You should see a notification to update Radzen Blazor for Visual Studio.

Ah, thanks for that. Indeed, that has solved the problem.

Much obliged for the help :grinning_face:

Actually, one more thing. With all those errors gone, I can now see a genuine set of results. I know - because I’ve asked before - that you cannot provide any further detail of an error like the one I’ve pasted below, but from your experience, what sort of things might I look for to explain it?

Opening project C:\Software Projects\Tbi\Tbi.sln
Finished building C:\Software Projects\Tbi\Tbi.Common\Tbi.Common.csproj
Finished building C:\Software Projects\Tbi\Tbi.Services\Tbi.Services.csproj
System.ApplicationException: System.NullReferenceException: Object reference not set to an instance of an object.
at Radzen.Server.ProjectServer.FindDefaultLayout() in D:\a\radzen-next\radzen-next\Radzen.Server\ProjectServer.cs:line 1099
at Radzen.Server.ProjectServer.GetLayout(Type page) in D:\a\radzen-next\radzen-next\Radzen.Server\ProjectServer.cs:line 1138
at Radzen.Server.ProjectServer.Render(String fileName, String source, Boolean renderLayout) in D:\a\radzen-next\radzen-next\Radzen.Server\ProjectServer.cs:line 1192
at Radzen.Server.ProgramController.Render(RenderRequest request) in D:\a\radzen-next\radzen-next\Radzen.Server\ProgramController.cs:line 603
at Radzen.VisualStudio.HttpResponseMessageExtensions.d__1.MoveNext() in D:\a\radzen-next\radzen-next\Radzen.VisualStudio.Xaml\HttpResponseMessageExtensions.cs:line 30
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Radzen.VisualStudio.Server.d__80.MoveNext() in D:\a\radzen-next\radzen-next\Radzen.VisualStudio.Xaml\Server.cs:line 912
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Radzen.VisualStudio.Editor.d__90.MoveNext() in D:\a\radzen-next\radzen-next\Radzen.VisualStudio.Xaml\Editor.xaml.cs:line 503
System.ApplicationException: System.NullReferenceException: Object reference not set to an instance of an object.
at Radzen.Server.ProjectServer.FindDefaultLayout() in D:\a\radzen-next\radzen-next\Radzen.Server\ProjectServer.cs:line 1099
at Radzen.Server.ProjectServer.GetLayout(Type page) in D:\a\radzen-next\radzen-next\Radzen.Server\ProjectServer.cs:line 1138
at Radzen.Server.ProjectServer.Render(String fileName, String source, Boolean renderLayout) in D:\a\radzen-next\radzen-next\Radzen.Server\ProjectServer.cs:line 1192
at Radzen.Server.ProgramController.Render(RenderRequest request) in D:\a\radzen-next\radzen-next\Radzen.Server\ProgramController.cs:line 603
at Radzen.VisualStudio.HttpResponseMessageExtensions.d__1.MoveNext() in D:\a\radzen-next\radzen-next\Radzen.VisualStudio.Xaml\HttpResponseMessageExtensions.cs:line 30
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Radzen.VisualStudio.Server.d__80.MoveNext() in D:\a\radzen-next\radzen-next\Radzen.VisualStudio.Xaml\Server.cs:line 912
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Radzen.VisualStudio.Editor.d__90.MoveNext() in D:\a\radzen-next\radzen-next\Radzen.VisualStudio.Xaml\Editor.xaml.cs:line 503
Finished building C:\Software Projects\Tbi\Tbi.App\Tbi.App.csproj
Finished building C:\Software Projects\Tbi\Tbi.LoginPortal\Tbi.LoginPortal.csproj

Hi @SolutionJ,

This is a known issue that will be addressed with the next release today or early tomorrow.