Я создал стандартный класс XsltContext и назвал его следующим образом:
XPathCustomContext context = new XPathCustomContext(new NameTable());
context.AddNamespace("windward", XPathCustomContext.Namespace);
XsltArgumentList varList = new XsltArgumentList();
varList.AddParam("stat-index", "", 0);
context.ArgList = varList;
XmlDocument doc = new XmlDocument();
doc.Load("c:\\test\\order.xml");
object xx = doc.CreateNavigator().Evaluate("/order[1]/customer[1]/num[@negone = $stat-index]", context);
При работе в .net 4.0 он работает нормально.Но под .NET 3.5 (который мы должны использовать в настоящее время) я получаю:
System.Xml.XPath.XPathException was unhandled
Message=XsltContext is needed for this query because of an unknown function.
Source=System.Xml
StackTrace:
at MS.Internal.Xml.XPath.CompiledXpathExpr.UndefinedXsltContext.ResolveVariable(String prefix, String name)
at MS.Internal.Xml.XPath.VariableQuery.SetXsltContext(XsltContext context)
at MS.Internal.Xml.XPath.LogicalExpr.SetXsltContext(XsltContext context)
at MS.Internal.Xml.XPath.FilterQuery.SetXsltContext(XsltContext input)
at MS.Internal.Xml.XPath.CompiledXpathExpr.SetContext(XmlNamespaceManager nsManager)
at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)
at System.Xml.XPath.XPathNavigator.Evaluate(String xpath, IXmlNamespaceResolver resolver)
at CustomXpathFunctions.Program.Main(String[] args) in c:\src\CustomXpathFunctions\Program.cs:line 62
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Есть идеи почему?
Пример кода на http://www.windwardreports.com/temp/CustomXPathFunctionsBug.zip
спасибо -Дэйв