runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Debugger crash when trying to access an EntityFrameworkCore Proxy

Open tommcdon opened this issue 6 years ago • 12 comments

[Transfer from microsoft/dotnet/issues/1159]

[Opened on behalf of @Kurtz1993]

This issue was reported to the Microsoft.EntityFrameworkCore.Proxies team and you can find the thread here: dotnet/efcore#14286 (comment)

They checked the issue on their side, but seems to be something more with the debugger side than the Proxies package itself. See dotnet/efcore#14286 (comment)

Also, it has been reported to the Visual Studio Developer Community, and they told me to raise the issue here. See the thread: https://developercommunity.visualstudio.com/content/problem/859485/debugger-crash-when-trying-to-access-an-entityfram.html?childToView=872228#comment-872228

I'm using Microsoft.EntityFrameworkCore.Proxies to lazy load my navigation properties but I can't debug my objects anymore. When I try to evaluate them in the debugger the debugger just crashes with the following exception:

Loaded '/usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.0/System.Linq.Queryable.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. Stack overflow. The program '[3407] EfCoreIssue.dll' has exited with code 0 (0x0). Error processing 'variables' request. The process has been terminated.

To replicate the issue, you can use the following code: https://github.com/Kurtz1993/efcore-proxies-issue

I'm using: EntityFrameworkCore 3.1.0 EntityFrameworkCore.Proxies 3.1.0 netcoreapp3.0 This was also happening with EntityFrameworkCore.Proxies 3.0.1 Here's a short video of me trying to hover over a property that is being lazy-loaded, and a few seconds later... the debugging session crashes. This happens both on Visual Studio Code and Visual Studio for Mac Additional details: Database Provider: Microsoft.EntityFrameworkCore.SqlServer 3.1.0 OS: macOS Catalina 10.15.1 Visual Studio for Mac 8.3.10 (build 2) Visual Studio Code 1.40.2 Console details: Microsoft.EntityFrameworkCore.Database.Command: Information: Executing DbCommand [Parameters=[@__p_0='61fee321-5998-48c7-9543-250adfe5f373' (Size = 450)], CommandType='Text', CommandTimeout='30'] SELECT [a].[Id], [a].[Aficion], [a].[UsuarioEntityId] FROM [AficionPasatiempo] AS [a] WHERE ([a].[UsuarioEntityId] = @__p_0) AND @__p_0 IS NOT NULL Stack overflow. The target process exited with code 0 while evaluating the function 'Castle.Proxies.UsuarioEntityProxy.Aficiones.get'.The program '[4360] TrascenderAPI.dll' has exited with code 0 (0x0).

These are all the providers I've tested, both on VS for Mac and Visual Studio Code.

Microsoft.EntityFrameworkCore.SqlServer Microsoft.EntityFrameworkCore.Cosmos Npgsql.EntityFrameworkCore.PostgreSQL Pomelo.EntityFrameworkCore.MySql

Visual Studio for Mac 8.3.10 (build 2) Visual Studio Code (since 1.40.2) with C# extension v1.21.8 OS: macOS Catalina 10.15.2 (happening since 10.15)

tommcdon avatar Oct 28 '20 04:10 tommcdon

Tagging subscribers to this area: @tommcdon See info in area-owners.md if you want to be subscribed.

ghost avatar Oct 28 '20 04:10 ghost

Hi @Kurtz1993, we have moved microsoft/dotnet/issues/1159 here. Are you still seeing the same problem? I noticed that you were seeing a Stack Overflow. The debugger calls "ToString" on objects in the local/watch windows. Based off of the description and problem symptoms, it sounds like ToString is calling itself recursively, leading to the stack overflow. It should be easy to repro the problem by calling ".ToString()" on the object in the project to see if it leads to the same behavior.

tommcdon avatar Oct 28 '20 04:10 tommcdon

@tommcdon I can confirm that this is still issue on MacOS Catalina (10.15.7). It's impossible to debug if you hit navigation properties. Tested on Jetbrains Rider IDE

berik avatar Oct 30 '20 06:10 berik

Hi @tommcdon it's been a while since I tried to debug .NET Core on a Mac but it seems that the issue is still happening. Do you want me to do the test you asked?

