Access violation when setting Windows Tags

12 views Asked by At

I have a C# all platforms console app to set Windows tags. It is created using VS2022 with code as shown below

using Microsoft.WindowsAPICodePack.Shell;
class TestClass
{
   static void Main(string[] args)
   {
    // Display arguments.
    Console.WriteLine(args[0] + " " + args[1]);
    string sFile = args[0];
    string sTagString = args[1];
    
    var shellFile = ShellFile.FromFilePath(sFile);
    string[] sTags = sTagString.Split(';');
        
    shellFile.Properties.System.Keywords.AllowSetTruncatedValue = true;
    shellFile.Properties.System.Keywords.Value = sTags;
    shellFile.Dispose();

    }
}

When I run it with arguments "C:\Users\simon\Pictures\Camera Trap\100RECNX\RCNX0025.JPG" NewTag

it crashes with an access violation at the line

shellFile.Properties.System.Keywords.Value = sTags;

Can anyone suggest how to avoid this problem?

0

There are 0 answers