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

NullReferenceException #40

Closed
Jamaxack opened this issue Sep 12, 2021 · 14 comments
Closed

NullReferenceException #40

Jamaxack opened this issue Sep 12, 2021 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@Jamaxack
Copy link

Jamaxack commented Sep 12, 2021

Version

C# REPL 0.3.3

What happened?

Billion dollar exception(NullReferenceException)

Windows specifications:
Edition Windows 10 Pro
Version 21H1
OS build 19043.1165
Experience Windows Feature Experience Pack 120.2212.3530.0

System type 64-bit operating system

Steps to reproduce:

  • dotnet tool install -g csharprepl
  • charprepl
  • type any key. example: f

image

@Jamaxack Jamaxack added the bug Something isn't working label Sep 12, 2021
@waf
Copy link
Owner

waf commented Sep 12, 2021

Oof, thanks for reporting! Is this reproducible every time you start csharprepl?

I have the exact same Windows specifications that you have (down to the exact same point number), and I'm unable to reproduce it. If you press "Enter" as the first key, do you get a different stack trace?

EDIT: Could you please also share the output of dotnet --info ?

@Jamaxack
Copy link
Author

Jamaxack commented Sep 12, 2021

Thanks for the prompt response. Yes pressing the "Enter" as a first key also gives an error:
132987106-f133b8a3-e8c4-4834-84cd-472b45d5c80d

@waf
Copy link
Owner

waf commented Sep 12, 2021

I just set up my computer's .NET SDK installation to match yours, and still can't reproduce the issue. From the stack traces, it's pretty clear that the Roslyn Workspace is failing to get built correctly, but it's odd that it's silently failing and we then get a NullReferenceException.

I'll set up some more logging to better understand the issue; it should be ready in a few days.

In the meantime, could you please verify if installing .NET 5 resolves the issue? CSharpRepl should run just fine on the .NET 6 previews, but it'd help to rule out the possibility of something unexpected in the previews.

@waf
Copy link
Owner

waf commented Sep 15, 2021

@Jamaxack when you have a chance, could you please update to the prerelease version of CSharpRepl? The only thing different in the prerelease is that it now has a --trace option that will help troubleshoot this.

You can update by running dotnet tool update -g csharprepl --version 0.3.4-rc

Then, please start csharprepl with the trace flag: csharprepl --trace

After you recreate the NullReferenceException, please share the csharprepl-tracelog-*.txt file. It's written to the current working directory.

image

Thanks! I appreciate you helping out with this.

@Jamaxack
Copy link
Author

Thanks for the detailed steps. I updated to the 0.3.4-rc version and started with the trace flag.

Here is the logs for pressing 'enter' first and then restarting again and pressing 'c'.

2021-09-15T14:12:06 - Trace session starting
2021-09-15T14:12:06 - Starting background initialization
2021-09-15T14:12:07 - Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at CSharpRepl.Services.Roslyn.RoslynServices.IsTextCompleteStatementAsync(String text) in C:\Users\will.fuqua\source\repos\CSharpRepl\CSharpRepl.Services\Roslyn\RoslynServices.cs:line 143
   at CSharpRepl.PrettyPromptConfig.PromptConfiguration.<>c__DisplayClass0_0.<<Configure>g__forceSoftEnterHandler|2>d.MoveNext() in C:\Users\will.fuqua\source\repos\CSharpRepl\CSharpRepl\PrettyPromptConfig\PromptConfiguration.cs:line 51
--- End of stack trace from previous location ---
   at PrettyPrompt.Panes.CodePane.OnKeyDown(KeyPress key)
   at PrettyPrompt.Prompt.InterpretKeyPress(KeyPress key, CodePane codePane, CompletionPane completionPane)
   at PrettyPrompt.Prompt.ReadLineAsync(String prompt)
   at CSharpRepl.ReadEvalPrintLoop.RunAsync(Configuration config) in C:\Users\will.fuqua\source\repos\CSharpRepl\CSharpRepl\ReadEvalPrintLoop.cs:line 41
   at CSharpRepl.Program.Main(String[] args) in C:\Users\will.fuqua\source\repos\CSharpRepl\CSharpRepl\Program.cs:line 47
   at CSharpRepl.Program.<Main>(String[] args)
2021-09-15T14:13:00 - Trace session starting
2021-09-15T14:13:00 - Starting background initialization
2021-09-15T14:13:01 - Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at CSharpRepl.Services.Roslyn.RoslynServices.CompleteAsync(String text, Int32 caret) in C:\Users\will.fuqua\source\repos\CSharpRepl\CSharpRepl.Services\Roslyn\RoslynServices.cs:line 114
   at CSharpRepl.PrettyPromptConfig.PromptConfiguration.<>c__DisplayClass0_0.<<Configure>g__completionHandler|0>d.MoveNext() in C:\Users\will.fuqua\source\repos\CSharpRepl\CSharpRepl\PrettyPromptConfig\PromptConfiguration.cs:line 45
