C1PrintDocument breaks after upgrading from version 2023v3(631) to 2024v1(657)

Posted by: hrvoje.zirdum on 17 June 2024, 7:32 am EST

    • Post Options:
    • Link

    Posted 17 June 2024, 7:32 am EST

    Hi!

    I’m using :Net Framework 4.8 Controls.

    After upgrading from version 2023v3(631) to 2024v1(657) next line code doesn’t work anymore:

    double yMM;

    yMM = printDoc.PageLayout.PageSettings.TopMargin + 17;

    It throws this error:

    Exception: $exception {“Unsupported unit of measurement: [Default].”} System.Exception

    Stack trace

    at C1.C1Preview.Utils.ConvertUnits(Double value, UnitTypeEnum from, UnitTypeEnum to, Single fromDpi, Single toDpi)

    at C1.C1Preview.Unit.ConvertUnit(UnitTypeEnum destUnitType)

    at C1.C1Preview.Unit.op_Addition(Unit u1, Unit u2)

    I found a workaround which does the same and does not throw error:

    double yMM;

    yMM = printDoc.PageLayout.PageSettings.TopMargin;

    Ymm += 17;

    Can You please check what gone wrong between versions 2023v3(631) and 2024v1(657).

    Thank You.

    Regards,

    Hrvoje

  • Posted 18 June 2024, 7:33 am EST

    Hi Hrvoje,

    We tested your code

    double yMM;
    yMM = printDoc.PageLayout.PageSettings.TopMargin + 17;

    with both the .631 and .657 versions of C1PrintDocument, and both throw an error because it is not the correct way to add Unit objects. The correct way to add Unit objects is to either add two Unit objects or use their Value property. Please see the attached sample project for reference.

    If you have a different implementation that works with .631 and shows error with .657, please update the attached project to reproduce the issue, so we can investigate further and assist you better.

    Attachment: UnitOperationTest.zip

    Thanks, and Best Regards,

    Kartik

  • Posted 18 June 2024, 8:00 am EST - Updated 18 June 2024, 8:11 am EST

    Hi,

    now that I’ve seen your example and compared it to my code, I think I’ve figured out where the problem is. Your code works, but if you first set/initialize LeftMargin and then somewhere in code you do add operation, then it will break. I have it set like that in my code for years and it worked before this version.

    I modified your example. This is code which breaks:

    var printDoc = new C1PrintDocument();

    printDoc.DefaultUnit = UnitTypeEnum.Mm;

    printDoc.ResolvedUnit = UnitTypeEnum.Mm;

    printDoc.PageLayout.PageSettings.LeftMargin = 35;

    Unit unit = printDoc.PageLayout.PageSettings.LeftMargin + new Unit(17, UnitTypeEnum.Mm);

    double value = printDoc.PageLayout.PageSettings.LeftMargin.Value + 17;

    MessageBox.Show($“Unit = {unit}{Environment.NewLine}Value = {value}”);

    Regards,

    Hrvoje

  • Posted 19 June 2024, 4:17 am EST

    Hi Hrvoje,

    Thank you for sharing the updated code.

    We tested your code with version .631 and found it doesn’t work because, in earlier versions, the addition of two Unit objects was not allowed. This is because the + operator was not implemented in the Unit struct. The attached screenshot (631.png) illustrates this issue.

    In the latest .657 release, the + and - operators were implemented, allowing the addition and subtraction of two Unit objects, provided the Units property of any object is not set to Default. If it is set to Default, you will encounter the exception shown in the attached screenshot (Exception657.png).

    To fix this exception in your code, you can set the margins with the “mm” units instead of “default” units. Please see the updated sample project for reference (UnitOperationTest_Updated.zip).


    If the issue persists, please update the sample project with your code so that it works with version .631 but breaks with version .657. This will allow us to investigate the cause of the problem.

    Attachments:

    UnitOperationTest_Updated.zip

    UnitOperationScreenshots.zip

    Thanks, and Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels