Q: Getting System.FormatException: Input string was not in a correct format. while trying to upload a file from Angular "System.FormatException: Input string was not in a correct format while trying to upload a file" from my Angular application to asp.net 6 backend api. My client side code goes as follows
 onFileSelected(event: any) {

    this.selectedFile = event.target.files[0];
    const formData = new FormData();
    formData.append('file', this.selectedFile, this.selectedFile.name);    
    debugger;
    const file: File = event.target.files[0];
  
    // const formData = new FormData();
    // formData.append('file', file);
  
    this.http.post(this.BaseUrl + '/api/FileUpload/upload', formData).subscribe(response => {
      console.log('File uploaded successfully');
    });
  }

and server side code as
    [HttpPost("upload")]
    public async Task<IActionResult> Upload(IFormFile file)
    {
        // Retrieve the connection string from configuration
        var connectionString = _storageConnectionString;

        // Create a BlobServiceClient object
        var blobServiceClient = new BlobServiceClient(connectionString);

        // Get a reference to the container where you want to upload the file
        var containerName = "mycontainer";
        var containerClient = blobServiceClient.GetBlobContainerClient(containerName);

        // Create a unique name for the blob
        var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);

        // Upload the file to Azure Storage
        var blobClient = containerClient.GetBlobClient(fileName);
        await blobClient.UploadAsync(file.OpenReadStream(), true);

        // Return a response to the client
        return Ok();
    }

I am not able to get any solution for the issue.
Turns out the code never reaches the back end as I never get a debugger hit in the back end, whereas while trying to test the method from swagger, it works fine.

A: For testing purpose, I created an Angular project with .net core web api. Here is the code of web page:
<input type="file" class="file-input" (change)="onFileSelected($event)" #fileUpload>
<div class="file-upload">
    {{fileName || "No file uploaded yet."}}
    <button mat-mini-fab color="primary"class="upload-btn"       
      (click)="fileUpload.click()">
        click
    </button>
</div>

and here is the code for uploading files action:
fileName = '';
constructor(private http: HttpClient) {}
 onFileSelected(event) { 
    const file:File = event.target.files[0];
    if (file) {
        this.fileName = file.name; 
        const formData = new FormData();
        formData.append("thumbnail", file);
        const upload$ = this.http.post("https://localhost:7212/home/upload", formData);
        upload$.subscribe();
        }
    }

Here is the code from api side:
[HttpPost("upload")]
public async Task<IActionResult> Upload()//IFormFile file
{   
    var file = Request.Form.Files[0];
    return Ok();
}

At last is my test result:

You can see from the screenshot, the file has been uploaded successfully.

A: I never managed to get the IFormFile to work, I guess that should be past of a class that is used.
My first Google result looks like code that I used in the past. This is verified to work.
The part you need to change is the way you read the file in dotnet core.
[HttpPost, DisableRequestSizeLimit]
public async Task<IActionResult> Upload()
{
    try
    {
        var formCollection = await Request.ReadFormAsync();
   
        var file = formCollection.Files.First();


