473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

the given assembly name or codebase was invalid

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

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Assignment2
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public MotorVehicle[] arr_MotorVehicles = new MotorVehicle[0];
  15.         private MotorVehicle newVehicle;
  16.  
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void button_addnewvehicle_Click(object sender, EventArgs e)
  23.         {
  24.             try
  25.             {
  26.                 if (textBox_Manufacturer.Text.Trim() == "")
  27.                     throw new Exception("Please enter a Manufacturer");
  28.  
  29.                 try
  30.                 {
  31.                     int.Parse(textBox_YearMade.Text);
  32.                 }
  33.                 catch (Exception)
  34.                 {
  35.                     throw new Exception("Invalid format for \'Year Made\'");
  36.                 }
  37.  
  38.                 try
  39.                 {
  40.                     int.Parse(textBox_Occupants.Text);
  41.                 }
  42.                 catch (Exception)
  43.                 {
  44.                     throw new Exception("Invalid format for \'Occupants\'");
  45.                 }
  46.  
  47.                 newVehicle = new MotorVehicle(textBox_Manufacturer.Text.Trim(), int.Parse(textBox_YearMade.Text), int.Parse(textBox_Occupants.Text));
  48.  
  49.                 //Resize array
  50.                 Array.Resize(ref arr_MotorVehicles, arr_MotorVehicles.Length + 1);
  51.  
  52.                 //Insert vehicle
  53.                 arr_MotorVehicles[arr_MotorVehicles.GetUpperBound(0)] = newVehicle;
  54.  
  55.                 //Update Age
  56.                 label_age.Text = arr_MotorVehicles[arr_MotorVehicles.GetUpperBound(0)].Age.ToString();
  57.                 numericUpDown_IndexNumber.Maximum = arr_MotorVehicles.GetUpperBound(0);
  58.                 numericUpDown_IndexNumber.Value = arr_MotorVehicles.GetUpperBound(0);
  59.                 groupBox_controlcenter.Enabled = true;
  60.                 populateRecord();
  61.             }
  62.             catch (Exception ex)
  63.             {
  64.                 MessageBox.Show(ex.Message, "ERROR");
  65.             }
  66.         }
  67.  
  68.         private void button_Delete_Click(object sender, EventArgs e)
  69.         {
  70.             MotorVehicle[] arr_TempArray = new MotorVehicle[arr_MotorVehicles.GetLength(0) - 1];
  71.             int MaximumNewArrayIndex = arr_TempArray.GetLength(0) - 1;
  72.  
  73.             for (int i = 0, j = 0; i <= MaximumNewArrayIndex; i++, j++)
  74.             {
  75.                 if (j == numericUpDown_IndexNumber.Value) j++;
  76.                 arr_TempArray[i] = arr_MotorVehicles[j];
  77.             }
  78.  
  79.             arr_MotorVehicles = arr_TempArray;
  80.             numericUpDown_IndexNumber.Maximum = Math.Max(arr_MotorVehicles.GetUpperBound(0), 0);
  81.             if (arr_MotorVehicles.Length == 0)
  82.             {
  83.                 groupBox_controlcenter.Enabled = false;
  84.                 clearRecord();
  85.             }
  86.             else
  87.             {
  88.                 populateRecord();
  89.             }
  90.         }
  91.  
  92.         private void button_Exit_Click(object sender, EventArgs e)
  93.         {
  94.             Close();
  95.         }
  96.  
  97.         private void Form1_Load(object sender, EventArgs e)
  98.         {
  99.             groupBox_controlcenter.Enabled = false;
  100.             textBox_Manufacturer.Clear();
  101.             textBox_Occupants.Clear();
  102.             textBox_YearMade.Clear();
  103.             label_age.Text = null;
  104.             numericUpDown_IndexNumber.Minimum = 0;
  105.         }
  106.  
  107.         private void numericUpDown_IndexNumber_ValueChanged(object sender, EventArgs e)
  108.         {
  109.             if (arr_MotorVehicles.Length == 0)
  110.             {
  111.                 clearRecord();
  112.             }
  113.             else
  114.             {
  115.                 populateRecord();
  116.             }
  117.         }
  118.  
  119.         private void populateRecord()
  120.         {
  121.             textBox_Manufacturer.Text = arr_MotorVehicles[(int)numericUpDown_IndexNumber.Value].Manufacturer;
  122.             textBox_YearMade.Text = arr_MotorVehicles[(int)numericUpDown_IndexNumber.Value].YearMade.ToString();
  123.             textBox_Occupants.Text = arr_MotorVehicles[(int)numericUpDown_IndexNumber.Value].Occupants.ToString();
  124.             label_age.Text = arr_MotorVehicles[(int)numericUpDown_IndexNumber.Value].Age.ToString();
  125.         }
  126.  
  127.         private void clearRecord()
  128.         {
  129.             textBox_Manufacturer.Text = null;
  130.             textBox_YearMade.Text = null;
  131.             textBox_Occupants.Text = null;
  132.             label_age.Text = null;
  133.         }
  134.     }
  135.  
  136.  
  137.     public class MotorVehicle
  138.     {
  139.         private string str_Manufacturer;
  140.         private int int_YearMade;
  141.         private int int_Occupants;
  142.         private int int_Age;
  143.  
  144.         public MotorVehicle(string str_Manufacturer, int int_YearMade, int int_Occupants)
  145.         {
  146.             Manufacturer = str_Manufacturer;
  147.             YearMade = int_YearMade;
  148.             Occupants = int_Occupants;
  149.             int_Age = System.DateTime.Today.Date.Year - int_YearMade;
  150.         }
  151.  
  152.         public string Manufacturer
  153.         {
  154.             set
  155.             {
  156.                 if (value.Length == 0) throw new Exception("Please enter a Manufacturer");
  157.                 str_Manufacturer = value;
  158.             }
  159.  
  160.             get
  161.             {
  162.                 return str_Manufacturer;
  163.             }
  164.         }
  165.  
  166.         public int YearMade
  167.         {
  168.             set
  169.             {
  170.                 if (value < 1769) throw new Exception("\'Year Made\' cannot be earlier than 1769.");
  171.                 if (value > System.DateTime.Today.Date.Year) throw new Exception("\'Year Made\' cannot be later than current year (" + System.DateTime.Today.Date.Year.ToString() + ").");
  172.                 int_YearMade = value;
  173.             }
  174.  
  175.             get
  176.             {
  177.                 return int_YearMade;
  178.             }
  179.         }
  180.  
  181.         public int Occupants
  182.         {
  183.             set
  184.             {
  185.                 if (value < 1) throw new Exception("Occupants cannot be less than 1");
  186.                 if (value > 100) throw new Exception("Occupants cannot be more than 100");
  187.                 int_Occupants = value;
  188.             }
  189.  
  190.             get
  191.             {
  192.                 return int_Occupants;
  193.             }
  194.         }
  195.  
  196.         public int Age
  197.         {
  198.             get
  199.             {
  200.                 return int_Age;
  201.             }
  202.         }
  203.     }
  204.  
  205.  
  206.  
  207.  
  208. Here's my program.cs code
  209.  
  210. using System;
  211. using System.Collections.Generic;
  212. using System.Linq;
  213. using System.Windows.Forms;
  214.  
  215. namespace WindowsFormsApplication1
  216. {
  217.     static class Program
  218.     {
  219.         /// <summary>
  220.         /// The main entry point for the application.
  221.         /// </summary>
  222.         [STAThread]
  223.         static void Main()
  224.         {
  225.             Application.EnableVisualStyles();
  226.             Application.SetCompatibleTextRenderingDefault(false);
  227.             Application.Run(new Assignment2.Form1());
  228.         }
  229.     }
  230. }
