Extension function

May 5, 2010 at 12:55 AM

Hello Semyon,

I'm trying make this extension function work:

[XQuerySignature("query-param", NamespaceUri = CoreFunctions.Namespace, Cardinality = XmlTypeCardinality.ZeroOrMore, Return = XmlTypeCode.String)]
public static object QueryParam(
   [XQueryParameter(XmlTypeCode.String, Cardinality = XmlTypeCardinality.One)]
   string name) {

   List<XPathItem> items = new List<XPathItem>();

   foreach (string item in CoreFunctions.QueryParam(name)) 
      items.Add(new XQueryItem(item, XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.String)));

   return new NodeIterator(items);
}

But I'm getting a NullReferenceException:

[NullReferenceException: Object reference not set to an instance of an object.]
   DataEngine.XQuery.InnerExecutive.HandleRuntimeException(Exception exception) +1637
   DataEngine.CoreServices.CompiledLambda.Invoke(Object[] args) +160
   DataEngine.CoreServices.Executive.Apply(Object id, Parameter[] parameters, Object lval, Object[] args, SymbolLink dynamicFunc) +60
   DataEngine.XQuery.XQueryCommand.Execute() +327

Any ideas ?

Coordinator
May 5, 2010 at 5:08 AM
Edited May 5, 2010 at 5:15 AM

Check you CoreFunctions class. This snippet works fine:

 

        [XQuerySignature("query-param", Cardinality = XmlTypeCardinality.ZeroOrMore, Return = XmlTypeCode.String)]
        public static object QueryParam(
           [XQueryParameter(XmlTypeCode.String, Cardinality = XmlTypeCardinality.One)] string name)
        {

            List<XPathItem> items = new List<XPathItem>();

            items.Add(new XQueryItem("1", XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.String)));
            items.Add(new XQueryItem("2", XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.String)));
            items.Add(new XQueryItem("3", XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.String)));

            return new NodeIterator(items);
        }

 

I recommend to check "Break when exception is | Common Language Runtime Exceptions | Thrown" in Debug | Exception menu in Visual Studio.
HandleRuntimeException rethrows exception and will hide a real line number.
Second parameter in XQueryItem constructor is also not necessarily because XmlType will be infered from value automatically.

 

 

 

 

 

 

May 5, 2010 at 5:32 AM
I found the issue, it happens when the list is empty. I see you have
an EmptyIterator class, but it's internal. What do you suggest?

--
Max

2010/5/5 semyonc <notifications@codeplex.com>:
> From: semyonc
>
> Check you CoreFunctions class. This snippet works fine:
>
> [XQuerySignature("query-param", Cardinality =
> XmlTypeCardinality.ZeroOrMore, Return = XmlTypeCode.String)]
> public static object QueryParam(
> [XQueryParameter(XmlTypeCode.String, Cardinality =
> XmlTypeCardinality.One)] string name)
> {
>
> List<XPathItem> items = new List<XPathItem>();
>
> items.Add(new XQueryItem("1",
> XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.String)));
> items.Add(new XQueryItem("2",
> XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.String)));
> items.Add(new XQueryItem("3",
> XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.String)));
>
> return new NodeIterator(items);
> }
>
> I recomend to check "Break when exception is | Common Language Runtime
> Exceptions | Thrown" in Debug | Exception menu in Visual Studio.
> HandleRuntimeException rethrows exception and will hide a real line number.
> Second parameter in XQueryItem constructor is also not nessesary because
> XmlType will be infered from value automatically.
>
>
>
>
>
>
>
>
>
>
>
>
>
> Read the full discussion online.
>
> To add a post to this discussion, reply to this email
> ([email removed])
>
> To start a new discussion for this project, email
> [email removed]
>
> You are receiving this email because you subscribed to this discussion on
> CodePlex. You can unsubscribe on CodePlex.com.
>
> Please note: Images and attachments will be removed from emails. Any posts
> to this discussion will also be available online at CodePlex.com
Coordinator
May 5, 2010 at 5:44 AM

Is not true. This code work:

[XQuerySignature("query-param", Cardinality = XmlTypeCardinality.ZeroOrMore, Return = XmlTypeCode.String)]
        public static object QueryParam(
           [XQueryParameter(XmlTypeCode.String, Cardinality = XmlTypeCardinality.One)] string name)
        {

            List<XPathItem> items = new List<XPathItem>();
            return new NodeIterator(items);
        }

 

May 5, 2010 at 4:02 PM
Sorry, you are right, I found my bug.
--
Max