• 0

Help me with C# WPF


Question

I am not sure which forum this best goes to

 

When I select from a Select List, it shows up in a text box that I can edit it, but when I press Update Button, I get an error.

 

What am I overlooking?

 

private void CustomerUpdateButton_OnClick(object sender, RoutedEventArgs e)

{

Customer customer = (Customer)CustomerList.SelectedItem;

var custResp = new CustomerRepository();

int custid = customer.CustomerId;

customer = custResp.GetById(custid);

customer.FirstName = FirstNameInput.Text;

customer.LastName = LastNameInput.Text;

customer.City = CityInput.Text;

customer.State = StateInput.Text;

custResp.Update(customer);

custResp.SaveChanges();

}

 

 

 

 

Trying to update the database, but it doesn't work. Gave me this error.

 

I got An unhandled exception of type 'System.MissingMethodException'

Additional information: Method not found: 'Void System.Data.Entity.Infrastructure.DbEntityEntry`1.set_State(System.Data.EntityState)'.

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

MissingMethodException tells you there's some mismatch between dlls at runtime, assembly A expects assembly B to contain this method but it doesn't (usually because assembly B is a different version than the one expected). This particular method appears to be part of the Entity Framework 5.0 and above. Verify that EntityFramework.dll is present and with the right version in the folder where your application is deployed when you run it. Check if there's any mismatch between the version of Entity Framework you're compiling against vs. the version you deploy.

 

EDIT: actually Entity Framework is part of the .NET framework so it should be in the GAC, so your application might simply not be referencing the right version, or the right version of .NET is not installed on the machine where the exception is occuring.

Link to comment
Share on other sites

  • 0

I have no idea what the implementation of "Customer" and "CustomerRepository" are so that's not something I can answer by looking at the information you've provided. You're calling methods that sound like they should do the right thing but whether they actually work is another matter.

Link to comment
Share on other sites

  • 0

Again, I have a list/grid in WPF format that is working properly, it list the database from Customers table all the customers from an Entity frame.

 

Then I have this, let me call it the 'Edit section'

 

First Name [Textbox]

Last Name [Textbox]

City [Textbox]

State [Textbox]

 

And a update button (private void CustomerUpdateButton_OnClick(object sender, RoutedEventArgs e))

 

When I select a customer from the list it will reflect on the 'Edit section' same customer that I selected, this part is definitely working right.

 

 

But when I click update button, I get this error.

Link to comment
Share on other sites

  • 0

But the code is no problem, it would update?

 

Not if the libary doesn't have the method being called.

 

What EF version do you use?

Link to comment
Share on other sites

  • 0

When I select a customer from the list it will reflect on the 'Edit section' same customer that I selected, this part is definitely working right.

 

But when I click update button, I get this error.

Yes, that would be because of the reasons I and Dermot just outlined.

Link to comment
Share on other sites

  • 0

It looks like depending on which version of .NET your project is targeting you might end up with a different EntityFramework.dll. http://thedatafarm.com/data-access/when-entity-framework-5-ef5-is-not-entity-framework-5-ef5/ So if you're targeting .NET 4 that could explain (I guess?) the missing method.

 

Anyway, look in your bin/Debug folder or wherever is the output of your project and check the assembly version of EntityFramework.dll.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.