Editor issue

I’m overwriting a file in the Unity editor version 2020.3.38 using a file stream and a stream writer. Right after that, I refresh the AssetDatabase. I’m actually updating a shader through a C# script, and the shader needs to be refreshed in the database. This is my piece of code:

FileStream fstream = new FileStream(bufferPath, FileMode.Truncate, FileAccess.Write);
StreamWriter swriter = new StreamWriter(fstream);
swriter.WriteLine(content);
swriter.Dispose();
fstream.Dispose();

AssetDatabase.Refresh();

Right after the database is refreshed, I’ve got these two errors:

  1. GetLoadedImportedAssetsAndArtifactIDs called with an invalid artifactID
    UnityEditor.AssetDatabase:Refresh()

  2. Assertion failed on expression: it->second.IsValid()
    UnityEditor.AssetDatabase:Refresh()

Any ideas on what I can do to get rid of them? Thanks a bunch!