简体   繁体   中英

g.i.cs files missing, classes no longer contain a definition for InitializeComponent

I've been developing a UWP project in my spare time to get a hang of UWP, MVVM and Prism. The project was originally really classic, with no use of MVVM and Prism, and I've been working to get those 2 into the project. I've been relying on https://msdn.microsoft.com/en-us/library/gg405484(v=pandp.40).aspx , https://msdn.microsoft.com/en-us/library/gg405494(v=pandp.40).aspx and https://msdn.microsoft.com/en-us/library/ff921098(v=pandp.40).aspx to work my way through it.

Some background: I originally had a direct function call from my Mainpage.xaml to the MainPage.xaml.cs codebehind, but during the conversion to MVVM and a separate usercontrol, I removed that function call so I could later using Command Binding. After I removed that, I got an error that was somewhere in GameRouletteView.gics that was a remnant of this removed function call, where the gics file assumed it was still bound. I rebuilt my project and those gics files apparently got removed.

I added the following lines to my Usercontrol View so my ViewModel gets added:

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

Full Code:

<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>

It gave the following error:

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

I rebuilt the project, and then it gave the following error for each of my 3 .xaml files: GameRouletteView, App.xaml and 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?)

Also, when first opening the project, I get the Intellisense errors:

[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'.

Things I've ruled out:

  1. My namespaces are correct;
  2. I've tried https://stackoverflow.com/a/27260580/1770430 , didn't work;
  3. i've deleted the bin, obj folders and the .suo file, didn't fix it;
  4. I've closed and reopened the solution, did not fix it.
  5. Repair Visual Studio through the add/repair/remove programs window, no result.

I've googled this error, but I can't really find anything that I haven't tried yet.

I've also noticed that my NuGet Packages have gone missing and that my Package Manager Console does not recognize NuGet anymore. I also get this error:

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.

I got a feeling that all these issues are related, but I can't figure out what's wrong with it. As mentioned above, Google doesn't really provide much assistance, and what it does provide doesn't work.

I'm using Visual Studio 2015 Community Edition with Update 1. The project can be found at https://github.com/nzall/GameRoulette .

I've struggled with this issue for a couple of days, and, at least in my case, I'm pretty sure that it depended on some subtle bug that I introduced inadvertently in my xaml code. Or, better, not exactly a bug, but something that's not supported by the version of xaml for the platform we are targeting. In that case the xaml parser fails, and the gics files (which contain the part of the pages and app classes generated by the parser, including the InitializeComponent method) are not generated as expected. Why do I believe that?

  1. At first, I thought it was a problem with Visual Studio, so I cleared component cache, then deleted completely the folder C:\\Users{myname}\\AppData\\Local\\Microsoft\\VisualStudio\\14.0, then I disinstalled and then reinstalled VS from scratch. I still had the error.
  2. When I tried to build the solution, in the error windows I Only saw a generic 'Object reference not set to an instance of an object', but if I examined build output window, I could see that the problem was in effect related to the xaml parser (precisely: Xaml Internal Error WMC9999).
  3. There's not so much on the internet about this issue, a part for a few help request by people facing the same situation, but the only two pages I managed to found that do offer a solution both linked this problem to the use of (different) unsupported functionality in xaml (code that is syntactically correct but unsupported by the target platform): see here and here .
  4. I finally managed to get rid of the errors simply by undoing the last changes with my source control repository. Unfortunately, I had made a lot of change in code, so I can't say which was the exact line of code that caused the problem in my case. But the takeaway of this story is that every evidence points to the fact that it was something related to my xaml code. So, even if, of course, one can't exclude that sometimes there could be a major, system-wide issue with the xaml parser, I would advise other people facing this problem first to quickly undo the last changes and see if the problem disappears.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM