The first item in a list-expansion cannot be null
See original GitHub issueWhen generating a client, Autorest sets an empty string to the parameter…
if (entityTypes.Count == 0)
{
_queryParameters.Add(string.Format("Blah={0}", System.Uri.EscapeDataString(string.Empty)));
}
This causes issues on model binding in controllers because now the list has a null item in it. It would be better not to set the parameter at all if the list is empty.
if (blah != null && blah.Count != 0)
{
foreach (var _item in blah)
{
_queryParameters.Add(string.Format("Blahs={0}", System.Uri.EscapeDataString("" + _item)));
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
The first item in a list-expansion cannot be null - Stack Overflow
This is caused by a null value in the @xyzs parameter. When Dapper attempts to expand that to a sql "in" clause it...
Read more >c# - Add the first non-null item from one list to another list
I'm mixed about helpers like this that cannot be named in a way that makes it clear what they do. The signature: public...
Read more >Cannot Expand Null List - Microsoft Power BI Community
I am getting heavily nested data from an api and need to expand all the columns. I followed this guide to stop creating...
Read more >Dapper throws Value cannot be null. Parameter name: con
If you are using Dapper and try to select data into an object and don't have a default constructor the exception. Value cannot...
Read more >Dapper/SqlMapper.cs · Windragon/WLib - Gitee.com
throw new NotSupportedException("The first item in a list-expansion cannot be null");. } if (!isDbString). {. dbType = LookupDbType(item.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue should not be closed!
Why would we want to send a list with a single
null
element?We had a nasty side-effect introduced in our generated code given my colleague updated the client code to contact one of our services and he wondered if the parameter should be set as an empty list or anything else. We should not have to look at the generated code to ensure that the code is correct. It is our fault to not have tested thoroughly after the code was regenerated, but this behavior is very strange.
The suggestion by @zunama was great, in my opinion, but it might diverge from @olydis.
Hmm good question. I did a little bit more digging and found that asp.net has some interesting behavior here:
http://localhost:80/api/values
to a controller that accepts a list, will actually initialize the list parameter and have it empty. This is a bit odd, but it is documented to some degree (Search for “Reference Types”). This is the case in the original repro I linked. Including the “myList” string like so:http://localhost:80/api/values?myList=
will create a list with one null element.http://localhost:80/api/values?testlist[]
. Oddly enough, you will get a different result if you posthttp://localhost:80/api/values?testlist
(no brackets)To repro my second bullet point, simply modify the original AutoRest project by adding a class similar to this:
My original problem was the second bullet point, but this seems to be a bit more convoluted than I thought at first, so I think I’ll switch to passing the object in the body of the request instead :0 since I can just send this:
{ TestList : [] }
in the request body.So I am all set 👍