I'm using the uQuery.GetNodeByUrl() method and getting an interesting XPath related error. This is just a quick check to make sure i'm using it properly!
Node n = uQuery.GetNodeByUrl("/test.aspx");
This returns an XPathException stating "Expression must evaluate to a node-set."
Am I using this method properly? test.aspx exists and I can browse to it! Prefixing the url with "~" doesn't help either.
Which outputted the id as 1049. When I changed the URL to something else, (that didn't exist), that returned a -1.
If you've got time and want to help get to the bottom of this, try either downloading the symbol files, or the source (for v3.0.2) to see if there is an underlying exception. Would be good to iron out any problems (that I can't reproduce).
I'm calling the method in an HttpHandler and the error only occurs when I've recycled the application pool and I haven't already navigated to that page.
I'm guessing that something in Umbraco is not loaded into memory until i've hit an aspx page...
From looking at the uQuery code, we are querying the content XML cache. Which suggests that until you "start-up" Umbraco, the XML cache isn't initialised.
Wondering if there is another API call you could make to "warm it up"?
Guessing that RefreshContent() is pretty expensive so I probably don't want to be doing it every time on the off chance that it's not warmed up already. Is there any system variable which can tell me whether content is already loaded into cache or not?
We're probably getting into realms outside of uComponents now, but thanks for the input guys!
Just been looking over the core (like I spend most of my Tuesday afternoons) ... and reckon you should be able to do a quick check on the content cache.
if (umbraco.content.Instance != null) {
Tthe "umbraco.content" has a static constructor which will perform a check called "CheckXmlContentPopulation()" ... if the content isn't already initialised, it will do so.
... it's so crazy, that it. might. just. work! ;-)
I encountered this problem in Umbraco 4.9. After digging in the source code, I found that the cause is a bug in the umbraco.requestHandler class, which is used internally by uQuery.GetNodeByUrl to do the heavy lifting.
requestHandler has a static method CreateXPathQuery. If this is called before any instances of requestHandler have been created, then the method will return a malformed XPath query. For example,
The reason for CreateXPathQuery returning a broken XPath is that requestHandler has a static method "InitializeUrlName" which is only called by its constructor, hence the bug only occurs if the uQuery API calls are made before any requests have been handled by the Umbraco site, e.g. immediately after an application pool recycle.
My workaround is to use reflection to ensure that requestHandler is properly initialized:
uQuery.GetNodeByUrl() usage error/bug?
Hi guys!
I'm using Umbraco 4.7.1.1 & uComponents 3.0.2
I'm using the uQuery.GetNodeByUrl() method and getting an interesting XPath related error. This is just a quick check to make sure i'm using it properly!
This returns an XPathException stating "Expression must evaluate to a node-set."
Am I using this method properly? test.aspx exists and I can browse to it! Prefixing the url with "~" doesn't help either.
Could it be a bug?
Thanks for your help
Hi Joel,
Not sure what is going on there.
I've just re-tested this with a fresh v4.7.1.1. install and uComponents v3.0.2. On the homepage template, added in an inline script...
Which outputted the id as 1049. When I changed the URL to something else, (that didn't exist), that returned a -1.
If you've got time and want to help get to the bottom of this, try either downloading the symbol files, or the source (for v3.0.2) to see if there is an underlying exception. Would be good to iron out any problems (that I can't reproduce).
Thanks, Lee.
Thanks, Lee.
Have noticed that it is ocurring intermittently which suggests there could be some other foul play afoot...
Will investigate further and dig deeper to uncover the villain responsible!
Joel
I'm calling the method in an HttpHandler and the error only occurs when I've recycled the application pool and I haven't already navigated to that page.
I'm guessing that something in Umbraco is not loaded into memory until i've hit an aspx page...
From looking at the uQuery code, we are querying the content XML cache. Which suggests that until you "start-up" Umbraco, the XML cache isn't initialised.
Wondering if there is another API call you could make to "warm it up"?
Cheers, Lee.
Hi, there was a post last week about refreshing the xml file, I wonder if the following will do the trick ?
Cool. Isn't that called in Application_Start?!
Guessing that RefreshContent() is pretty expensive so I probably don't want to be doing it every time on the off chance that it's not warmed up already. Is there any system variable which can tell me whether content is already loaded into cache or not?
We're probably getting into realms outside of uComponents now, but thanks for the input guys!
Just been looking over the core (like I spend most of my Tuesday afternoons) ... and reckon you should be able to do a quick check on the content cache.
Tthe "umbraco.content" has a static constructor which will perform a check called "CheckXmlContentPopulation()" ... if the content isn't already initialised, it will do so.
... it's so crazy, that it. might. just. work! ;-)
Cheers, Lee.
I encountered this problem in Umbraco 4.9. After digging in the source code, I found that the cause is a bug in the umbraco.requestHandler class, which is used internally by uQuery.GetNodeByUrl to do the heavy lifting.
requestHandler has a static method CreateXPathQuery. If this is called before any instances of requestHandler have been created, then the method will return a malformed XPath query. For example,
will return
"/root/*/* [ = \"root\"]/* [ = \"test-page\"]"
when it should return
"/root/*/* [@urlName = \"root\"]/* [@urlName = \"test-page\"]"
This is the cause of uQuery.GetNodeByUrl failing.
The reason for CreateXPathQuery returning a broken XPath is that requestHandler has a static method "InitializeUrlName" which is only called by its constructor, hence the bug only occurs if the uQuery API calls are made before any requests have been handled by the Umbraco site, e.g. immediately after an application pool recycle.
My workaround is to use reflection to ensure that requestHandler is properly initialized:
is working on a reply...