i have a code that create a folder and add desktop.ini file and icon.ico file to change folder icon
string dir = path;
string[] lines = { "[.ShellClassInfo]", $"IconResource=Icon.ico,0",
"[ViewState]", "Mode=", "Vid=", "FolderType=Pictures" };
File.WriteAllLines(dir + @"\desktop.ini", lines);
DirectoryInfo dirInfo = new(folderpath + $"\\{name}");
// Set the directory to read-only.
dirInfo.Attributes |= FileAttributes.ReadOnly;
DirectoryInfo dirInfo2 = new(folderpath + $"\\{name}\\desktop.ini");
dirInfo2.Attributes |= FileAttributes.ReadOnly;
DirectoryInfo dirInfo3 = new(folderpath + $"\\{name}\\Icon.ico");
dirInfo3.Attributes |= FileAttributes.ReadOnly;
//refresh folder
SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
now the folder icon is not changing:

but when i go to folder options i see that the icon has been set successfully:

And this:

And when I move the folder from it's place using file explorer the icon appears.
I tried to change folder icon. I expected the icon to appear but it didn't.
to Use It
// Set the custom icon for the folder
Make Sure That Your Icon Size 128 X 128