Pulsar4xDevs / Pulsar4x

A Fan work recreation of Aurora4x in C#
Other
159 stars 67 forks source link

Unhandled Exception on initial launch - Loading Preferences #372

Closed DifferentLevelDan closed 10 months ago

DifferentLevelDan commented 10 months ago

System.IO.IOException: 'The process cannot access the file 'C:\Users\Diffe\AppData\Roaming\Pulsar4X\Pulsar4X\preferences.ini' because it is being used by another process.'

` if(!File.Exists(preferencesPath)) { File.Create(preferencesPath); }

        IConfiguration preferences = new ConfigurationBuilder().AddIniFile(preferencesPath).Build();`

Exception is on the IConfiguration preferences = new ConfigurationBuilder().AddIniFile(preferencesPath).Build(); line.

Specifically, File.Create returns a FileStream that is not properly disposed before trying to be accessed by the ConfigurationBuilder.