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

  • Question

  • Hello!I'm creating  a control library and consequently a class.Visual studio compiler is giving my followed error, when I wrote InitializeComponent();

    The name 'InitializeComponent' does not exist in the current context

    Can anybody help me please?
    Saturday, August 5, 2006 9:00 PM

All replies

  • where is the error pointing to? can you post the code where the error is pointing to?

    did you modify any default designer codes?

    Monday, August 7, 2006 1:59 AM
  • First, I didn't modify any designer codes.This error repeats two line in my codes.I'm posting the codes:

    public EasyMail()
            {
                InitializeComponent();

                MailObject = new MailMessage();
                mMailFrom = "";
                mMailTo = "";
                mMailSubject = "";
                mMailBody = "";
                mSMTPServer = "";
                mSMTPPort = 25;
                mSMTPUsername = "";
                mSMTPPassword = "";
                mSMTPSSL = false;
            }

      public EasyMail(IContainer container)
            {
                container.Add(this);
                InitializeComponent();
            }
    Monday, August 7, 2006 11:01 AM
  • Is EasyMail a form?

    which line is the error on from the code posted?

    Monday, August 7, 2006 1:19 PM
  • EasyMail is the name of my control library's one method.This method takes parameter from user, and sends mail using smtp protocol.I added every needed libraries in my codes but it fails 2 line.These are the same codes which they're InitializeComponent();

    I'm following the codes again and i'm using bolded and bigger text at the error lines(they aren't all of my codes but i can follow them, if u'll need)

     

     

    public EasyMail()
            {
                InitializeComponent();

                MailObject = new MailMessage();
                mMailFrom = "";
                mMailTo = "";
                mMailSubject = "";
                mMailBody = "";
                mSMTPServer = "";
                mSMTPPort = 25;
                mSMTPUsername = "";
                mSMTPPassword = "";
                mSMTPSSL = false;
            }

      public EasyMail(IContainer container)
            {
                container.Add(this);
                InitializeComponent();
            }

     

    The compiler is giving that error: The name 'InitializeComponent' does not exist in the current context

    Thanks for interest already now

    Tuesday, August 8, 2006 10:31 PM
  • EasyMail is the name of my control library's one method.This method takes parameter from user, and sends mail using smtp protocol.I added every needed libraries in my codes but it fails 2 line.These are the same codes which they're InitializeComponent();

    I'm following the codes again and i'm using bolded and bigger text at the error lines(they aren't all of my codes but i can follow them, if u'll need)

     

     

    public EasyMail()
            {
                InitializeComponent();

                MailObject = new MailMessage();
                mMailFrom = "";
                mMailTo = "";
                mMailSubject = "";
                mMailBody = "";
                mSMTPServer = "";
                mSMTPPort = 25;
                mSMTPUsername = "";
                mSMTPPassword = "";
                mSMTPSSL = false;
            }

      public EasyMail(IContainer container)
            {
                container.Add(this);
                InitializeComponent();
            }

     

    The compiler is giving that error: The name 'InitializeComponent' does not exist in the current context

    Thanks for interest already now

    Tuesday, August 8, 2006 10:32 PM
  • well to me, as the compiler said, the method name doesnt exist in the form/class file so remove it or comment it out
    Tuesday, August 8, 2006 10:39 PM
  • InitializeComponent() is generated by the designer to initialize a form or user control in the constructor.  It creates and initializes the controls sited on the form or user control. If your class is neither (and it doesn't sound like it is), you don't use that method.
    Wednesday, August 9, 2006 3:24 PM
  • you probably don't have the definition for the said method in your mail class.

    if you mail class is going to be the control/component, it should have an initializecomponent method since the designer needs it to preview your control/component.

    if mail is not your control/component but just another class used by the control, you should have used another code sheet for that and not edit the one generated by the wizard for your control class.
    Thursday, August 10, 2006 5:01 AM
  • This will happen if your namespace doesn't match the namespace in your x:Class value on Page.xaml.  You can check your The Page.g.cs file to verify that the namespaces match.

    • Proposed as answer by dheccMegg Thursday, February 23, 2012 1:56 PM
    Wednesday, July 25, 2007 8:25 PM
  • Open your *.csproj file in an editor (notepad or any other) and locate the following line:

    <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

    Once you find it, check the following one, and add it if not there:

    <Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />

     

    The absense of the last line would generate the error message you are having.

     

    Thanks,

    -Ashraf

    Sunday, September 30, 2007 11:21 PM
  • "The absense of the last line would generate the error message you are having."

    Why does this have to be added.  I would think that it should already be there. 

    Thanks!
    Thursday, December 20, 2007 8:39 PM
  • The line I have near the end of my .csproj files is

     

    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
      
    Even after adding the following line, the error persists.


    <Import Project="$(MSBuildBinPath)\Microsoft.WinFx.targets" />

     

    I'm using C# Express 2008 with .NET framework 3.5.

     

    Any one with a solution? Hello, hello Microsoft.

    Sunday, July 27, 2008 7:13 PM
  • I think I'm very late to respons this question.

    But you can check class name given inside the xaml file and xaml.cs file. If class name mismatches then also such problem can occure.

    HTH.
    Krunal C
    • Proposed as answer by ASPNet_Unknown Saturday, January 23, 2010 12:14 PM
    Friday, January 22, 2010 6:22 PM
  • while working with silverlight application , i m geting the error

     

    Error 1 The name 'InitializeComponent' does not exist in the current context C:\Users\Iram\Documents\Visual Studio 2008\Projects\SilverlightDB\SilverlightDB\MainPage.xaml.cs 23 13 SilverlightDB

     

    here is teh chucnk of code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using SilverlightDB.ServiceReference1;
    
    
    namespace SilverlightDB
    {
    
      
      public partial class MainPage : UserControl
      {
        public MainPage()
        {
          InitializeComponent();
    
    
        }
        private void SubmitRegister_Click(object sender, RoutedEventArgs e)
        {
    
          RegisterClient webservice = new RegisterClient();
    
          //txtFirstName
          webservice.InsertDataAsync(txtFirstName.Text, txtEmailID.Text, txtPhoneno.Text, txtLoginName.Text, txtPassword.Text);
    
        }
    
      }
    }
    
    
    Monday, August 30, 2010 2:21 AM