© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•8mo ago•
2 replies
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) 
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.. 
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
Pastesio.com
title - Pastesio.com
title - Pastesio.com
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

[ASP.NET] ArgumentNullException: Value cannot be null. (Parameter 'viewData')
C#CC# / help
2y ago
Entity Framework 6 error - 'Value cannot be null. Parameter name: entitySet'
C#CC# / help
2y ago
❔ Dependency injection fails-Value cannot be null
C#CC# / help
3y ago