Skip to content

Commit 2bd5a14

Browse files
authored
Fix: Fixed InvalidOperationException in GetSystemFilePropertiesAsync (#16176)
1 parent 3e31b2b commit 2bd5a14

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Files.App/ViewModels/Properties/Items/CombinedFileProperties.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public CombinedFileProperties(
1717

1818
public async Task GetSystemFilePropertiesAsync()
1919
{
20-
var queries = await Task.WhenAll(List.AsParallel().Select(async item => {
20+
var queries = await Task.WhenAll(List.AsParallel().Select(async item =>
21+
{
2122
BaseStorageFile file = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathAsync(item.ItemPath));
2223
if (file is null)
2324
{
@@ -27,10 +28,13 @@ public async Task GetSystemFilePropertiesAsync()
2728

2829
var list = await FileProperty.RetrieveAndInitializePropertiesAsync(file);
2930

30-
list.Find(x => x.ID == "address").Value =
31-
await LocationHelpers.GetAddressFromCoordinatesAsync((double?)list.Find(
32-
x => x.Property == "System.GPS.LatitudeDecimal").Value,
33-
(double?)list.Find(x => x.Property == "System.GPS.LongitudeDecimal").Value);
31+
var latitude = list.Find(x => x.Property == "System.GPS.LatitudeDecimal")?.Value as double?;
32+
var longitude = list.Find(x => x.Property == "System.GPS.LongitudeDecimal")?.Value as double?;
33+
var addressItem = list.Find(x => x.ID == "address");
34+
35+
if (latitude.HasValue && longitude.HasValue && addressItem != null)
36+
addressItem.Value = await LocationHelpers.GetAddressFromCoordinatesAsync(latitude.Value, longitude.Value);
37+
3438

3539
return list
3640
.Where(fileProp => !(fileProp.Value is null && fileProp.IsReadOnly))

0 commit comments

Comments
 (0)