To fix a null-ref error you need to know
1. What is actually "null"
2. Why that variable is not being set to something
First: Check objfile.files.Length
objfile is an object so could be null
files is a property of the that's an array. It's possible for this to be null
Length is a scalar (a number) and can't be null
So the code is trying to get the
Length
of
files
of
objfile
. If
files
is null you're trying to get
objfile
of "null". If files is null you're trying to get Length of null.
So to protect your code you can do
int length = 0;
if (objfile != && objfile.files != null)
length = objfile.files.Length;
or
int length = objfile?.files?.Length ?? 0;
Second: stopping the null-ref happening
This you can't do. If the upload didn't work, if there were errors, if there were simply no files uploaded, then you'll see null. Except nulls on
every variable that can be null. It'll get tedious. Welcome to being a developer.