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.

Exception when using .? operator for nullable fields

See original GitHub issue

Looks like the following will try to create Nullable for Nullable.

    class Scope
    {
        public int? Value { get; set; }
    }
    
    class Program
    {
        static void Main(string[] args)
        {

            var interpreter = new Interpreter();
            var lambda = interpreter.Parse("Scope?.Value", new Parameter("Scope", typeof(Scope)));
            var result = lambda.Invoke(new Scope());
            Console.WriteLine(result);
        }
    }

this will throw an exception

 System.ArgumentException: GenericArguments[0], 'System.Nullable`1[System.Int32]', on 'System.Nullable`1[T]' violates the constraint of type 'T'.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
metoulecommented, Oct 19, 2021

Oh I didn’t see your pull request. There’s actually an existing method that does the check already: GenerateNullableTypeConversion.

0reactions
davideicardicommented, Oct 21, 2021

Thanks @halamah and @metoule for bug report and fix! New version is on the way …

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - System.NullReferenceException when using null ...
The most probable cause is that FirstOrDefault() returns null (as a default value) and thus FirstOrDefault().Name throws exception.
Read more >
(null-forgiving) operator - C# reference
Learn about the C# null-forgiving, or null-suppression, operator that is used to declare that an expression of a reference type isn't null.
Read more >
Null Conditional Operators in C# - ?. and ?[]
When we have nullability enabled, we need to respond to the warnings that come up in our code. This often means performing null...
Read more >
Null Pointer Exception In Java
NullPointerException is thrown when program attempts to use an object reference that has the null value.
Read more >
Understanding null safety
A deep dive into Dart language and library changes related to null safety.
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