question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Culture non invariant cause crash on save

See original GitHub issue

description

running a simple create workbook, worksheet and save crashes for non invariant cultures.

repro

using System;
using System.Globalization;
using System.IO;
using System.Threading;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("it");

            var wb = new ClosedXML.Excel.XLWorkbook();
            var ws = wb.Worksheets.Add("test1");


            wb.SaveAs(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.xlsx"));
        }
    }
}

workaround

force a thread “en” culture on the workbook usage

stacktrace

System.ApplicationException occurred
  HResult=0x80131600
  Message=The attribute 'left' has invalid value '0.75'. The MaxExclusive constraint failed. The value must be less than 49. in /x:worksheet[1]/x:pageMargins[1]
The attribute 'right' has invalid value '0.75'. The MaxExclusive constraint failed. The value must be less than 49. in /x:worksheet[1]/x:pageMargins[1]
The attribute 'top' has invalid value '0.75'. The MaxExclusive constraint failed. The value must be less than 49. in /x:worksheet[1]/x:pageMargins[1]
The attribute 'footer' has invalid value '0.75'. The MaxExclusive constraint failed. The value must be less than 49. in /x:worksheet[1]/x:pageMargins[1]
  Source=ClosedXML
  StackTrace:
   at ClosedXML.Excel.XLWorkbook.Validate(SpreadsheetDocument package) in C:\Git\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 90
   at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath, SpreadsheetDocumentType spreadsheetDocumentType, Boolean validate) in C:\Git\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 105
   at ClosedXML.Excel.XLWorkbook.SaveAs(String file, Boolean validate) in C:\Git\ClosedXML\ClosedXML\Excel\XLWorkbook.cs:line 479
   at ClosedXML.Excel.XLWorkbook.SaveAs(String file) in C:\Git\ClosedXML\ClosedXML\Excel\XLWorkbook.cs:line 461
   at ConsoleApp2.Program.Main(String[] args) in C:\Users\loren\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2\Program.cs:line 18

notes

I think some double.Parse(str_val) should replace with double.Parse(str_val, CultureInfo.InvariantCulture)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chris-denningcommented, Mar 20, 2017

Yes, the develop branch solves the problem for me.

I removed my workaround and verified that downloading a spreadsheet in German gave the original error. I then rebuilt my solution with the locally-built DLL from develop instead of the NuGet package, and was able to download the spreadsheet okay.

Thanks

0reactions
igiturcommented, Mar 20, 2017

The PR has been merged into the develop branch. I’d appreciate it if you could pull the develop branch and check that it solves your issue. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Saving causes CTD - No discernable pattern, and I have ...
To make it short, lately, whenever I try to manually save or quicksave, the sound cuts off and the game CTD... I was...
Read more >
What would cause setting CurrentCulture to crash?
I agree with Alexei, InvariantCulture is a synthetic culture and is likely to cause trouble on a machine that boots XP. Changing the...
Read more >
Skyrim Suddenly Crashes When Saving Game Everytime
The crashes are caused by a single plugin, a mod that I actually made myself. It's a merge of many different armors and...
Read more >
Crash on save
The crashing when quicksaving can be caused by backup or sync programs, if they lock the original save.
Read more >
no save / crashing fix - Crusader Kings II - GameFAQs
When the game exceeds alotted memory, it can't save anymore. ... Whatever your path, shifting culture is tricky but not impossible to achieve....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found