Note that there are some explanatory texts on larger screens.

plurals
  1. POSystem.MissingMethodException: Cannot create an instance of an interface
    primarykey
    data
    text
    <p>I have a form that has a few text boxes, you input some values into the text boxes and then when you press submit it saves the values to a file. However when I press submit, I get the following exception. I've narrowed the problem down to something in the InventoryMngr and CreateInventory code, but I am unsure what I am doing wrong there.</p> <pre><code>System.MissingMethodException: Cannot create an instance of an interface. at HomeInventory2.Services.Factory.GetService(String servicename) in C:\Users\Protego\documents\visual studio 2010\Projects\HomeInventory2\HomeInventory2\Services\Factory.cs:line 37 at HomeInventory2.Business.Manager.GetService(String name) in C:\Users\Protego\documents\visual studio 2010\Projects\HomeInventory2\HomeInventory2\Business\Manager.cs:line 14 at HomeInventory2.Business.InventoryMngr.Create(CreateInventory inv) in C:\Users\Protego\documents\visual studio 2010\Projects\HomeInventory2\HomeInventory2\Business\InventoryMngr.cs:line 19 at HomeInventory2.Form1.submitButton_Click(Object sender, EventArgs e) in C:\Users\Protego\documents\visual studio 2010\Projects\HomeInventory2\HomeInventory2\Form1.cs:line 52 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message&amp; m) at System.Windows.Forms.ButtonBase.WndProc(Message&amp; m) at System.Windows.Forms.Button.WndProc(Message&amp; m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) </code></pre> <p>InventoryMngr</p> <pre><code>namespace HomeInventory2.Business { public class InventoryMngr : Manager { /// &lt;summary&gt; /// persists the inventory information /// &lt;/summary&gt; /// &lt;param name="inv"&gt;&lt;/param&gt; public void Create(CreateInventory inv) { InventorySvc inventorySvc = (InventorySvc)GetService(typeof(InventorySvc).Name); inventorySvc.CreateInventory(inv); } } } </code></pre> <p>CreateInventory</p> <pre><code>namespace HomeInventory2.Domain { [Serializable] public class CreateInventory { /// &lt;summary&gt; /// item category /// &lt;/summary&gt; private string itemCategory; public String ItemCategory { set { itemCategory = value; } get { return itemCategory; } } /// &lt;summary&gt; /// item properties /// &lt;/summary&gt; private string itemProperties; public String ItemProperties { set { itemProperties = value; } get { return itemProperties; } } /// &lt;summary&gt; /// item amount /// &lt;/summary&gt; private string itemAmount; public String ItemAmount { set { itemAmount = value; } get { return itemAmount; } } /// &lt;summary&gt; /// item value /// &lt;/summary&gt; private string itemValue; public String ItemValue { set { itemValue = value; } get { return itemValue; } } } } </code></pre> <p>InventorySvc is an interface</p> <pre><code>namespace HomeInventory2.Services { public interface InventorySvc : IService { void CreateInventory(CreateInventory createinventory); } } </code></pre> <p>InventoryImpl</p> <pre><code>namespace HomeInventory2.Services { public class InventoryImpl: InventorySvc { /// &lt;summary&gt; /// Creates an output files with the given inventory information written to it, serves as placeholder - this will be replaced with a database system /// &lt;/summary&gt; /// &lt;param name="createinventory"&gt;&lt;/param&gt; public void CreateInventory(CreateInventory createinventory) { try { FileStream fileStream = new FileStream ("CreateInventory.bin", FileMode.Create, FileAccess.Write); IFormatter formatter = new BinaryFormatter(); formatter.Serialize(fileStream, createinventory); fileStream.Close(); } catch (ItemNotFoundException) { throw new ItemNotFoundException("Output not created - see logs"); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload