dotnet / interactive

.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
MIT License
2.91k stars 389 forks source link

Exception when displaying ArraySegment with null value #3773

Open jianyunliu opened 5 days ago

jianyunliu commented 5 days ago

Describe the bug

There is exception when displaying ArraySegment with null value. The other enumerable values are just fine with null - like List, byte[] and etc. This is one code example to repro the issue:

ArraySegment<byte> arraySeg = null;
arraySeg

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The underlying array is null. at Microsoft.DotNet.Interactive.Formatting.EnumerableExtensions.TakeAndCountRemaining[T](IEnumerable1 source, Int32 count, Boolean forceCountRemainder) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\EnumerableExtensions.cs:line 17 at Microsoft.DotNet.Interactive.Formatting.PlainTextFormatter.JoinGeneric[T](IEnumerable1 seq, TextWriter writer, FormatContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\PlainTextFormatter.cs:line 350 at InvokeStub_Action3.Invoke(Object, Span1) at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) --- End of inner exception stack trace --- at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Delegate.DynamicInvokeImpl(Object[] args) at Microsoft.DotNet.Interactive.Formatting.PlainTextFormatter1.<>c__DisplayClass8_0.<CreateForAnyEnumerable>b__5(T value, FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\PlainTextFormatter{T}.cs:line 103 at Microsoft.DotNet.Interactive.Formatting.PlainTextSummaryFormatter.<>c.<.cctor>b__7_2(IEnumerable obj, FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\PlainTextSummaryFormatter.cs:line 42 at Microsoft.DotNet.Interactive.Formatting.Formatter1.FormatTo(T obj, FormatContext context, String mimeType) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Formatter{T}.cs:line 68 at lambda_method530(Closure, FormatContext, Object, String) at Microsoft.DotNet.Interactive.Formatting.Formatter.ToDisplayString(Object obj, String mimeType) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Formatter.cs:line 277 at Microsoft.DotNet.Interactive.Formatting.HtmlFormatter1.<>c__DisplayClass8_5.<CreateTreeViewFormatterForAnyObject>b__8(FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\HtmlFormatter{T}.cs:line 280 at Microsoft.DotNet.Interactive.Formatting.HtmlTag.WriteTo(FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\HtmlTag.cs:line 103 at Microsoft.DotNet.Interactive.Formatting.PocketView.Write(IReadOnlyList1 args, FormatContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\PocketView.cs:line 220 at Microsoft.DotNet.Interactive.Formatting.PocketView.Write(IReadOnlyList1 args, FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\PocketView.cs:line 216 at Microsoft.DotNet.Interactive.Formatting.PocketView.Write(IReadOnlyList1 args, FormatContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\PocketView.cs:line 216 at Microsoft.DotNet.Interactive.Formatting.PocketView.WriteTo(FormatContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\PocketView.cs:line 283 at Microsoft.DotNet.Interactive.Formatting.HtmlFormatter1.<CreateTreeViewFormatterForAnyObject>g__BuildTreeView|8_3(T source, FormatContext context, ValueTuple2[] rows) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\HtmlFormatter{T}.cs:line 294 at Microsoft.DotNet.Interactive.Formatting.HtmlFormatter1.<>c__DisplayClass8_0.<CreateTreeViewFormatterForAnyObject>b__2(T instance, FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\HtmlFormatter{T}.cs:line 266 at Microsoft.DotNet.Interactive.Formatting.HtmlFormatter1.Format(T value, FormatContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\HtmlFormatter{T}.cs:line 54 at Microsoft.DotNet.Interactive.Formatting.TypeFormatter1.Microsoft.DotNet.Interactive.Formatting.ITypeFormatter.Format(Object instance, FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\TypeFormatter{T}.cs:line 23 at Microsoft.DotNet.Interactive.Formatting.HtmlFormatter1.Format(T value, FormatContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\HtmlFormatter{T}.cs:line 54 at Microsoft.DotNet.Interactive.Formatting.Formatter1.FormatTo(T obj, FormatContext context, String mimeType) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Formatter{T}.cs:line 68 at lambda_method530(Closure, FormatContext, Object, String) at Microsoft.DotNet.Interactive.Formatting.Formatter.ToDisplayString(Object obj, String mimeType) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Formatter.cs:line 277 at Microsoft.DotNet.Interactive.FormattedValue.<>c__DisplayClass12_0.<CreateManyFromObject>b__0(String mimeType) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive\FormattedValue.cs:line 49 at System.Linq.Enumerable.SelectArrayIterator2.Fill(ReadOnlySpan1 source, Span1 destination, Func2 func) at System.Linq.Enumerable.SelectArrayIterator2.ToArray() at Microsoft.DotNet.Interactive.FormattedValue.CreateManyFromObject(Object value, String[] mimeTypes) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive\FormattedValue.cs:line 47 at Microsoft.DotNet.Interactive.CSharp.CSharpKernel.Microsoft.DotNet.Interactive.IKernelCommandHandler.HandleAsync(SubmitCode submitCode, KernelInvocationContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive.CSharp\CSharpKernel.cs:line 339 at Microsoft.DotNet.Interactive.Kernel.HandleAsync(KernelCommand command, KernelInvocationContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive\Kernel.cs:line 365 at Microsoft.DotNet.Interactive.KernelCommandPipeline.b__60(KernelCommand command, KernelInvocationContext context, KernelPipelineContinuation ) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive\KernelCommandPipeline.cs:line 60 at Microsoft.DotNet.Interactive.KernelCommandPipeline.SendAsync(KernelCommand command, KernelInvocationContext context) in D:\a_work\1\s\src\Microsoft.DotNet.Interactive\KernelCommandPipeline.cs:line 41

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ):

Screenshots

Image