Problem Building Sample 1 : List Box in Visual Studio 2010 using c#

Answered Problem Building Sample 1 : List Box in Visual Studio 2010 using c#

  • domingo, 13 de mayo de 2012 16:24
     
     

    Hi everyone!

    I just got started with Microsoft Speech Recognition, and was working with some given tutorials in the samples folder (MicrosoftSDK's -> Windows -> v7.1 -> Samples -> winui -> speech -> cs -> listBox). When I was working with the sample code, everything was working fine, compiling alright, and I pretty much understood how the code worked. So I decided on making two new project files in a different folder (one for SpeechListBox, and the other for SpeechListBoxApplication), just to test what I had learned. I wrote pretty much the same things (except for the namespace, it was ListBox for both project files in my case instead of Microsoft.Samples.Speech.Recognition.ListBox), but I was getting a lot of errors.

    Here's what I did:

    1) Made a new project file of c# (windows form type) with solution name 'ListBox', and project name 'SpeechListBox'. Added a component called "SpeechListBox.cs". Deleted the form.cs file. Wrote all the code into it that was written in the Samples version of SpeechListBox.cs. There were no errors.

    2) Made a new project file of c# (windows form type) with project name 'SpeechListBoxApplication'. Deleted the 'program.cs' file. and added the following code into the Design file. I checked everything, the reference to SpeechListBox project was there, the SpeechListBoxApplication was chosen as the startup project, the build order was SpeechListBox, then SpeechListBoxApplication. But I'm getting the following errors while trying to build the solution:

    Error 1 Could not load referenced assembly "D:\Visual Studio 2010 Projects\ProperTutorial1_ASR_ListBox\ListBox\SpeechListBox1\bin\Debug\SpeechListBox.dll".  Caught a FileNotFoundException saying "Could not load file or assembly 'D:\Visual Studio 2010 Projects\Tutorial1_ASR_ListBox\ListBox\SpeechListBox1\bin\Debug\SpeechListBox.dll' or one of its dependencies. The system cannot find the file specified.". D:\Visual Studio 2010 Projects\Tutorial1_ASR_ListBox\ListBox\SpeechListBoxApplication\ResGen SpeechListBoxApplication

    Error 60 'System.Windows.Forms.ListBox' does not contain a definition for 'SpeechEnabled' and no extension method 'SpeechEnabled' accepting a first argument of type 'System.Windows.Forms.ListBox' could be found (are you missing a using directive or an assembly reference?) D:\Visual Studio 2010 Projects\Tutorial1_ASR_ListBox\ListBox\SpeechListBoxApplication\SpeechListBoxApplication.cs 15 65 SpeechListBoxApplication

    Error 61 'System.Windows.Forms.ListBox' does not contain a definition for 'AddItem' and no extension method 'AddItem' accepting a first argument of type 'System.Windows.Forms.ListBox' could be found (are you missing a using directive or an assembly reference?) D:\Visual Studio 2010 Projects\Tutorial1_ASR_ListBox\ListBox\SpeechListBoxApplication\SpeechListBoxApplication.cs 32 28 SpeechListBoxApplication

    Error 62 'System.Windows.Forms.ListBox' does not contain a definition for 'RemoveItem' and no extension method 'RemoveItem' accepting a first argument of type 'System.Windows.Forms.ListBox' could be found (are you missing a using directive or an assembly reference?) D:\Visual Studio 2010 Projects\Tutorial1_ASR_ListBox\ListBox\SpeechListBoxApplication\SpeechListBoxApplication.cs 43 32 SpeechListBoxApplication

    Error 63 'System.Windows.Forms.ListBox' does not contain a definition for 'SpeechEnabled' and no extension method 'SpeechEnabled' accepting a first argument of type 'System.Windows.Forms.ListBox' could be found (are you missing a using directive or an assembly reference?) D:\Visual Studio 2010 Projects\Tutorial1_ASR_ListBox\ListBox\SpeechListBoxApplication\SpeechListBoxApplication.cs 50 28 SpeechListBoxApplication

    Am I doing something wrong while creating the projects, or when linking them up? I'm totally new to this, so any sort of help would be appreciated.

    Thanks guys!

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    namespace ListBox
    {
        public class SpeechListBoxApplication : System.Windows.Forms.Form
        {
            public SpeechListBoxApplication()
            {
                InitializeComponent();
                this.chkSpeechEnabled.Checked = this.speechListBox1.SpeechEnabled;
            }

            /// <summary>
            ///     The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.Run(new SpeechListBoxApplication());
            }

            private void button1_Click(object sender, EventArgs e)
            {
                // Add the new item. Internally to SpeechListBox, this will cause 
                // a rebuild of the dynamic grammar used by speech recognition 
                // engine.
                speechListBox1.AddItem(txtNewItem.Text);
                txtNewItem.Text = "";

            }

            private void button2_Click(object sender, EventArgs e)
            {
                // Just remove the current selected item. Same as AddItem, removing 
                // an item causes a grammar rebuild as well.
                if (speechListBox1.SelectedIndex >= 0)
                {
                    speechListBox1.RemoveItem(speechListBox1.SelectedIndex);
                }

            }

            private void checkBox1_CheckedChanged(object sender, EventArgs e)
            {
                speechListBox1.SpeechEnabled = chkSpeechEnabled.Checked;
            }

            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                // don't allow empty string to be added
                btnAdd.Enabled = !String.IsNullOrEmpty(txtNewItem.Text);
            }
        }
    }

