putting a macro in a dictionary item seems broken since 4.10
I recently upgraded one of my sites from 3.0.2 up to 4.10. This went great up to 4.9 but in 4.10 umbraco starts raising exceptions, i started cleaning out my templates until I found the cause. It's a macro that i call inside a header dictionary item.(i used to do that all the time before i understood masterpages :-)) I found that the macro is not the problem; it just runs fine when called from a template.
I am now wondering if this is a bug introduced in v4.10 or is this caused by a mistake i made during the upgrade. Can someone test this on their install please and tell me what happens,
(i run on windows server 2008, sql, just plain umbraco no extentions, packages etc)
Do you still have the issue? Or did you manage to solve the issue and now you're just being curious? :)
What kind of error description did you get if any? And could you show a screendump that displays how you used to do it?
It's important to keep in mind that Umbraco was rewritten making use of native .NET stuff like asp.net masterpages etc so other things have been affected as well for sure and it might be related to this.
Since the upgrade to 4.10 caused errors I went back to 4.9, and that is the version i am currently running on. I will be happy to try to fix this problem myself, but first i want to make sure this is not a problem in my installation. You can see the error below.
Leon
Server Error in '/' Application.
The given key was not present in the dictionary.
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.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[KeyNotFoundException: The given key was not present in the dictionary.]
System.Collections.Generic.Dictionary`2.get_Item(TKey key) +12686831
Umbraco.Core.Macros.MacroTagParser.ParseMacros(String text, Action`1 textFoundCallback, Action`2 macroFoundCallback) +745
umbraco.presentation.templateControls.Item.OnInit(EventArgs e) +329
System.Web.UI.Control.InitRecursive(Control namingContainer) +133
System.Web.UI.Control.InitRecursive(Control namingContainer) +421
System.Web.UI.Control.InitRecursive(Control namingContainer) +421
System.Web.UI.Control.InitRecursive(Control namingContainer) +421
System.Web.UI.Control.InitRecursive(Control namingContainer) +421
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1970
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Request Details
Session Id:
bhcposo1xpm5t2mlhpogaxf2
Request Type:
GET
Time of Request:
20-1-2013 21:10:39
Status Code:
500
Request Encoding:
Unicode (UTF-8)
Response Encoding:
Unicode (UTF-8)
Trace Information
Category
Message
From First(s)
From Last(s)
aspx.page
Begin PreInit
aspx.page
End PreInit
0,951684716386734
0,951685
aspx.page
Begin Init
0,951742312798861
0,000058
item
Start parsing '#head1a'
1,02014893152256
0,068407
item
Done parsing '#head1a'
1,02056746545069
0,000419
item
Start parsing 'titel'
1,0262865758549
0,005719
item
Done parsing 'titel'
1,0263497185882
0,000063
item
Start parsing '#head1b'
1,02643461996607
0,000085
item
Done parsing '#head1b'
1,02649093645793
0,000056
renderMacro
Rendering started (macro: Hoofdmenu, type: 1, cacheRate: 0)
The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Umbraco.Core.Macros.MacroTagParser.ParseMacros(String text, Action`1 textFoundCallback, Action`2 macroFoundCallback) at umbraco.presentation.templateControls.Item.OnInit(EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Today I downloaded the v4.10.1 source, found the problem and made a fix.
The problem was in MacroTagParser.cs (part of the core), the troublesome line is
var macroAlias = attributes["macroalias"] ?? attributes["alias"];
My macro tag only had an alias attribute, the programmer probably assumed that a non existing dictionary-item would return null, but that's not the case.
I replaced the line above with the following which works for me.
var macroAlias = ""; if (attributes.Keys.IndexOf("macroalias") == -1) macroAlias = attributes["alias"]; else macroAlias = attributes["macroalias"];
I built the core.dll, replaced it on the server and to my delight it works fine. I have no idea if this was fixed in a later release, maybe someone more experienced can check this and maybe put a fix like this in some future release.
If someone reads this who experiences the same problem, the quick fix is to change you macro tag and use the macroalias attribute instead of the macro attribute.
putting a macro in a dictionary item seems broken since 4.10
I recently upgraded one of my sites from 3.0.2 up to 4.10. This went great up to 4.9 but in 4.10 umbraco starts raising exceptions, i started cleaning out my templates until I found the cause. It's a macro that i call inside a header dictionary item.(i used to do that all the time before i understood masterpages :-)) I found that the macro is not the problem; it just runs fine when called from a template.
I am now wondering if this is a bug introduced in v4.10 or is this caused by a mistake i made during the upgrade. Can someone test this on their install please and tell me what happens,
(i run on windows server 2008, sql, just plain umbraco no extentions, packages etc)
Thanks for your help.
Hi Leon
Do you still have the issue? Or did you manage to solve the issue and now you're just being curious? :)
What kind of error description did you get if any? And could you show a screendump that displays how you used to do it?
It's important to keep in mind that Umbraco was rewritten making use of native .NET stuff like asp.net masterpages etc so other things have been affected as well for sure and it might be related to this.
/Jan
Since the upgrade to 4.10 caused errors I went back to 4.9, and that is the version i am currently running on. I will be happy to try to fix this problem myself, but first i want to make sure this is not a problem in my installation. You can see the error below.
Leon
Server Error in '/' Application.
The given key was not present in the dictionary.
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.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Request Details
Trace Information
The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Umbraco.Core.Macros.MacroTagParser.ParseMacros(String text, Action`1 textFoundCallback, Action`2 macroFoundCallback)
at umbraco.presentation.templateControls.Item.OnInit(EventArgs e)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Today I downloaded the v4.10.1 source, found the problem and made a fix.
The problem was in MacroTagParser.cs (part of the core), the troublesome line is
var macroAlias = attributes["macroalias"] ?? attributes["alias"];
My macro tag only had an alias attribute, the programmer probably assumed that a non existing dictionary-item would return null, but that's not the case.
I replaced the line above with the following which works for me.
var macroAlias = "";
if (attributes.Keys.IndexOf("macroalias") == -1)
macroAlias = attributes["alias"];
else
macroAlias = attributes["macroalias"];
I built the core.dll, replaced it on the server and to my delight it works fine.
I have no idea if this was fixed in a later release, maybe someone more experienced can check this and maybe put a fix like this in some future release.
If someone reads this who experiences the same problem, the quick fix is to change you macro tag and use the macroalias attribute instead of the macro attribute.
Leon
is working on a reply...