Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 2
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET MVC 2
This is the forum to discuss the Wrox book Professional ASP.NET MVC 2 by Jon Galloway, Scott Hanselman, Phil Haack, Scott Guthrie, Rob Conery; ISBN: Professional ASP.NET MVC 2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 16th, 2010, 09:28 PM
Registered User
 
Join Date: Jun 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default ConstraintException was unhandled by user code

I am following along in Professional ASP.NET MVC 2 creating NerdDinner and running into a problem.

I made the change in Code snippet 1-32.txt.

Code:
        //
        // POST: /Dinners/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            Dinner dinner = dinnerRepository.GetDinner(id);
            if (TryUpdateModel(dinner))
            {
                dinnerRepository.Save();
                return RedirectToAction("Details", new { id = dinner.DinnerID });
            }
            return View(dinner);

        }
When I run under the debugger, VS 2010 breaks at

Code:
_Title = StructuralObject.SetValidValue(value,false);
in the following code with the warning "ConstraintException was unhandled by user code"

Code:
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Title
        {
            get
            {
                return _Title;
            }
            set
            {
                OnTitleChanging(value);
                ReportPropertyChanging("Title");
                _Title = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Title");
                OnTitleChanged();
            }
        }
If I continue to debug, the correct view appears as in Figure 1-89.

If I run, but do not debug, I do not get the warning.

What is going on? Shouldn't TryUpdateModel be catching this error? Is the warning appearing because TryUpdateModel is is catching the exception rather than my code? Is this a feature of VS 2010 that I want to switch off? If so, how?

Thank you,
Jeff Cooper
Reply With Quote
  #2 (permalink)  
Old July 14th, 2010, 07:59 PM
Registered User
 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having the exact same problem. Any ideas?
Reply With Quote
  #3 (permalink)  
Old July 15th, 2010, 02:04 PM
Registered User
 
Join Date: Jun 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did find that if I included the MVC/ASP.NET debugging binaries, this went away. I presume that is because the error was being handled by code that was not recognized by the debugger and once the appropriate binaries are loaded, the debugger detects the exception handler in the MVC library.
Reply With Quote
  #4 (permalink)  
Old July 28th, 2010, 04:21 PM
Registered User
 
Join Date: Jul 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just started without debugging. Worked fine.
Reply With Quote
  #5 (permalink)  
Old July 28th, 2010, 04:36 PM
Registered User
 
Join Date: Jun 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That works. I am just one of those people who wants all debugging turned on, likes to trace every line of code, and will not consider code to be complete until it generates no warnings. I know this is just sample code, but this is too much of an ingrained habit.

Compiling with the MVC debug libraries makes this go away. The issue is that if the exception takes place in a release binary and the catch is in the debugging binary, this error gets generated.
Reply With Quote
  #6 (permalink)  
Old August 3rd, 2010, 08:53 PM
Registered User
 
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Satisfactory Outcome

I'm in exactly the same boat, and I share your concerns about running without a debugger. Did you ever find a satisfactory solution for this?
Reply With Quote
  #7 (permalink)  
Old August 8th, 2010, 12:51 PM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 1
Thanked 1 Time in 1 Post
Default Workaround

I run with the debugger on and just hit F5 to continue when the database errors come up.
Reply With Quote
  #8 (permalink)  
Old August 14th, 2010, 09:33 PM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do you add the MVC debug libraries?

Quote:
Originally Posted by jcooper0 View Post
Compiling with the MVC debug libraries makes this go away. The issue is that if the exception takes place in a release binary and the catch is in the debugging binary, this error gets generated.
I'm having the same problem. I'm a newbie so excuse my ignorance. If, I understand your solution ... you are saying that if I add the MVC debug libraries as a "Reference" to my project then everything works fine and you can still debug? Could you share how you added the MVC debug libraries to your project. I don't know where to find the binaries. Thanks!

ed

Reply With Quote
  #9 (permalink)  
Old February 16th, 2011, 08:32 AM
Registered User
Points: 439, Level: 7
Points: 439, Level: 7 Points: 439, Level: 7 Points: 439, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2006
Location: , , .
Posts: 7
Thanks: 1
Thanked 1 Time in 1 Post
Default

Here is the solution:

Quote:
If you just want to debug against the provided DLL, you can install the symbols for System.Web.Mvc.dll. You'll be able to set breakpoints in the code, get better stack traces, etc. To do so, enter debugging mode then in the Debug menu, select Windows > Modules. Right click on the DLL in the Modules tab, the Load Symbols > From Symbol Servers. That'll download and install the symbols, and off you go.

-- http://stackoverflow.com/questions/1...vc-source-code
Load Symbols of System.Web.Mvc.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
AccessViolationException was unhandled evolution BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 3 May 4th, 2009 07:59 AM
Unhandled Exception stu9820 ASP.NET 1.0 and 1.1 Basics 11 January 14th, 2004 04:55 PM
Unhandled Exception: mbarrett C# 3 August 1st, 2003 05:25 PM
'System.Data.ConstraintException' - HELP PLEASE AlanBell ADO.NET 1 July 1st, 2003 02:23 AM



All times are GMT -4. The time now is 09:08 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.