p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=560)
-   -   Chapter 19 page 702 (http://p2p.wrox.com/showthread.php?t=87155)

Nick Makin April 2nd, 2012 08:10 AM

Chapter 19 page 702
Hi, I have finished the chapter but had to go back to the first exercise of this chapter because of an error I cant seem to shake off,

In the exercise on page 702 it instructs you to insert the following code:

    public static string FromAddress
            string result = WebConfigurationManager.AppSettings.Get("FromAddress");
            if (!string.IsNullOrEmpty(result))
                return result;
        throw new Exception("AppSettings FromAddress not found in web.config file.");

But I am getting errors for both "get" and "throw". For "get" it says 'AppConfiguration.FromAddress.get': not all code paths return a value and for "throw" it says "a get or set accessor expected".

I have inserted the using.System.Web.Configuration; to the top of the code.

Any help would be appreciated,


Imar April 2nd, 2012 08:15 AM

Hi Nick,

Your throw statement is outside the curly brace of the getter, while it should be inside. That should fix both problems as a) the throw statement is now in a valid location, and b) the getter returns something (or throws an error) on all code paths.



Nick Makin April 2nd, 2012 08:45 AM

Wow! Can't believe I missed that one,

Thanks again Imar,


Imar April 2nd, 2012 08:53 AM

Looks like you found the Global class? ;-)


Nick Makin April 2nd, 2012 09:51 AM

Haha yep!

Was something I remember reading through the other day and thought "what is that?" so I thought I'd ask, but then realised when I was looking through my Solution Explorer that I had the Global.asax file sat right in front of me so tried to delete the post!


Imar April 2nd, 2012 10:41 AM


so tried to delete the post!
I noticed. But I get notifications by e-mail, so I saw your question before you deleted it.... ;-)



All times are GMT -4. The time now is 12:06 AM.

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