While saving photo file Properties, it throws Argument Exception (The parameter is incorrect.) on SavePropertiesAsync() call -

SmilingMoon 981 Reputation points
2020-12-31T21:13:33.487+00:00

While saving photo file Properties, it throws Argument Exception on SavePropertiesAsync() call for only certain values.
The code below tries to copy all properties supported, but it throws exception only certain ones.
e.g. System.Photo.FocalLength: 5.9 => On save, it throws the exception. I confirmed it's double value type and all look good, but it throws error.

Total 17 values cause the same issue.

Error: key=System.Photo.FocalLength, value type = Double, exception= The parameter is incorrect.
Error: key=System.Image.ResolutionUnit, value type = Int16, exception= The parameter is incorrect.
Error: key=System.GPS.Latitude, value type = Double[], exception= The parameter is incorrect.

All 17 errors are out of numeric types.

public static async Task CopyProperties(StorageFile sourceFile, StorageFile copyToFile)
        {
            ImageProperties imgPs = await sourceFile.Properties.GetImagePropertiesAsync();
            ImageProperties imgPt = await copyToFile.Properties.GetImagePropertiesAsync();


var propList = GetPhotoPropertyList(); //get all key list of Photo Metadata Policies
                IDictionary<string, object> photoPropertyDic = await sourceFile.Properties.RetrievePropertiesAsync(propList);

                foreach (var key in photoPropertyDic.Keys)
                {
                    App.l($"{key}: {photoPropertyDic[key]}", 3);
                    var value = photoPropertyDic[key];
                    if (value == null) continue;

                    var keyvalue = new KeyValuePair<string, object>(key, value); 

                    var propListToSave = new List<KeyValuePair<string, object>>();
                    propListToSave.Add(keyvalue);

                    try
                    {
                        await imgPt.SavePropertiesAsync(propListToSave); //Test code to save individually to see which one causes an error.
                    } 
                    catch(Exception ex)
                    {
                        App.l($"Error: key={key}, value type = {value.GetType().Name}, exception= {ex.Message}", 3); //Log error
                    }
                }

GetPhotoPropertyList method - include only partial for easy testing.

        private static List<string> GetPhotoPropertyList()
        {
            var lst = new List<string>();

            lst.Add("System.ApplicationName"); //The photo metadata policy for the System.ApplicationName property.
            lst.Add("System.Author"); //The photo metadata policy for the System.Author property.
            lst.Add("System.Photo.FocalLength"); //The photo metadata policy for the System.Photo.FocalLength property.
 lst.Add("System.GPS.Latitude"); //The photo metadata policy for the System.GPS.Latitude property.
            //lst.Add("System.GPS.Latitude"); //The property proxy for the System.GPS.Latitude photo metadata policy.
            lst.Add("System.GPS.LatitudeRef"); //The photo metadata policy for the System.GPS.LatitudeRef property.

            return lst;
        }
Developer technologies Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Yan Gu - MSFT 2,676 Reputation points
    2021-01-04T03:12:58.28+00:00

    Hello,

    Welcome to Microsoft Q&A.

    I test your code with the image provide by you, and the exception is reproduced. I searched for the relative document and found that the file properties with causes an exception has a value IsInnate = true in typeInfo, such as System.ApplicationName, System.Photo.FocalLength, System.GPS.Altitude. If a property has a value IsInnate = true in typeInfo, then the property may not be changed because the property is innate. You need to exclude the file properties which contains a value IsInnate = true in typeInfo when you use RetrievePropertiesAsync method.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.