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

Submitting code from a C# cell using CSharpKernel.SubmitCodeAsync(string code) doesn't work properly #1378

Closed
2 of 15 tasks
Lawlzee opened this issue May 29, 2021 · 2 comments
Closed
2 of 15 tasks
Assignees
Labels
Area-C# Specific to C# bug Something isn't working

Comments

@Lawlzee
Copy link
Contributor

Lawlzee commented May 29, 2021

Describe the bug

When submitting code from a C# cell, dot net interactive cannot find the submitted code. On the other hand, the submitted code is available in the IntelliSense.

Example

#!csharp

using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.CSharp;

CSharpKernel kernel  = (CSharpKernel)KernelInvocationContext.Current.HandlingKernel.FindKernel("csharp");
await kernel.SubmitCodeAsync("public class TestClass { public int A { get; set; } }");

#!csharp
//IntelliSense can see "TestClass", but dot net interactive can't
TestClass a = new TestClass();

Please complete the following:

Which version of .NET Interactive are you using? There are a few ways to find this out:

  • In a notebook, run the #!about magic command.
.NET Interactive

© 2020 Microsoft Corporation

Version: 1.0.225503+3174511575ce656cd699fc7978d7c9a8ecd4353c

Build date: 2021-05-08T13:04:58.4839798Z

https://github.com/dotnet/interactive
  • At the command line, run dotnet interactive --version.
    1.0.222801+f2ff13b19c29823ac625c235db4ee2343954cc87
  • OS
    • 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
    • Other (please specify)

Screenshots

If applicable, add screenshots to help explain your problem.
image

@Lawlzee
Copy link
Contributor Author

Lawlzee commented Jun 5, 2021

I ended up fixing my problem by simply calling kernel.DeferCommand(new SubmitCode(code)); instead.

@jonsequitur
Copy link
Contributor

When submitting code to a kernel using that same kernel, using DeferCommand is the only supported approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-C# Specific to C# bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants