gpt4 book ai didi

c# - g.i.cs 文件丢失,类不再包含 InitializeComponent 的定义

转载 作者:行者123 更新时间:2023-11-30 16:04:17 26 4
gpt4 key购买 nike

我一直在利用业余时间开发一个 UWP 项目,以熟悉 UWP、MVVM 和 Prism。该项目最初非常经典,没有使用 MVVM 和 Prism,我一直在努力将这 2 个纳入项目。我一直依赖https://msdn.microsoft.com/en-us/library/gg405484(v=pandp.40).aspx , https://msdn.microsoft.com/en-us/library/gg405494(v=pandp.40).aspxhttps://msdn.microsoft.com/en-us/library/ff921098(v=pandp.40).aspx努力解决它。

一些背景:我最初有一个从我的 Mainpage.xamlMainPage.xaml.cs 代码隐藏的直接函数调用,但是在转换为 MVVM 和一个单独的usercontrol,我删除了该函数调用,以便以后可以使用命令绑定(bind)。在我删除它之后,我在 GameRouletteView.g.i.cs 中的某个地方得到了一个错误,这是这个删除的函数调用的残余,g.i.cs 文件假设它仍然是绑定(bind)的。我重建了我的项目,那些 g.i.cs 文件显然被删除了。

我将以下行添加到我的用户控件 View 中,以便添加我的 ViewModel:

xmlns:gameRoulette="using:GameRoulette.DesignViewModels"
xmlns:prism="using:Prism.Windows.Mvvm"
d:DataContext="{d:DesignInstance gameRoulette:GameRouletteDesignViewModel, IsDesignTimeCreatable=True}"
prism:ViewModelLocator.AutoWireViewModel="True"

完整代码:

<UserControl
x:Class="GameRoulette.Views.GameRouletteView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:GameRoulette.Views"
xmlns:gameRoulette="using:GameRoulette.DesignViewModels"
xmlns:prism="using:Prism.Windows.Mvvm"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400"
d:DataContext="{d:DesignInstance gameRoulette:GameRouletteDesignViewModel, IsDesignTimeCreatable=True}"
prism:ViewModelLocator.AutoWireViewModel="True">
<Grid Background="White">
<Button x:Name="btnSelectGames" Content="Click here to select your games"
HorizontalAlignment="Left" Margin="110,50,0,0"
VerticalAlignment="Top" Height="40" Width="240"
Click="{Binding SelectCommand}"/>
<Button x:Name="btnChooseGame" Content=""
HorizontalAlignment="Left" Margin="110,150,0,0"
VerticalAlignment="Top" Width="240" Height="40"
Click="{Binding ChooseCommand}" IsEnabled="True"/>
<ProgressRing HorizontalAlignment="Left" Margin="200,100,0,0"
VerticalAlignment="Top" RenderTransformOrigin="1.05,1.983"
Height="45" Width="45" IsActive="True" Visibility="{Binding }"/>
<Image x:Name="imgFileIcon" HorizontalAlignment="Left"
Height="64" Margin="110,224,0,0"
VerticalAlignment="Top" Width="64" />
<TextBlock x:Name="lblFileName" HorizontalAlignment="Left"
Margin="179,224,0,0" TextWrapping="Wrap"
Text="" VerticalAlignment="Top" Width="171" Height="64"/>
</Grid>
</UserControl>

它给出了以下错误:

The name "GameRouletteDesignViewModel" does not exist in the namespace "using:GameRoulette.DesignViewModels".

我重建了项目,然后它为我的 3 个 .xaml 文件中的每一个都给出了以下错误:GameRouletteView、App.xamlMainPage.xaml:

'GameRouletteView' does not contain a definition for 'InitializeComponent' and no extension method 'InitializeComponent' accepting a first argument of type 'GameRouletteView' could be found (are you missing a using directive or an assembly reference?)

另外,当第一次打开项目时,我得到 Intellisense 错误:

[Failure] Could not find file 'C:\Users\username\Source\Repos\GameRoulette\GameRoulette\GameRoulette\obj\ARM\Debug\MainPage.g.i.cs'.
[Failure] Could not find file 'C:\Users\username\Source\Repos\GameRoulette\GameRoulette\GameRoulette\obj\ARM\Debug\Views\GameRouletteView.g.i.cs'.
[Failure] Could not find file 'C:\Users\username\Source\Repos\GameRoulette\GameRoulette\GameRoulette\obj\ARM\Debug\App.g.i.cs'.

我已经排除的事情:

  1. 我的命名空间是正确的;
  2. 我试过了https://stackoverflow.com/a/27260580/1770430 , 没用;
  3. 我已经删除了 bin、obj 文件夹和 .suo 文件,但没有修复它;
  4. 我已经关闭并重新打开解决方案,但没有修复它。
  5. 通过添加/修复/删除程序窗口修复 Visual Studio,无结果。

我用谷歌搜索了这个错误,但我真的找不到任何我还没有尝试过的东西。

我还注意到我的 NuGet 包丢失了,而且我的包管理器控制台不再识别 NuGet。我也收到此错误:

Microsoft.NETCore.Portable.Compatibility 1.0.0 provides a compile-time reference assembly for mscorlib on UAP,Version=v10.0, but there is no run-time assembly compatible with win10.

我感觉所有这些问题都是相关的,但我无法弄清楚它有什么问题。如上所述,Google 并没有真正提供太多帮助,而且它提供的帮助也不起作用。

我正在使用带有更新 1 的 Visual Studio 2015 社区版。可以在 https://github.com/nzall/GameRoulette 找到该项目。 .

最佳答案

我已经为这个问题苦苦挣扎了几天,而且,至少就我而言,我很确定它取决于我在我的 xaml 代码中无意中引入的一些细微错误。或者,更好的是,不完全是错误,而是我们目标平台的 xaml 版本不支持的东西。在这种情况下,xaml 解析器会失败,并且不会按预期生成 g.i.cs 文件(其中包含由解析器生成的部分页面和应用程序类,包括 InitializeComponent 方法)。我为什么这么认为?

  1. 一开始我以为是Visual Studio的问题,所以清了组件缓存,然后把C:\Users{myname}\AppData\Local\Microsoft\VisualStudio\14.0这个文件夹彻底删除了,然后卸载了,然后从头开始重新安装VS。我仍然有错误。
  2. 当我尝试构建解决方案时,在错误窗口中我只看到一个通用的“对象引用未设置到对象的实例”,但是如果我检查构建输出窗口,我可以看到问题是有效的与 xaml 解析器相关(准确地说:Xaml 内部错误 WMC9999)。
  3. 互联网上关于这个问题的内容不多,一部分是针对面临相同情况的人的一些帮助请求,但我设法找到的仅有的两个页面确实提供了解决方案,都将这个问题与使用xaml 中(不同的)不支持的功能(语法正确但目标平台不支持的代码):see herehere .
  4. 我最终通过撤消源代码控制存储库中的最后更改成功地消除了错误。不幸的是,我对代码做了很多更改,所以我不能说是哪一行代码导致了我的问题。但这个故事的要点是,每个证据都表明它与我的 xaml 代码有关。因此,即使不能排除 xaml 解析器有时可能存在重大的系统范围的问题,我还是会建议其他遇到此问题的人首先快速撤消最后的更改并查看问题是否存在消失。

关于c# - g.i.cs 文件丢失,类不再包含 InitializeComponent 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35259603/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com