views:

86

answers:

1

I'm getting the following error when I call the SaveChanges() method on my entity context:

Culture 'en' is a neutral culture. It cannot be used in formatting and parsing and therefore cannot be set as the thread's current culture.

My browser culture is set to en-us and so is my OS (tested on windows 7, vista and server 2003).

using(SubscriptionEntity context = new SubscriptionEntity()) {

            User user = new User();
            user.First_Name = firstName;
            user.Last_Name = lastName;
            user.Company = company;
            user.Job_Title = jobTitle;
            user.Email_Address = email;
            user.Address1 = address1;
            user.Date_Created = DateTime.Now;


            User_Mail_Preference_Language_Format user_mail_format_language = new User_Mail_Preference_Language_Format();
            user_mail_format_language.Mail_Preferences_Format = context.Mail_Preferences_Format.FirstOrDefault(p => p.Mail_Preferences_Format_ID == mailFormat);
            user_mail_format_language.Mail_Preferences_Language = context.Mail_Preferences_Language.FirstOrDefault(t => t.Mail_Preferences_Language_ID == languagePreference);
            user.User_Mail_Preference_Language_Format.Add(user_mail_format_language);


            foreach (int i in aoi)
            {
                User_Area_of_Interest user_aoi = new User_Area_of_Interest();
                user_aoi.Area_of_Interest = context.Area_of_Interest.First(p => p.Area_of_Interest_ID == i);
                user.User_Area_of_Interest.Add(user_aoi);
            }

            context.AddToUser(user);
            context.SaveChanges();

Error: [NotSupportedException: Culture 'en' is a neutral culture. It cannot be used in formatting and parsing and therefore cannot be set as the thread's current culture.] System.Globalization.CultureInfo.CheckNeutral(CultureInfo culture) +7484386 System.Globalization.CultureInfo.get_NumberFormat() +13 System.Globalization.NumberFormatInfo.GetInstance(IFormatProvider formatProvider) +89 System.Data.EntityUtil.ConvertCardinalityToString(Nullable1 cardinality) +90 System.Data.EntityUtil.UpdateRelationshipCardinalityConstraintViolation(String relationshipSetName, Int32 minimumCount, Nullable1 maximumCount, String entitySetName, Int32 actualCount, String otherEndPluralName, IEntityStateEntry stateEntry) +26 System.Data.Mapping.Update.Internal.RelationshipConstraintValidator.ValidateConstraints() +417 System.Data.Mapping.Update.Internal.UpdateTranslator.ProduceCommands() +59 System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) +210 System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) +117 System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave) +453 System.Data.Objects.ObjectContext.SaveChanges() +9 Osler.PublicWeb.Subscription.Business.Subscription.AddSubscription(String firstName, String lastName, String company, String jobTitle, String email, String address1, String address2, String city, String provinceState, String postalCode, String country, Int32 languagePreference, Int32 mailFormat, List`1 aoi) in D:\DevProjects\OslerDOTcom\Main\Source\Code\Osler.com\Osler.PublicWeb.Subscription.Business\Subscription.cs:150 osler_ContentTemplates_CT_EmailSubscriptions.SaveSubscriptionInfo() in c:\Inetpub\wwwroot\dev.osler.com\osler\ContentTemplates\CT_EmailSubscriptions.ascx.cs:338 osler_ContentTemplates_CT_EmailSubscriptions.Button1_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\dev.osler.com\osler\ContentTemplates\CT_EmailSubscriptions.ascx.cs:38 System.Web.UI.HtmlControls.HtmlButton.OnServerClick(EventArgs e) +111 System.Web.UI.HtmlControls.HtmlButton.RaisePostBackEvent(String eventArgument) +109 System.Web.UI.HtmlControls.HtmlButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

A: 

See Bug in Entity Framework. Entity Framework is seeing your culture as "en"(which is culture neutral) not "en-us"

DaveB
I saw that, but I don't have my culture set to 'en'.I'll try that out to see if it gets rid of the issue.Thanks!
Dave
I converted the project to .net 4.0 and I ended up figuring it out: When I submitted the asp.net form, I didn't validate blank values on one field. The choice was initialized to 0, but the reference table didn't have a value of 0. .net 4.0 EF gave a different error that helped me narrow down the issue.Thanks for your help!
Dave