![](/img/trans.png)
[英]How to fix "The type of namespace name "Fault" does not exist in the namespace" for gRPC and C#?
[英]How to fix 'The type name does not exist' error in C# while having the correct namespace and the directory
由於出現相同的錯誤結果,我在嘗試構建項目時遇到問題。 此錯誤指出:
The type 'Shared' (my guess the folder) does not exist in the type 'MyNameSpace'.
https://ibb.co/fDZ0Pyb-具有錯誤代碼和項目結構的IDE圖像。 這個圖片替代方案是由於我的代表不讓我發布圖片。
我嘗試尋找解決此問題的答案。 我嘗試過的所有方法(例如:排除該文件夾然后再將其添加回,刪除de .vs文件夾等)均未成功。
在Blazor中,_Imports.razor文件具有該應用程序中使用的所有文件。 在此文件中,我添加了以下using語句。
@using NeighborHub
@using NeighborHub.Shared
@using NeighborHub.Data
我認為由於該文件夾存在,因此不應彈出此錯誤。 如果我缺少任何東西,請幫忙。 如果可以將其識別為錯誤,我該如何解決此問題,或者應該在github上打開一個新的問題。
POST編輯https://ibb.co/sqGyw23-此圖像添加了有關IDE和錯誤的更多詳細信息。
除此之外,我正在使用不久前發布的.NET Core 3.0預覽版9。
導致錯誤的剃須刀頁面如下:
@page "/househubform"
@page "/househubform/{EditId:int}"
@using NeighborHub.Data
@inject Data.ApplicationDbContext db
@inject NavigationManager UriHelper
@attribute [Authorize(Roles = "admin")]
<div class="card">
<h3 class="card-header text-center">Add a New HouseHub</h3>
//Some Html code
@*--- Code Below ---*@
@code {
//Variables used to fill the form
Data.HouseHub houseHub = new Data.HouseHub();
private string varSurname { get; set; } = null;
private string varHouseNumber { get; set; } = null;
private int varHouseholdSize { get; set; } = 0;
private int FKId { get; set; } = 0;
//Drowdown list
private List<Data.NeighborHub> NeighborHub = new List<Data.NeighborHub>();
//Error Msg
public string Errmsg { get; set; }
//Parameters
[Parameter]
public int EditId { get; set; } = 0;
//On change select list update
private void SelectListUpdate(ChangeEventArgs Event)
{
FKId = Int32.Parse(Event.Value.ToString());
}
//Submit form to database
private async Task SubmitForm()
{
//Submit logic and validation
}
//Edit form to database
private async Task EditForm()
{
//Edit logic and validation
}
//Initializing logic using Async Task
protected override async Task OnInitializedAsync()
{
//If EditId is passed it will start filling the entity to edit
if (EditId != 0)
{
houseHub = await db.DbHouseHubs.FindAsync(EditId);
//The following will occur only if the entity is found
if (houseHub != null)
{
varSurname = houseHub.Surname;
varHouseNumber = houseHub.HouseNumber;
varHouseholdSize = houseHub.HouseholdSize;
FKId = houseHub.NeighborhubId;
NeighborHub = db.DbNeighborHubs.ToList();
}
//If the entity is not found it will set an error
else
{
Errmsg = "Could not find the entity. Add a new entry or cancel.";
EditId = 0;
NeighborHub = db.DbNeighborHubs.ToList();
}
}
//If set to 0 this will create a new entry
else
{
NeighborHub = db.DbNeighborHubs.ToList();
}
}
}
請注意錯誤消息狀態指出類型 Shared
不存在。 我可以看到兩個新手錯誤,它們可能在這里:-您使用@inject NeighborHub-聲明某些變量時忘記添加類型。
因此,我找到了錯誤,似乎是一個錯誤。
在_Imports.razor文件中,我具有以下內容:
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Rendering
@using Microsoft.AspNetCore.Components.RenderTree
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using NeighborHub
@using NeighborHub.Shared
@using NeighborHub.Data //Cause of the error
所以我繼續刪除
@using NeighborHub.Data
這似乎可以解決所有問題。 為什么? 我完全不確定為什么此@using Namespace.Data語句導致錯誤。
我遇到過同樣的問題。 我可以通過從名稱空間中刪除解決方案名稱來解決此問題。 例如。
@using NeghborHub.Data
至:
@使用數據
讓我知道這是否適合您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.