Henry wrote:
> I am trying to work my way through a textbook on web services. I was
> running a help page and got this error message. To me it is vague. Not
> knowing the code well enough I am not sure which data element it is talking
> about.... schemas? Context.items? I am not sure where that is
> initialized.....
>
> Any ideas about what I should be looking for?
>
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
>
> Source Error:
>
>
> Line 1183:
> Line 1184: schemas = new XmlSchemas();
> Line 1185: foreach (XmlSchema schema in
> (XmlSchemas)Context.Items["schemas"]) {
> Line 1186: schemas.Add(schema);
> Line 1187: }
>
>
> Source File: G:\Software\Wrox Press\Professional ASP.NET Web
> Services\Chapter02\wwwroot\MywsdlHelpGenerator.aspx Line: 1185
>
> Stack Trace:
>
>
> [NullReferenceException: Object reference not set to an instance of an
> object.]
> ASP.MyWsdlHelpGenerator_aspx.Page_Load(Object sender, EventArgs e) in
> G:\Software\Wrox Press\Professional ASP.NET Web
> Services\Chapter02\wwwroot\MywsdlHelpGenerator.aspx:1185
> System.Web.UI.Control.OnLoad(EventArgs e) +67
> System.Web.UI.Control.LoadRecursive() +35
> System.Web.UI.Page.ProcessRequestMain() +750
Hi Henry,
My guess is Context.Items["schemas"] is null and the cast is causing the
NullReferenceException. Not knowing the code I don't know how much I
can help. You might try searching the code for '["schemas"] = ' or
'Context.Add("schemas"' to see where schemas are added to the context.
You could add an if statement to it like so:
if(Context.Items["schemas"] != null) {
foreach(XmlSchema schema in (XmlSchemas)Context.Items["schemas"]) {
schemas.Add(schema);
}
}
Looking at the few lines of code I'm not sure what the purpose of
looping through the collection is when you could just do:
if(Context.Items["schemas"] != null)
schemas = (XmlSchemas)Context.Items["schemas"]);
--
David Hogue
|