Todas las respuestas

  • domingo, 13 de mayo de 2012 19:44
     
     

    Let me update my question. I was playing around with the code a little bit, and found out that the problem was definitely with the name spaces. So, I changed the name spaces, and the code started working. But now I've got another problem, I have a library assembly called SpeechListBox that has all the methods that I want to use in my process assembly (aka the executable), "SpeechListBoxApplication". The SpeechListApplication is a windows form type project in c# in which I want to put up a ListBox named speechListBox1, and use the methods from the library class SpeechListBox. But for some reason, when I type speechListBox1.AddItem(), the IntelliSense doesn't give me any method from the library class.

    P.S AddItem() is a method from the library class that I wanna use for the application class. And I've included the reference of the library class in the application class and have also stated "using Speech.Recognition.ListBox (the name of my library class's name space)" at the top of the application class.

    Any ideas on how I can make speechListBox1 use those methods?


    ENIGMA365

    I'm attaching an image of the error that I'm getting so you guys would know what I'm talking about. Like when I introduce a listBox called speechListBox2, I expect it now to have the additional methods from the library class too. But it doesn't have them for some reason.

    

    • Editado Enigma365 domingo, 13 de mayo de 2012 20:18 more precise question with image
    •  
  • martes, 15 de mayo de 2012 9:03
     
     Respondida

    Hi Man

    the speechListBox1's Type is 'System.Windows.Forms.ListBox'  and not type somewhat definited in the SpeechListBox Assemby

    you must change the speechListBox1's Type to SpeechListBox.SpeechListBox ( if your custom Listbox is named SpeechListBox )

    or

    at design time .you drag the custom speechlistbox from toolbox to designer surface or not the 'System.Windows.Forms.ListBox' 

    have a nice day


    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.


    • Editado Matthew LIN martes, 15 de mayo de 2012 9:04
    • Marcado como respuesta Enigma365 martes, 15 de mayo de 2012 17:00
    •  
  • martes, 15 de mayo de 2012 16:53
     
     

    Hey Matthew!

    Thanks for the comment! I think I've figured it out. Like I had two projects, one was the library for the custom list box that I wanted to use, and the other was the application that was going to use that custom made listbox. The problem I was facing was I couldn't see my version of the listbox in the toolbox. That was because my classes weren't compiling right. So, I just commented out all the methods being used by the custom listbox, and first compiled everything, making sure I didn't get any errors. When I looked at the toolbox, voi'la, I the custom list box which I could finally use in my application class.

    Another issue that I faced was the " does not contain a main method for a suitable entry point ", so I'm gonna tell how I fixed that too, just in case, anybody else is also facing the same problem. FYI, I had two projects, with one acting as the library for the custom made listbox, and the other acing as the application, with the appropriate Main method, and that project was also set up as the startup project, but I was still getting the main method error in a project that isn't supposed to have one. So here's what I did, right clicked the library project --> went to properties --> changed the output type from windows form to library type. And it started working again.


    ENIGMA365

  • miércoles, 16 de mayo de 2012 1:16
     
     

    Hey Matthew!

    Thanks for the comment! I think I've figured it out. Like I had two projects, one was the library for the custom list box that I wanted to use, and the other was the application that was going to use that custom made listbox. The problem I was facing was I couldn't see my version of the listbox in the toolbox. That was because my classes weren't compiling right. So, I just commented out all the methods being used by the custom listbox, and first compiled everything, making sure I didn't get any errors. When I looked at the toolbox, voi'la, I the custom list box which I could finally use in my application class.

    Another issue that I faced was the " does not contain a main method for a suitable entry point ", so I'm gonna tell how I fixed that too, just in case, anybody else is also facing the same problem. FYI, I had two projects, with one acting as the library for the custom made listbox, and the other acing as the application, with the appropriate Main method, and that project was also set up as the startup project, but I was still getting the main method error in a project that isn't supposed to have one. So here's what I did, right clicked the library project --> went to properties --> changed the output type from windows form to library type. And it started working again.


    ENIGMA365

    if you got "does not contain a main method for a suitable entry point" ,please ,check the Main method is declared as static


    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.