Save PreviewTexture in ScriptableObject

Hello Coders

I do want to save the preview of a prefab in a Texture2D in a scriptableObject. My current code does not work. It gets the preview, but it is not able to save it in the sriptableObject.

public class AnyObject : ScriptableObject
{
    public Texture2D previewTexture;
    public GameObject prefab;
  
    public void SetPreviewTexture()
    {
        previewTexture = AssetPreview.GetAssetPreview(prefab);
    }  
}

Thanks for help

Does line 7 even compile? What does that function return?

Sorry I was writing freehand. Clear it is Public void

No Answer here?