the given assembly name or codebase was invalid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eruss21
    New Member
    • Nov 2009
    • 1

    #1

    the given assembly name or codebase was invalid

    Here's my code. Don't know what's going on.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace Assignment2
    {
        public partial class Form1 : Form
        {
            public MotorVehicle[] arr_MotorVehicles = new MotorVehicle[0];
            private MotorVehicle newVehicle;
    
            public Form1()
            {
                InitializeComponent();
            }
            
            private void button_addnewvehicle_Click(object sender, EventArgs e)
            {
                try
                {
                    if (textBox_Manufacturer.Text.Trim() == "")
                        throw new Exception("Please enter a Manufacturer");
    
                    try
                    {
                        int.Parse(textBox_YearMade.Text);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Invalid format for \'Year Made\'");
                    }
    
                    try
                    {
                        int.Parse(textBox_Occupants.Text);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Invalid format for \'Occupants\'");
                    }
    
                    newVehicle = new MotorVehicle(textBox_Manufacturer.Text.Trim(), int.Parse(textBox_YearMade.Text), int.Parse(textBox_Occupants.Text));
    
                    //Resize array
                    Array.Resize(ref arr_MotorVehicles, arr_MotorVehicles.Length + 1);
    
                    //Insert vehicle
                    arr_MotorVehicles[arr_MotorVehicles.GetUpperBound(0)] = newVehicle;
    
                    //Update Age
                    label_age.Text = arr_MotorVehicles[arr_MotorVehicles.GetUpperBound(0)].Age.ToString();
                    numericUpDown_IndexNumber.Maximum = arr_MotorVehicles.GetUpperBound(0);
                    numericUpDown_IndexNumber.Value = arr_MotorVehicles.GetUpperBound(0);
                    groupBox_controlcenter.Enabled = true;
                    populateRecord();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "ERROR");
                }
            }
    
            private void button_Delete_Click(object sender, EventArgs e)
            {
                MotorVehicle[] arr_TempArray = new MotorVehicle[arr_MotorVehicles.GetLength(0) - 1];
                int MaximumNewArrayIndex = arr_TempArray.GetLength(0) - 1;
    
                for (int i = 0, j = 0; i <= MaximumNewArrayIndex; i++, j++)
                {
                    if (j == numericUpDown_IndexNumber.Value) j++;
                    arr_TempArray[i] = arr_MotorVehicles[j];
                }
    
                arr_MotorVehicles = arr_TempArray;
                numericUpDown_IndexNumber.Maximum = Math.Max(arr_MotorVehicles.GetUpperBound(0), 0);
                if (arr_MotorVehicles.Length == 0)
                {
                    groupBox_controlcenter.Enabled = false;
                    clearRecord();
                }
                else
                {
                    populateRecord();
                }
            }
    
            private void button_Exit_Click(object sender, EventArgs e)
            {
                Close();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                groupBox_controlcenter.Enabled = false;
                textBox_Manufacturer.Clear();
                textBox_Occupants.Clear();
                textBox_YearMade.Clear();
                label_age.Text = null;
                numericUpDown_IndexNumber.Minimum = 0;
            }
    
            private void numericUpDown_IndexNumber_ValueChanged(object sender, EventArgs e)
            {
                if (arr_MotorVehicles.Length == 0)
                {
                    clearRecord();
                }
                else
                {
                    populateRecord();
                }
            }
    
            private void populateRecord()
            {
                textBox_Manufacturer.Text = arr_MotorVehicles[(int)numericUpDown_IndexNumber.Value].Manufacturer;
                textBox_YearMade.Text = arr_MotorVehicles[(int)numericUpDown_IndexNumber.Value].YearMade.ToString();
                textBox_Occupants.Text = arr_MotorVehicles[(int)numericUpDown_IndexNumber.Value].Occupants.ToString();
                label_age.Text = arr_MotorVehicles[(int)numericUpDown_IndexNumber.Value].Age.ToString();
            }
    
            private void clearRecord()
            {
                textBox_Manufacturer.Text = null;
                textBox_YearMade.Text = null;
                textBox_Occupants.Text = null;
                label_age.Text = null;
            }
        }
    
    
        public class MotorVehicle
        {
            private string str_Manufacturer;
            private int int_YearMade;
            private int int_Occupants;
            private int int_Age;
    
            public MotorVehicle(string str_Manufacturer, int int_YearMade, int int_Occupants)
            {
                Manufacturer = str_Manufacturer;
                YearMade = int_YearMade;
                Occupants = int_Occupants;
                int_Age = System.DateTime.Today.Date.Year - int_YearMade;
            }
    
            public string Manufacturer
            {
                set
                {
                    if (value.Length == 0) throw new Exception("Please enter a Manufacturer");
                    str_Manufacturer = value;
                }
    
                get
                {
                    return str_Manufacturer;
                }
            }
    
            public int YearMade
            {
                set
                {
                    if (value < 1769) throw new Exception("\'Year Made\' cannot be earlier than 1769.");
                    if (value > System.DateTime.Today.Date.Year) throw new Exception("\'Year Made\' cannot be later than current year (" + System.DateTime.Today.Date.Year.ToString() + ").");
                    int_YearMade = value;
                }
    
                get
                {
                    return int_YearMade;
                }
            }
    
            public int Occupants
            {
                set
                {
                    if (value < 1) throw new Exception("Occupants cannot be less than 1");
                    if (value > 100) throw new Exception("Occupants cannot be more than 100");
                    int_Occupants = value;
                }
    
                get
                {
                    return int_Occupants;
                }
            }
    
            public int Age
            {
                get
                {
                    return int_Age;
                }
            }
        }
    } 
    
    
    
    
    Here's my program.cs code
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Assignment2.Form1());
            }
        }
    }
    Last edited by tlhintoq; Nov 25 '09, 08:52 PM. Reason: [CODE] ...your code here... [/CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Here's my code. Don't know what's going on.
      Not exactly the most helpful description of your issue. The error mentioned in your title should have also given an indication of the assembly name, the file, the line in the file, of where the problem is.

      Given that this is schoolwork, there isn't a lot the volunteers can do to help you. For example, we can't tell you where the problem is because for all we know that is the purpose of this assignment: for you to debug the program.

      Posting guidelines regarding schoolwork

      Comment

      Working...