英文:
Maui Blazor - CS0029 when passing component @ref
问题
After updating Visual Studio to version 17.6.0, the following error occurred in my MAUI project:
> Error CS0029 Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to '<componentName>'
以下是我的代码:
@using UI.Components.Dialogs.InfoDialog
@using UI.Components.Dialogs.InputDialog
@using UI.Components.Dialogs.MessageDialog
@using UI.Components.Dialogs.SettingsDialog
@using UI.Components.Dialogs.ProcedureTypeSelectorDialog
@using UI.Services;
@inject DialogService dialogService
<InputDialog @ref="inputDialog" />
<InfoDialog @ref="infoDialog" />
<MessageDialog @ref="messageDialog" />
<SettingsDialog @ref="settingsDialog" />
<ProcedureTypeSelectorDialog @ref="procedureTypeSelectorDialog" />
@code {
InputDialog inputDialog { set => dialogService.RegisterDialog(value); }
InfoDialog infoDialog { set => dialogService.RegisterDialog(value); }
MessageDialog messageDialog { set => dialogService.RegisterDialog(value); }
SettingsDialog settingsDialog { set => dialogService.RegisterDialog(value); }
ProcedureTypeSelectorDialog procedureTypeSelectorDialog { set => dialogService.RegisterDialog(value); }
}
我已尝试以下操作:
- 将所有内容转移到代码后端
- 删除命名空间和组件名称的重复(实际上,我将组件从它们的文件夹中提取出来)
- 寻找将
ElementReference
转换或从中提取我的组件的方法(未找到相关信息) - 删除了 .vs、bin 和 obj 文件夹,并重新构建了项目
在更新 Visual Studio 之前(我使用的是版本 17.5),这段代码可以正常工作。更新后,尝试使用相同的代码运行时,出现了这个错误。提前感谢大家的帮助!
英文:
After updating Visual Studio to version 17.6.0, the following error occurred in my MAUI project:
> Error CS0029 Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to '<componentName>'
Here is my code:
@using UI.Components.Dialogs.InfoDialog
@using UI.Components.Dialogs.InputDialog
@using UI.Components.Dialogs.MessageDialog
@using UI.Components.Dialogs.SettingsDialog
@using UI.Components.Dialogs.ProcedureTypeSelectorDialog
@using UI.Services;
@inject DialogService dialogService
<InputDialog @ref="inputDialog" />
<InfoDialog @ref="infoDialog" />
<MessageDialog @ref="messageDialog" />
<SettingsDialog @ref="settingsDialog" />
<ProcedureTypeSelectorDialog @ref="procedureTypeSelectorDialog" />
@code {
InputDialog inputDialog { set => dialogService.RegisterDialog(value); }
InfoDialog infoDialog { set => dialogService.RegisterDialog(value); }
MessageDialog messageDialog { set => dialogService.RegisterDialog(value); }
SettingsDialog settingsDialog { set => dialogService.RegisterDialog(value); }
ProcedureTypeSelectorDialog procedureTypeSelectorDialog { set => dialogService.RegisterDialog(value); }
}
I have tried the following:
- Transfer everything to the codebehind
- Remove the duplication of the namespace and the name of the component (in fact, I pulled the components from their folders)
- I was looking for ways to convert
ElementReference
or extract my component from it (I didn't find anything like that) - Deleted folders .vs, bin, obj and rebuilt the project
Before updating Visual Studio (I was working on version 17.5), this code worked fine. After the update, when trying to run with the same code, I encountered this error. Thank you all in advance for your help!
答案1
得分: 1
这可能是在新版本的Visual Studio 17.6.0上出现的问题。我建议你在GitHub上报告它作为一个新问题,并报告一个与Visual Studio产品相关的问题以获取更多信息。
英文:
This might be an issue on the new version of Visual Studio 17.6.0. I recommend you to report it as a new issue on the GitHub and report a problem with the Visual Studio product for more information.
答案2
得分: 0
"Its reported on dotnet/AspNetCore.Docs
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论