'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'
Here we go again. I now have 2 Umbraco 4.11.10 sites where I can use Children.Random() and two other Umbraco 4.11.10 sites where I can not.
I get the following error.
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'
I am at a total loss here as I know darn well that .Random() is supported for DynamicNodes. But I now have two sites in completely different environments that both say otherwise.
I have reduced my code to the one line pretty much (below) and it still fails with the same error.
I have also tried adding this reference with no change
using umbraco.MacroEngines
And various other desperate attempts. I believe at this point it might be to do with dll versions, or IIS versions, or GAC file versions, or configs or something other than syntax. Again I have 2 other sites, same version of Umbraco, where this does work.
Incidentally, if I remove .Random(), I do get back a list of DynamicNodes that I can loop through, so at least I know that the data is good and that it is in the correct media folder.
Here is my entire error message from the trace log.
2013-10-08 13:42:57,772 [11] WARN umbraco.macro - [Thread 42] Error loading MacroEngine script (file: CollageImage.cshtml, Type: ''. Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'
at CallSite.Target(Closure , CallSite , Object )
at ASP._Page_macroScripts_CollageImage_cshtml.Execute() in c:\Development\CSFI\macroScripts\CollageImage.cshtml:line 5
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
at umbraco.macro.loadMacroScript(MacroModel macro)
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
Any help or pointers would be greatly appreciated!
@Jeavon - Thanks for the reply. Yes, there are quite a few differences in the bin folder as this particular site was a 4.7 upgrade. Not to mention that they are just different sites, different packages, etc. It's worth mentioning that my other site where .Random() fails, was a clean install and not an upgrade, and I get the same error. Also worth noting that both of the sites where Random doesn't work are using the files from the 4.11.10 download at http://our.umbraco.org/download, where as the ones that do work were created using the Microsoft Web Platform Installer.
Is there a particular area (files) I should be looking at? Do you know which .dll file/files would be responsible for DynamicNodeList.Random()?
Also I wonder if it wouldn't just be easier to find an alternative to using Random? Any ideas?
The key assembly is umbraco.MacroEngines.dll, if you check the assembly version for v4.11.10 it should be 1.0.4926.14936 also worth checking umbraco.macroRenderings.dll which should be 1.0.4926.14929
Thanks for sticking with me. My file versions on the working and non-working sites match perfectly. Very perplexing.
Anyway I ended up just using a rather lengthy workaround by using the following code.
dynamic mediaFolder = Library.MediaById(1083);
var theChildren = mediaFolder.Children();
Random random = new Random();
int randomNumber = random.Next(0, theChildren.Count());
var image = theChildren[randomNumber];
<img class="internalPageImage" width="@image.umbracoWidth" height="@image.umbracoHeight" src="@image.umbracoFile" alt="@image.Name" />
Thanks again for trying to help me. I'd still love to know the reason for this odd behavior between sites, but I am on a bit of time crunch on this project and had to just come up with something quickly.
Hi Roger, do you have WebGrease.dll in your bin folder? If you do check which version and if less than v1.5.2, try to upgrade it to the latest version.
Sorry to jump on this thread, I'm just wondering if anyone found a solution to this issue?
I'm also using Umbraco 4.11.10 and I'm having exactly the same problems as Roger had above. Is there a way to specify how many random nodes to return using Roger's solution?
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'
Here we go again. I now have 2 Umbraco 4.11.10 sites where I can use Children.Random() and two other Umbraco 4.11.10 sites where I can not.
I get the following error.
I am at a total loss here as I know darn well that .Random() is supported for DynamicNodes. But I now have two sites in completely different environments that both say otherwise. I have reduced my code to the one line pretty much (below) and it still fails with the same error.
I have tried...
I have also tried adding this reference with no change
And various other desperate attempts. I believe at this point it might be to do with dll versions, or IIS versions, or GAC file versions, or configs or something other than syntax. Again I have 2 other sites, same version of Umbraco, where this does work.
Incidentally, if I remove .Random(), I do get back a list of DynamicNodes that I can loop through, so at least I know that the data is good and that it is in the correct media folder.
Here is my entire error message from the trace log.
Any help or pointers would be greatly appreciated!
Thanks -Roger
Hi Roger,
Are there any dll files in the bin folder of a site that doesn't work that are not present in a site that does work?
Jeavon
@Jeavon - Thanks for the reply. Yes, there are quite a few differences in the bin folder as this particular site was a 4.7 upgrade. Not to mention that they are just different sites, different packages, etc. It's worth mentioning that my other site where .Random() fails, was a clean install and not an upgrade, and I get the same error. Also worth noting that both of the sites where Random doesn't work are using the files from the 4.11.10 download at http://our.umbraco.org/download, where as the ones that do work were created using the Microsoft Web Platform Installer.
Is there a particular area (files) I should be looking at? Do you know which .dll file/files would be responsible for DynamicNodeList.Random()?
Also I wonder if it wouldn't just be easier to find an alternative to using Random? Any ideas?
Thanks again!
-Roger
Hi Roger,
The key assembly is umbraco.MacroEngines.dll, if you check the assembly version for v4.11.10 it should be 1.0.4926.14936 also worth checking umbraco.macroRenderings.dll which should be 1.0.4926.14929
See what you have in your sites.
Jeavon
Hi Jeavon,
Thanks for sticking with me. My file versions on the working and non-working sites match perfectly. Very perplexing.
Anyway I ended up just using a rather lengthy workaround by using the following code.
Thanks again for trying to help me. I'd still love to know the reason for this odd behavior between sites, but I am on a bit of time crunch on this project and had to just come up with something quickly.
Thanks -Roger
Hi Roger, do you have WebGrease.dll in your bin folder? If you do check which version and if less than v1.5.2, try to upgrade it to the latest version.
Jeavon
Hi,
Sorry to jump on this thread, I'm just wondering if anyone found a solution to this issue?
I'm also using Umbraco 4.11.10 and I'm having exactly the same problems as Roger had above. Is there a way to specify how many random nodes to return using Roger's solution?
pronto
Hi Pronto,
Do you have WebGrease.dll in your bin folder?
Jeavon
Hi Jeavon,
Thanks for the reply. I don't have WebGrease.dll, no - do you think this would help?
pronto
No, I've seen it's presence cause this issue. I have also read that DotNetOAuth can cause the same issue, maybe check for that also?
Thanks for the help Jeavon - it was indeed DotNetOAuth that was the cause, weird!
pronto
Awesome! I know with WebGrease, the latest version didn't mess it up, maybe there is a similar solution for DotNetOAuth.
@Jeavon Leopold - Nice! I'm glad to see this issue resurface and a solution come out at the end.
Thanks for your contributions!!
-Roger
is working on a reply...