why are "The associated scripts can not be loaded" errors seemingly being thrown at random for .asset files

HI , This error seems to occur at random . Once I create the asset ,everything is fine . Sometime when there is a assembly reload I get this error and sometime I don’t get the error , heck sometimes i get the error then it goes away … same thing whenever i close and restart Unity.

Here is my code for creating this asset where Comp is the Class which inherits from ScriptableObject

 var asset = ScriptableObject.CreateInstance<Comp>();
AssetDatabase.CreateAsset(asset,"Assets/NewFolder/Comp.asset");
                                                          
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

49877-comp5.jpg

The Comp class was part of another script. I created a new Comp.cs script and place the Comp class in it.

It seems that not having the class name be the same as the script name will cause this problem.