ToInt(tagid, "") Object reference not set to an instance of an object

Jian Zhong asked on September 20, 2016 16:00

Why Macro does not resolve ToInt(tagid, ""). After restarting the app, it's working again for maybe 2 days. Trace below:

Error while evaluating expression: ToInt(tagid, "") Object reference not set to an instance of an object. at CMS.DataEngine.AbstractInfo1.RegisterProperties() at CMS.DocumentEngine.TreeNode.RegisterProperties() at CMS.Base.RegisteredProperties1.GetRegisteredProperties() at CMS.DocumentEngine.TreeNode.TryGetProperty(String columnName, Object& value) at CMS.DataEngine.BaseInfo.TryGetProperty(String columnName, Object& value, Boolean notNull) at CMS.MacroEngine.MacroResolver.GetObjectValue(Object objectToCheck, String columnName, EvaluationContext context) at CMS.MacroEngine.MacroResolver.CheckDataSourcesInternal(String expression, EvaluationContext context) at CMS.MacroEngine.MacroResolver.CheckDataSourcesInternal(String expression, EvaluationContext context) at CMS.MacroEngine.MacroResolver.CheckDataSourcesInternal(String expression, EvaluationContext context) at CMS.MacroEngine.MacroResolver.CheckDataSources(String expression, EvaluationContext context) at CMS.MacroEngine.ExpressionEvaluator.EvaluateDataMember(Boolean& match, Boolean& securityPassed) at CMS.MacroEngine.ExpressionEvaluator.EvaluateInternal(Boolean& match, Boolean& securityPassed) at CMS.MacroEngine.ExpressionEvaluator.EvaluateMethodCall(Boolean& match, Boolean& securityPassed) at CMS.MacroEngine.ExpressionEvaluator.EvaluateInternal(Boolean& match, Boolean& securityPassed) at CMS.MacroEngine.ExpressionEvaluator.Evaluate() at CMS.MacroEngine.MacroResolver.ResolveMacroExpression(ResolveExpressionSettings settings)

Recent Answers


Jan Hermann answered on September 20, 2016 16:10

Not sure why it works for 2 days but the default value (second parameter) should be int as well:

ToInt(tagid, 0)

0 votesVote for this answer Mark as a Correct answer

Jian Zhong answered on September 20, 2016 16:32

Thx Jan. But the thing is after the app restarts, the error goes away and the macro resolves well. When the error happens, the null exception is not only on {%ToInt(tagid, "")%} but is also on {%tagname%} and {%ToInt(groupid, "")%}. See the whole where clause applied on the repeater: ({%ToInt(tagid, "")%} = 0 AND '{%tagname%}'='') OR (DocumentID IN (SELECT DocumentID FROM CMS_DocumentTag WHERE TagID = {%ToInt(tagid, "")%})) OR (DocumentID IN (SELECT DocumentID FROM CMS_DocumentTag WHERE TagID IN (SELECT TagID FROM CMS_Tag WHERE TagName = '{%tagname%}' AND TagGroupID = {%ToInt(groupid, "")%})))

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on September 21, 2016 16:27

Have you tried resigning the macros?

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on September 22, 2016 15:18

Along with resigning the macros and putting an integer as the 2nd thing to the ToInt(), i would highly recommend that when using macros in SQL, that you still encapsilate them with single quotes if you are unsure if it's going to be there. This way you get something like "TagGroupID = ''" which is valid sql, instead of "TagGroupID = " which will throw an error. But just a side note!

0 votesVote for this answer Mark as a Correct answer

Jian Zhong answered on September 27, 2016 22:17

We tried resigning the macro matters but it didn't help. the macro still stop resolving after a certain period of time. can anyone think of any server side reason which might cause macro failure? it becomes normal again every time we restart the site but fail at certain point of time.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.