--- End of stack trace from previous location ---
   at PrettyPrompt.Panes.CompletionPane.PrettyPrompt.Consoles.IKeyPressHandler.OnKeyUp(KeyPress key)
   at PrettyPrompt.Prompt.InterpretKeyPress(KeyPress key, CodePane codePane, CompletionPane completionPane)
   at PrettyPrompt.Prompt.ReadLineAsync(String prompt)
   at CSharpRepl.ReadEvalPrintLoop.RunAsync(Configuration config) in C:\Users\will.fuqua\source\repos\CSharpRepl\CSharpRepl\ReadEvalPrintLoop.cs:line 41
   at CSharpRepl.Program.Main(String[] args) in C:\Users\will.fuqua\source\repos\CSharpRepl\CSharpRepl\Program.cs:line 47
   at CSharpRepl.Program.<Main>(String[] args)
```

Hope it will help.

@Jamaxack
Copy link
Author

There is an error: "One or more errors occurred. (Could not find Microsoft.NETCore.App 5.0.7 installation in C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref -- is it installed?)"

But in my machine it is installed in different path: Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

@waf
Copy link
Owner

waf commented Sep 15, 2021

Thanks! That's useful. Just to make sure I fully understand the .NET installation setup, could you please share the output of the powershell command gci "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref", "C:\Program Files\dotnet\shared\Microsoft.NETCore.App"

I think that your computer should have a "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref" directory (I think is a standard disk layout in .NET), but if that's not the case then it's something I'll definitely need to handle in csharprepl. Thanks again.

@Jamaxack
Copy link
Author

Sure, please check it:
image

@Drabenstein
Copy link

Hello, I've just bumped into this project today and I have the same issue. It just exits after start. I get corresponding error in my case:

obraz

gci "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref", "C:\Program Files\dotnet\shared\Microsoft.NETCore.App"

    Directory: C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          26.12.2020    00:06                3.1.0

    Directory: C:\Program Files\dotnet\shared\Microsoft.NETCore.App

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          20.03.2021    17:01                3.1.13
d----          28.06.2021    23:05                3.1.15
d----          20.03.2021    16:59                5.0.4

@waf
Copy link
Owner

waf commented Sep 15, 2021

Thank you both @Jamaxack and @Drabenstein! It's because of the mismatch between those two folders. In both of your cases, the .NET 5 implementation assemblies are in "Microsoft.NETCore.App", but the .NET 5 reference assemblies are not in "Microsoft.NETCore.App.Ref".

While I work on a fix for csharprepl to handle this mismatch, I believe that both of you can solve it by installing the .NET SDK package from this link (the below screenshot shows the specific download). After installing this package, you should have .NET 5 subdirectories in both those directories.

image

waf added a commit that referenced this issue Sep 17, 2021
CSharpRepl currently depends on having shared frameworks globally
installed (e.g. to "\Program Files\dotnet" or equivalent on Linux/Mac
OS). This isn't always the case, though; the Shared Frameworks can also
be installed into ~/.nuget/packages. This PR adds support for this
scenario. Previously, CSharpRepl crashed in this case (see
#40).
@waf
Copy link
Owner

waf commented Sep 18, 2021

I've just released csharprepl 0.3.4 that has a fix for this issue. I'm not sure if it handles all variations of .NET installations, but it should handle these. I'm assuming that the missing Microsoft.NETCore.App.Ref installation is installed to ~/.nuget/packages/microsoft.netcore.app.ref as mentioned in this design document.

Please try updating (dotnet tool update -g csharprepl) and let me know! Thanks.

@Drabenstein
Copy link

I have installed again the newest SDK and it worked so I cannot check for sure if the fix works but maybe @Jamaxack could test it.

@Jamaxack
Copy link
Author

Yay, after updating to version 0.3.4 it works. Thanks for the quick fix.

@waf
Copy link
Owner

waf commented Sep 20, 2021

Great! Thanks for raising the issue and confirming the fix.

mattstern31 added a commit to mattstern31/CSharp-Repl-Services that referenced this issue Nov 11, 2023
CSharpRepl currently depends on having shared frameworks globally
installed (e.g. to "\Program Files\dotnet" or equivalent on Linux/Mac
OS). This isn't always the case, though; the Shared Frameworks can also
be installed into ~/.nuget/packages. This PR adds support for this
scenario. Previously, CSharpRepl crashed in this case (see
waf/CSharpRepl#40).
syedrizvinet added a commit to syedrizvinet/Repl-Tests-CSharp that referenced this issue Apr 24, 2024
CSharpRepl currently depends on having shared frameworks globally
installed (e.g. to "\Program Files\dotnet" or equivalent on Linux/Mac
OS). This isn't always the case, though; the Shared Frameworks can also
be installed into ~/.nuget/packages. This PR adds support for this
scenario. Previously, CSharpRepl crashed in this case (see
waf/CSharpRepl#40).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants