Texture2D.LoadImage() Not working

Everytime the user uploads a local image into the game, it gives the following:

ArgumentNullException: Value cannot be null.
Parameter name: tex

The path finder works, the byte array works with the path correctly, its solely the LoadImage method that is failing. I even used the exact example in the Texture2D.LoadImage API page and it failed with the same error. This is my file:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using SFB;

public class PlayerCard : MonoBehaviour
{
private Texture2D texture;
public Button yourButton;

void Start()
{
Button btn = yourButton.GetComponent<Button>();
btn.onClick.AddListener(imageUpload);
}
void Update()
{

}
void imageUpload()
{
var path = StandaloneFileBrowser.OpenFilePanel("Open File", "", "png", false);
var bytes = File.ReadAllBytes(path[0]);
texture.LoadImage(bytes);
GetComponent<Image>().sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2());
}
}

I dont know if im hella stupid here missing something but I have tested a series of things and I keep coming back to this.

Are you sure the exception is thrown in there? texdoesn’t exist in this code so it actually shouldn’t compile.

There might be an issue that you forgot to provide an optional argument to one of the functions but that seems unlikely to me.

Another issue could be that path is an invalid string, bytes is therefore null or empty and texture.LoadImage(...) gets null provided as an argument. Did you check the path is valid using the debugger or logging?