Wrox Programmer Forums
|
BOOK: Beginning ASP.NET for Visual Studio 2015
This is the forum to discuss the Wrox book Beginning ASP.NET for Visual Studio 2015 by William Penberthy; ISBN: 978-1-119-07742-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET for Visual Studio 2015 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2016, 08:55 AM
Jim Jim is offline
Registered User
 
Join Date: Apr 2016
Posts: 3
Thanks: 3
Thanked 0 Times in 0 Posts
Default Chapter 9

I’m using the downloaded sample code for Chapter 9 and I’ve changed the connection strings to point to my instance of SQL Server (Express). When I run the application I get the following error message:
  • An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code

It’s pointing at line 15 in Index.cshtml:
Code:
@item.Description.Substring(0, 250)
The Data Type of the Description field is “nvarchar(MAX)” and Allow Nulls is set to True.

Any suggestions?

Thanks,
Jim
 
Old June 7th, 2016, 11:00 AM
Registered User
 
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default Chapter 9

Hello Jim,

I came across this issue as well. If you look up the Substring() method overload, it takes two arguments, you will see that the second argument is an int for length. So referring to the chapter 9 code its looking to grab a substring (so not the full string basically) of a length of 250 characters. So if your "item.Description" isn't that long (length of 250 or more) it throws an exception. Not very robust to put into an example new people are learning from! As a fix you can increase your item descriptions, or shorten the length argument to something much smaller, or even better check if the item.Description length is greater than some amount and if so use the <span>...</span>, and if not write out the full description.
The Following User Says Thank You to rmalone For This Useful Post:
Jim (June 7th, 2016)
 
Old June 7th, 2016, 12:24 PM
Jim Jim is offline
Registered User
 
Join Date: Apr 2016
Posts: 3
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thanks!! The "even better" solution worked perfectly.

Jim
 
Old June 7th, 2016, 09:33 PM
Registered User
 
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default

Glad to help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 - Code Download Missing for this Chapter dbaechtel BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 0 August 11th, 2009 11:02 AM
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.