Try change:
item.Update(); //Apply the change
to item.SystemUpdate(); //Apply the change
or try this code (tested and a little edited):
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
{
UpdateListItem();
}
}
public static void UpdateListItem()
{
var siteURL = "https://sharepoint16.dev.cz/tweb";
var listName = "Set";
var listItemId = 1;
var createdBy = "[email protected]";
var modifiedBy = "[email protected]";
ClientContext context = new ClientContext(siteURL);
List list = context.Web.Lists.GetByTitle(listName);
ListItem item = list.GetItemById(listItemId);
FieldUserValue author = GetUsers(context, createdBy);
FieldUserValue editor = GetUsers(context, modifiedBy);
item["Author"] = author;
item["Editor"] = editor;
item.Update();
context.ExecuteQuery();
}
//get user by username
public static FieldUserValue GetUsers(ClientContext clientContext, string UserName)
{
FieldUserValue userValue = new FieldUserValue();
User newUser = clientContext.Web.EnsureUser(UserName);
clientContext.Load(newUser);
clientContext.ExecuteQuery();
userValue.LookupId = newUser.Id;
return userValue;
}
}
}
Before:

After:

If its not working for you, make sure you have appropriate permissions (Site Collection Administrator or Site Admin) and you are set createdBy and modifiedBy variables with correct login name.