locked
The name 'InitializeComponent' does not exist in the current context RRS feed

  • Question

  • I am attempting to build a UserControl class for a WPF MVVM application.  Even before I write a single line of code, I get the "The name 'InitializeComponent' does not exist in the current context" error.  The Build Action on the XAML file is set to "Page", Custom Tool is set to "MSBuild:Compile".

    XAML:

    <UserControl x:Class="ContractorModule.Views.ContractorView"

       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

       Height="300"

       Width="300">

       <Grid>

       </Grid>

    </UserControl>

    Code Behind:

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Windows;

    using System.Windows.Controls;

    using System.Windows.Data;

    using System.Windows.Documents;

    using System.Windows.Input;

    using System.Windows.Media;

    using System.Windows.Media.Imaging;

    using System.Windows.Navigation;

    using System.Windows.Shapes;

     

    namespace ContractorModule.Views

    {

       /// <summary>

       /// Interaction logic for ContractorView.xaml

       /// </summary>

       public partial class ContractorView : UserControl

       {

           public ContractorView()

           {

              InitializeComponent();

           }

       }

    }

     

    Thursday, January 27, 2011 7:36 PM

Answers

  • The Solution has the one main (shell) Project, and 7 additional UserControl Projects or "Modules".  This problem was occurring in two of the 7 UserControl projects.

    I have since fixed the problem by moving my XAML, CS, and DBML files out of the Project folder, dropping the Project folder completely, and recreating a new UserControl Project from scratch.  I then moved the files back into the UserControl Project folder, and added my references back into the UserControl Project.

    I was then able to build my UserControl Project successfully.  This indicates to me that there was some unknown conflict between my source code and the compiled code (possibly the baml file).

    Microsoft is notorious for correctly indicating when an error occurs, but giving you the wrong error message. While I am certain that an error did exist, I now have my doubts that it was the "The name 'InitializeComponent' does not exist in the current context" error.

    I appreciate the responses that I have received.  This problem has been resolved.

    Thanks.

    • Marked as answer by AlaskanGlitch Friday, January 28, 2011 8:23 PM
    Friday, January 28, 2011 8:22 PM

All replies

  • Sounds strange. It definetly doesn't associate ContractorView in your XAML with same one in the code. Could you upload your solution somewhere so I can look on it?
    God bless you!
    Thursday, January 27, 2011 7:53 PM
  • The solution is rather large, consisting of 8 projects.  The ContractorModule is one of those projects.  Zipped, the solution is 4.5MB.  It also references third-party controls and attaches to a remote MSSQL Server, so you would not be able to compile the solution successfully without recreating my environment.  However, if you still think that having the entire solution will help resolve this problem, I will try to upload the Zipped solution.  Do you know of some place where I can upload a 4.5MB Zip file that would give you access?

    Thursday, January 27, 2011 8:04 PM
  • Upload only ContractorModule project
    God bless you!
    Thursday, January 27, 2011 8:05 PM
  • Gladly.  It is only 616KB zipped.  Where/How do I upload the file for you to access?

    FYI:  The ContractorView.g.cs source file is not being created.

    Thursday, January 27, 2011 8:08 PM
  • Hi AlaskanGlitch,

    Thanks for posting.

    I am wondering whether this only happen to one particular usercontrol? Have you tried creating a new UserControl in the same project? Does the same thing happen again? If so, what if you create a UserControl in a brand new WPF project?

    Could you let us know your visual studio version and OS version?

    If there isn't any confidential/sensitive information in your code, you can upload it to SkyDrive and post the link here.


    Best regards,
    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 28, 2011 7:09 AM
  • The Solution has the one main (shell) Project, and 7 additional UserControl Projects or "Modules".  This problem was occurring in two of the 7 UserControl projects.

    I have since fixed the problem by moving my XAML, CS, and DBML files out of the Project folder, dropping the Project folder completely, and recreating a new UserControl Project from scratch.  I then moved the files back into the UserControl Project folder, and added my references back into the UserControl Project.

    I was then able to build my UserControl Project successfully.  This indicates to me that there was some unknown conflict between my source code and the compiled code (possibly the baml file).

    Microsoft is notorious for correctly indicating when an error occurs, but giving you the wrong error message. While I am certain that an error did exist, I now have my doubts that it was the "The name 'InitializeComponent' does not exist in the current context" error.

    I appreciate the responses that I have received.  This problem has been resolved.

    Thanks.

    • Marked as answer by AlaskanGlitch Friday, January 28, 2011 8:23 PM
    Friday, January 28, 2011 8:22 PM