Nov 25 '09 #1
2 4890
tlhintoq
3,525 Expert 2GB
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.
Nov 25 '09 #2
tlhintoq
3,525 Expert 2GB
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
Nov 25 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Pablo | last post by:
Hi, I'm creating an AppDomain and creating an instance of a class. This works fine unless I use caching, which I need to use. The exception that I get is of type "System.IO.FileLoadException"...
5
by: Bill Rust | last post by:
I have a component that needs to access files which exist in the same directory as the DLL containing the component itself. To determine the component's installation directory, I'm using...
7
by: Ruslan Popov | last post by:
Hi, I am trying to prevent an assembly being loaded from GAC and instead want it loaded from the application's base directory. However, the assembly always gets loaded from GAC. How to have it...
4
by: Aashish Patil | last post by:
Hi, My code is trying to load an assembly using Assembly.Load(string assemblyName); Assume that the current executing assembly is called Test.dll The following code works fine
4
by: Stefan | last post by:
Hi, I have an application that consists of multiple strong-named assemblies like: App.exe references Utils.dll (for simplicities sake) All assemblies are strong-named, but not GAC'd...
0
by: dbuchanan | last post by:
Hello, Why am I getting this error? I don't know how to isolate it. It occurs intermittently. Has anyone seen this before? Here is the full text \\ System.IO.FileLoadException was...
1
by: Patrick | last post by:
Has been trying to get an ASP.NET DLL's modification date/time for the "release date/time" to be displayed on the page's footer Using: System.Reflection.Assembly...
3
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I have used gacutil tool to install my COM dll into Global Assembly Cache, http://msdn2.microsoft.com/en-us/library/ex0ss12c(VS.80).aspx But I am not sure whether I need to...
7
by: chage | last post by:
Hi, I have been searching around to try adding reference assembly to another assembly during runtime, programatically. Is this possible in .Net? The reason for this is because i am having...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.