question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueProvider array of strings having a null value is processed wrong

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

public class SomeValueProvider : IValueProvider
{
  public bool ContainsPrefix(string prefix)
  {
    return true;
  }
  public ValueProviderResult GetValue(string key)
  {
    return new ValueProviderResult(new string[] { "a", "b", null, "c" });
  }
}

Controller method

public async Task<IActionResult> Index(List<string> list)
{
  await Task.Yield();

  // Returned list "a", b", "b",  "c"
  // Expected list "a", b", null, "c"

  return Content("<pre>returns "+string.Join(",", list)+ " expected a,b,,c</pre>", "text/html");
}

Expected Behavior

When using an Array of strings having null values in it, it must not skip, nor must it repeat previous element values.

Steps To Reproduce

The bug is visible in this small test project:

https://github.com/alphons/ValueProviderBug

Exceptions (if any)

No exceptions, bug procudes wrong processing of Array elements having null values.

.NET Version

6.0.102

Anything else?

ASP.NET 6.0.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
alphonscommented, Apr 7, 2022

To elaborate on the null values, and a read-world (?!) example … Maybe in forms or querystring request strings null has no much of a meaning, but when posting json data to a MVC controller, and binding its parameters, we have to use the famous ValueProviderResult. And string.Empty has a complete different meaning then null. Turning string.Empty into null has also devastating effects, mostly gaining nothing, i call it a weird feature or artifact.

Here is some of my javascript code, which posts json to a controller. It can be bind to method parameters, if we all want it 😉 netproxy is a simple javascript function to make json post calls to an url. Source …/wwwroot/Scripts/netproxy.js

 netproxy("./api/ComplexListNullableDouble", { list: [1.2, 3.4, 5.6, null, 7.8] });

To this controller method:

[HttpPost]
[Route("~/api/ComplexListNullableDouble")]
public async Task<IActionResult> ComplexListNullableDouble(List<double?> list)
{
	await Task.Yield();
	return Ok();
}

Results in the repeat bug: 1.2, 3.4, 5.6, 5.6, 7.8

Concluding, for having nullable values, this means also nullable strings, but also empty strings, and they are, clearly, not the same.

0reactions
TanayParikhcommented, Apr 6, 2022

Let’s keep this issue open for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Value Provider Path null issue GXT 3.0 - java
In GXT 3.0, valueProvider, I have a null pointer exception issue. I have this code snippet, @Path("xxx.yyy") ValueProvider<User, String> zzz() ...
Read more >
Model Binding in ASP.NET Core
The sample includes a value provider and factory example that gets values ... the model property has been set to null or a...
Read more >
How to fix the null index array error in powershell?
I am trying to run a PowerShell script which is taking three input PAT, organization and connection string of the database.
Read more >
Avoid Check for Null Statement in Java
Learn several strategies for avoiding the all-too-familiar boilerplate conditional statements to check for null values in Java.
Read more >
Creating classic Dataflow templates
You can use isAccessible() to check if the value of a ValueProvider is available. If you call get() before pipeline execution, Apache Beam...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found