SuperJediMedia Posted December 20, 2014 Share Posted December 20, 2014 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 More sharing options...
0 Andre S. Veteran Posted December 20, 2014 Veteran Share Posted December 20, 2014 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 More sharing options...
0 SuperJediMedia Posted December 20, 2014 Author Share Posted December 20, 2014 But the code is no problem, it would update? Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted December 20, 2014 Veteran Share Posted December 20, 2014 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 More sharing options...
0 Dermot Posted December 20, 2014 Share Posted December 20, 2014 You're probably referencing from dll and it's an older version of EF, so instead of referencing the dll use the EF nuget to be latest with your project instead using the Package Manager Console. Link to comment Share on other sites More sharing options...
0 SuperJediMedia Posted December 20, 2014 Author Share Posted December 20, 2014 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 More sharing options...
0 Dermot Posted December 20, 2014 Share Posted December 20, 2014 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 More sharing options...
0 Andre S. Veteran Posted December 20, 2014 Veteran Share Posted December 20, 2014 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 More sharing options...
0 SuperJediMedia Posted December 21, 2014 Author Share Posted December 21, 2014 <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0 Link to comment Share on other sites More sharing options...
0 SuperJediMedia Posted December 21, 2014 Author Share Posted December 21, 2014 Is there another way to do this, to avoid this error? Link to comment Share on other sites More sharing options...
0 Dermot Posted December 21, 2014 Share Posted December 21, 2014 That 6.0.0.0 build was out on Thursday, October 17 2013 The build you want is 6.1.1.0 which was compiled Friday, June 20 2014 Source: https://www.nuget.org/packages/EntityFramework/ Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted December 21, 2014 Veteran Share Posted December 21, 2014 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 More sharing options...
0 SuperJediMedia Posted December 21, 2014 Author Share Posted December 21, 2014 Oh it says I already have this reference. for EF 6.1.1 Link to comment Share on other sites More sharing options...
Question
SuperJediMedia
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