C# g、 i.cs文件丢失,类不再包含InitializeComponent的定义
我在业余时间开发了一个UWP项目,以了解UWP、MVVM和Prism。该项目最初是非常经典的,没有使用MVVM和Prism,我一直在努力将这两种技术引入到该项目中。我一直在依靠,并努力克服它 一些背景:我最初有一个从C# g、 i.cs文件丢失,类不再包含InitializeComponent的定义,c#,xaml,mvvm,prism,uwp,C#,Xaml,Mvvm,Prism,Uwp,我在业余时间开发了一个UWP项目,以了解UWP、MVVM和Prism。该项目最初是非常经典的,没有使用MVVM和Prism,我一直在努力将这两种技术引入到该项目中。我一直在依靠,并努力克服它 一些背景:我最初有一个从Mainpage.xaml到Mainpage.xaml.cscodebehind的直接函数调用,但在转换到MVVM和一个单独的用户控件的过程中,我删除了该函数调用,以便以后可以使用命令绑定。在我删除它之后,我在GameRoulettView.g.I.cs的某个地方得到了一个错误,这是
Mainpage.xaml
到Mainpage.xaml.cs
codebehind的直接函数调用,但在转换到MVVM和一个单独的用户控件的过程中,我删除了该函数调用,以便以后可以使用命令绑定。在我删除它之后,我在GameRoulettView.g.I.cs的某个地方得到了一个错误,这是这个删除的函数调用的一个残余,其中g.I.cs文件假定它仍然是绑定的。我重建了我的项目,那些g.I.cs文件显然被删除了
我在Usercontrol视图中添加了以下行,以便添加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>
我重新构建了该项目,然后它为我的3.xaml文件中的每个文件都给出了以下错误:GameRoulettView、App.xaml和MainPage.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'.
我已经排除的事情:
我的名字空间是正确的李>
我试过了,没用李>
我已经删除了bin、obj文件夹和.suo文件,没有修复它李>
我已关闭并重新打开解决方案,但没有修复它
通过“添加/修复/删除程序”窗口修复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.
我有一种感觉,所有这些问题都是相关的,但我不知道这是怎么回事。如上所述,谷歌并没有提供太多的帮助,它所提供的也不起作用
我使用的是Visual Studio 2015社区版,更新版本为1。该项目可以在中找到。我已经为这个问题挣扎了几天,至少在我的例子中,我非常确定它取决于我在xaml代码中无意中引入的一些微妙的错误。或者,更好的是,不完全是一个bug,而是我们目标平台的xaml版本不支持的东西。在这种情况下,xaml解析器失败,g.i.cs文件(包含解析器生成的部分页面和应用程序类,包括InitializeComponent方法)不会按预期生成。
我为什么相信这一点
起初,我认为这是Visual Studio的问题,所以我清除了组件缓存,然后完全删除了文件夹C:\Users{myname}\AppData\Local\Microsoft\VisualStudio\14.0,然后我取消安装,然后从头重新安装VS。我仍然有错误
当我尝试构建解决方案时,在错误窗口中,我只看到一个通用的“对象引用未设置为对象的实例”,但如果检查构建输出窗口,我可以看到问题实际上与xaml解析器有关(确切地说:xaml内部错误WMC9999)李>
互联网上没有太多关于这个问题的信息,这是面对同样情况的人提出的一些帮助请求的一部分,但我找到的唯一两个页面确实提供了解决方案,这两个页面都将这个问题与xaml中使用(不同的)不受支持的功能联系在一起(语法正确但目标平台不支持的代码):和
我最终通过撤销我的源代码管理存储库的最后更改成功地消除了错误。不幸的是,我在代码中做了很多更改,所以我不能说是哪一行代码导致了我的问题。但是这个故事的要点是,每一个证据都表明这是一个重新定义的事实因此,当然,即使不能排除xaml解析器有时可能存在重大的系统范围问题,我建议其他面临此问题的人首先快速撤销最后的更改,看看问题是否消失
至少在github存储库中,没有GameRoulettView。xaml
@Haukinger在提交过程中似乎出了问题。现在应该修复它。在我上次发表评论9小时后,这个问题似乎基本上得到了修复,但我不知道为什么。我留下的唯一问题是NuGet错误。我将为VtC修复无法复制的问题。
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.