Kurtz1993 avatar Nov 04 '20 14:11 Kurtz1993

@Kurtz1993 which versions platforms are you observing the issue? Also can you try .NET 5?

@berik thank you for confirming. Same as above, would you mind trying the same scenario on .NET 5 and let us know if the issue still reproduces?

tommcdon avatar Nov 04 '20 20:11 tommcdon

@tommcdon I've tried both version 3.1.9 and 5-rc2. Both versions throw an exception.

When you have 1 level nested property it works, but when it's 2 level nested and more it fails.

For example

public class Blog
    {
        public int BlogId { get; set; }
        public string Url { get; set; }

        public virtual List<Post> Posts { get; } = new List<Post>();
    }

public class Post
    {
        public int PostId { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }

        public int BlogId { get; set; }
        public virtual Blog Blog { get; set; }
        
        public virtual List<Comment> Comments { get; } = new List<Comment>();
    }

public class Comment
    {
        public int CommentId { get; set; }
        public string CommentText { get; set; }
        public int PostId { get; set; }
        public virtual Post Post { get; set; }
    }

When I try to get list of blogs and explore at the breakpoint in debug mode, it will crash on VS code and Rider IDE.

PS: I've wrapped both versions .net 3.1 and .net 5-rc2 if you need.

LazyLoadingVersion3.zip

LazyLoadingVersion5.zip

berik avatar Nov 06 '20 00:11 berik

@tommcdon I can confirm that this is still issue on MacOS Catalina (10.15.7). It's impossible to debug if you hit navigation properties. Tested on Jetbrains Rider IDE

I Just want to add that, this also is happening with NHibernate or Entityframework On Linux (I have tested on Ubuntu and Mint Versions) It's almost impossible to debug under this circunstancies, a barley mouse move and you got crash.

daniel-scatigno avatar Jan 08 '21 17:01 daniel-scatigno

I Just want to add that, this also is happening with NHibernate or Entityframework On Linux (I have tested on Ubuntu and Mint Versions) It's almost impossible to debug under this circunstancies, a barley mouse move and you got crash.

Thanks!

tommcdon avatar Jan 08 '21 23:01 tommcdon

I am having this problem too with Nhibernate - ToString causes stackoverflow exception and debugger crash. (doesn't happen on Windows, just mac/linux)

If in your mapping you set relations to load eagerly this goes away but of course that is terrible for performance.

A hotfix for this would be very much appreciated.

Target process has exited during evaluation of instance method NHibernate.Collection.Generic.PersistentGenericSet1 ::ToString() with actual parameters NHibernate.Collection.Generic.PersistentGenericSet1[MyCollection]. This may possibly happen due to StackOverflowException

Will-Bill avatar Jan 20 '21 09:01 Will-Bill

Hi, same problem here :

  • Ubuntu 18.04
  • VSCode 1.52.1
  • Dotnet sdk 5.0.102, dotnet runtime 5.0.2
  • SqlServer,
  • Microsoft.EntityFrameworkCore, SqlServer, Proxies, Design : Version=5.0.2

Crash when mouse hover object in debug mode :

Le processus cible s'est arrêté avec le code 0 (0x00000000) pendant l'évaluation de la fonction 'Castle.Proxies.ConsumptionProxy.Waste.get'. Le programme '[20896] I2bc.Rasp.Api.dll' s'est arrêté avec le code 0 (0x0).

Tested with PostgreSQL, SQLite, same result. The debugger is unusable. Any help is welcome ! Pierre

pacharbit avatar Jan 20 '21 16:01 pacharbit

Same thing here. MacBook Pro, macOS Big Sur v11.2.1. VS Code v1.53.1 .NET Core 5.0

The minute I hover over a Castle.Proxy.XXX type, or tries to view it in VARIABLES / WATCH window, I get a Stack Overflow with the following exception: The target process exited with code 0 (0x00000000) while evaluating the function 'Castle.Proxies.UserProxy.XXX.get'.

Appreciate any feedback...

Thank you Yaniv

yanivamrami avatar Feb 18 '21 14:02 yanivamrami

Looks like a duplicate to #12739

tommcdon avatar Mar 03 '21 21:03 tommcdon