0

I've been trying to use WindowsAPICodePack to get extended file properties but I keep running into the same problem. I'm getting 'An item with the same key has already been added' and I can't understand how and why.

public string Name = "";
public string Date = "";
public string Time = "";
public string FullPath = "";
public string FileName = "";
public int Duration = 0;
public double FrameRate = 0;
public Int64 Size = 0;
public string AMDAudioFile = "";
public string Thumbnail = "";
public string VWidth = "";
public string VHeight = "";
public string VBitrate = "";
public string ABitrate = "";

    var file = ShellFile.FromFilePath(FilePath);

    Duration = int.Parse(TimeSpan.Parse(file.Properties.System.Media.Duration.FormatForDisplay(PropertyDescriptionFormatOptions.None)).TotalSeconds.ToString());     
    Size = Int64.Parse(file.Properties.System.TotalFileSize.FormatForDisplay(PropertyDescriptionFormatOptions.None)); 
    FrameRate = double.Parse(Regex.Replace(file.Properties.System.Video.FrameRate.ValueAsObject.ToString(), @"[^\u0000-\u007F]+", string.Empty));
    VWidth = file.Properties.System.Video.FrameWidth.ValueAsObject.ToString().Trim();
    VHeight = file.Properties.System.Video.FrameHeight.ValueAsObject.ToString().Trim();
    VBitrate = file.Properties.System.Video.EncodingBitrate.ValueAsObject.ToString().Trim();
    ABitrate = Regex.Replace(file.Properties.System.Audio.EncodingBitrate.FormatForDisplay(PropertyDescriptionFormatOptions.None), @"[^\d]", "");
  • 1
    What line of code is throwing the exception? – Luke Oct 06 '22 at 18:33
  • all of them, I've commented them all out and tried doing line by line and all of them give the same error – Marius Van Rooyen Oct 06 '22 at 18:52
  • What do you mean "all of them"? I doubt your field declarations/initializations are throwing this exception, for example. In other words, which is the *first* line to throw the exception? Is it `Duration = int.Parse(...`? – Luke Oct 06 '22 at 18:54
  • Yes I meant all the lines that initializes the values. In this case its Duration, but if I comment the line Duration = out then Size gives the error. – Marius Van Rooyen Oct 06 '22 at 18:56
  • Sounds like it could be a bug or concurrency issues in WindowsAPICodePack? See related: [this question](https://stackoverflow.com/questions/34946748/odd-error-in-shellfile-fromfilepath) and [this question](https://stackoverflow.com/questions/55635429/how-to-fix-argumentexception-in-windows-api-code-pack) – Luke Oct 06 '22 at 19:02
  • thank you, is there something else I could use to get extended file metadata as WindowsAPICodePack is giving me headaches – Marius Van Rooyen Oct 06 '22 at 19:23
  • Unfortunately I don't have any experience there but it looks like there are several different potential solutions outlined here: https://stackoverflow.com/q/220097/6621862 – Luke Oct 06 '22 at 19:26

0 Answers0