C#C
C#6mo ago
morry329#

System.ArgumentNullException: Value cannot be null. (Parameter 's')

I wanted to create a new card view inserting images, names and review text etc as per short video attached.
The card view is not created but showed an exception instead:

System.ArgumentNullException: Value cannot be null. (Parameter 's')
   at System.ArgumentNullException.Throw(String paramName)
   at System.Text.Encoding.GetBytes(String s)
   at WebApplication1.Controllers.HomeController.CreateUser(ListingProjects_ver2 obModel) 
`

And this exception seems to point this part in controller

public async Task <JsonResult> CreateUser([Bind("ListingName","Id","ListingReview")]ListingProjects_ver2 obModel) 
    {
        try
        {
            
            if (true)
            {
                
                if (obModel.ListingName == null)
                {
                    return new JsonResult(Problem());
                }

                //this bytecode points to the exception --- ListingImgName is set to null
                byte[] bytesListingImageName = Encoding.ASCII.GetBytes(obModel.ListingImgName);
                Upload(bytesListingImageName);
                _context.ListingVer2_DBTable.Add(obModel); 
           //more codes.. 
`

I have no idea why it gets null. Any insights highly appreciated.

My full code for your reference https://pastesio.com/title-8921
Was this page helpful?