BUG: RDLC Winforms evaluates style expressions as CurrentCulture despite evaluating the result as InvariantCulture

Mirality 1 Reputation point
2021-09-21T04:28:02.297+00:00

Using Microsoft.ReportingServices.ReportViewerControl.Winforms 150.1449.0, I want to use a calculated padding value on an Image.

In particular, the image is set to resize proportionally to fit and I want to right-align it (which this StackOverflow answer provides a helpful formula for).

The report image is 6.5cm wide and 0.5cm tall and I have parameters that describe the pixel size on disk; plugging this all together it gave me this PaddingLeft formula:

=CStr(Round(6.5-0.5*CDbl(Parameters!LogoWidth.Value)/Parameters!LogoHeight.Value,2))&"cm"

This works perfectly ... as long as the report is run in a locale with a dot as the decimal separator.

When I try running it in a locale using a comma as decimal separator, then the report loads but with no padding. If I have the debugger attached at the time then I see the expression generates a parsing exception when trying to interpret a value containing a comma.

This is not entirely surprising, since CStr uses the current locale and the report definition internally uses the invariant locale, I guess.

Except: how do I write an expression that will format according to the invariant locale?

=Round(6.5-0.5*CDbl(Parameters!LogoWidth.Value)/Parameters!LogoHeight.Value,2).ToString(CultureInfo.InvariantCulture)&"cm"

'CultureInfo' is not declared. It may be inaccessible due to its protection level.

=Round(6.5-0.5*CDbl(Parameters!LogoWidth.Value)/Parameters!LogoHeight.Value,2).ToString(System.Globalization.CultureInfo.InvariantCulture)&"cm"

Value of type 'System.Globalization.CultureInfo' cannot be converted to 'Integer'.

The first error, ok. The second one: wat?

(I think the Real Bug™ is inside ReportViewer itself -- if it's going to use the InvariantCulture to interpret the value then it should use it when calculating the expression too, so that CStr would just work. But that doesn't help me work around this, and there doesn't appear to be any dedicated channel to report bugs to the developers.)

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,821 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,793 questions
{count} votes