Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TargetInvocationException when .Update()ing a .DisplayTable() with a string #3806

Open
3 of 17 tasks
Allon-Guralnek opened this issue Jan 9, 2025 · 0 comments
Open
3 of 17 tasks
Labels
Area-Formatting Data and object formatting as HTML and plaintext bug Something isn't working

Comments

@Allon-Guralnek
Copy link

Describe the bug

In Polyglot Notebooks, after displaying a table using .DisplayTable(), then calling .Update() on the returned DisplayValue object, passing a simple string as the argument, an exception is thrown. This does not happen when updating to an array, or when updating a non-Table element.

"Hello".Display().Update("Goodbye"); // Works
"Hello".DisplayTable().Update(new[] { "Goodbye" }); // Works
"Hello".DisplayTable().Update("Goodbye") // Throws

I expect all three to work. Although an obvious deficiency in the API is that is no way to update a DisplayValue as a table, but that's a separate issue (perhaps there should be a .UpdateTable() method?).

The following exception is thrown:

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidCastException: Unable to cast object of type 'Microsoft.DotNet.Interactive.Formatting.NonDestructurer' to type 'Microsoft.DotNet.Interactive.Formatting.Destructurer`1[System.String]'.
at Microsoft.DotNet.Interactive.Formatting.Destructurer`1.GetOrCreate() in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Destructurer{T}.cs:line 105
at Microsoft.DotNet.Interactive.Formatting.Csv.CsvFormatter`1.Create() in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Csv\CsvFormatter{T}.cs:line 39
at InvokeStub_CsvFormatter`1.Create(Object, Object, IntPtr*)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
--- End of inner exception stack trace ---
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
at Microsoft.DotNet.Interactive.Formatting.FormatterMapByType.<GetOrCreateFormatterForType>b__4_0(Type t) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\FormatterMapByType.cs:line 27
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.DotNet.Interactive.Formatting.Csv.CsvFormatter.<>c.<.cctor>b__6_0(IEnumerable seq, FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Csv\CsvFormatter.cs:line 17
at Microsoft.DotNet.Interactive.Formatting.Csv.CsvFormatter`1.Format(T value, FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Csv\CsvFormatter{T}.cs:line 21
at Microsoft.DotNet.Interactive.Formatting.Formatter.<>c__DisplayClass52_0.<TryFindPreferredFormatter>b__4(Object value, FormatContext context) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Formatter.cs:line 649
at Microsoft.DotNet.Interactive.Formatting.Formatter`1.FormatTo(T obj, FormatContext context, String mimeType) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive.Formatting\Formatter{T}.cs:line 68
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.SelectArrayIterator`2.Fill(ReadOnlySpan`1 source, Span`1 destination, Func`2 func)
at System.Linq.Enumerable.SelectArrayIterator`2.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.DisplayedValue.Update(Object updatedValue) in D:\a\_work\1\s\src\Microsoft.DotNet.Interactive\DisplayedValue.cs:line 32
at Submission#25.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

Please complete the following:

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

  • OS
    • Windows 11
    • Windows 10
    • macOS
    • Linux (Please specify distro)
    • iOS
    • Android
  • Browser
    • Chrome
    • Edge
    • Firefox
    • Safari
  • Frontend
    • Jupyter Notebook
    • Jupyter Lab
    • nteract
    • Visual Studio Code
    • Visual Studio Code Insiders
    • Visual Studio
    • Other (please specify): Polyglot Notebooks 1.0.5568010 on Visual Studio Code 1.96.2

Screenshots

If applicable, add screenshots to help explain your problem.

@jonsequitur jonsequitur added bug Something isn't working Area-Formatting Data and object formatting as HTML and plaintext labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Formatting Data and object formatting as HTML and plaintext bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants