Monday, September 30, 2013

Attempted to divide by zero

When exporting the Telerik RadGrid to Excel, the "Attempted to divide by zero" exception is thrown. The grid contains calculated columns such as getting the percentage, etc.


  
In Mathematics, dividing a number by zero is undefined. We can check first if the divisor is zero and return zero as the result.

String.Format("{0:0.00%}", group.Sum(i => i.myDivisor) == 0 ? 0 : group.Sum(i => i.myDividend) / group.Sum(i => i.myDivisor) ),

CS0012: The type is defined in an assembly that is not referenced

After deployment, page layouts are throwing Compiler Error Message: CS0012The type 'MCS.FW.SharePoint.UI.WebControlHTMLBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'MCS.FW.SharePoint, Version=2.0.0.0, Culture=neutral, PublicKeyToken=561ca36a4ea2b5b4'

The error can be fixed by adding the reference in the <assemblies> tag in web.config.