efcore
efcore copied to clipboard
Debugging With Primary Constructor
Description
When There Variables From Primary Constructor Like Injecting DbContext When Debug And Hover Over DbContext And Breakpoint In Method To Query Somthings I Hovered Over DbContext And dbContext varibale or parameter value is null
and This is in Watch
Try It With Your Self
Reproduction Steps
...
Expected behavior
....
Actual behavior
...
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Tagging subscribers to this area: @dotnet/area-system-reflection-emit See info in area-owners.md if you want to be subscribed.
Issue Details
Description
When There Variables From Primary Constructor Like Injecting DbContext When Debug And Hover Over DbContext And Breakpoint In Method To Query Somthings I Hovered Over DbContext And dbContext varibale or parameter value is null
and This is in Watch
Try It With Your Self
Reproduction Steps
...
Expected behavior
....
Actual behavior
...
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Author: | wisamidris7 |
---|---|
Assignees: | - |
Labels: |
|
Milestone: | - |
And i'm In AspNetCore 8 and visual studio
Windows 11
Tagging subscribers to this area: @tommcdon See info in area-owners.md if you want to be subscribed.
Issue Details
Description
When There Variables From Primary Constructor Like Injecting DbContext When Debug And Hover Over DbContext And Breakpoint In Method To Query Somthings I Hovered Over DbContext And dbContext varibale or parameter value is null
and This is in Watch
Try It With Your Self
Reproduction Steps
...
Expected behavior
....
Actual behavior
...
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Author: | wisamidris7 |
---|---|
Assignees: | - |
Labels: |
|
Milestone: | - |
@wisamidris7 please try 17.9.
This issue has been marked needs-author-action
and may be missing some important information.
I have this weird bug too. I can toggle between a working implementation and non. I'm using Rider, with dotnet 8.0.100 on OSX, working with an Orleans project.
Other things are being injected to other classes, so I'll investigate my use of Keyed services.
This will fail with a null for the client
public class CredentialsBuilder(IClient client) : ICredentialsBuilder
This will successfully inject the client.
{
private readonly IClient _client;
public CredentialsBuilder(IClient client)
{
_client = client;
}
Also, I'm able to make the GetServices request from the debugger and get back an object, so we're definitely registered.
My best description is, in Orleans grains (Couldn't reproduce in a normal HostBuilder setup) The initial constructor is created, the client is populated, but when in the context of a function call. The values of the primary constructor become null and unless you made a copy into a private variable you'll get a null exception.
I was unable to reproduce with an identical injection setup.
However a quick workaround is to assign the constructor variable to a private variable, since the constructor was called with the injected value, but null inside function calls.
public class CredentialGrain(Config config) : Grain<CredentialState>, ICredentialGrain {
private readonly Config _config = config;
Reproduction attempt:
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.AddTransient<d, D>();
builder.Services.AddTransient<b, B>();
builder.Services.AddKeyedTransient<c, C>(nameof(C));
builder.Services.AddKeyedTransient<a, A>(nameof(A));
var host = builder.Build();
host.Services.GetKeyedService<a>(nameof(A)).pt();
await host.StartAsync();
class A(b client) : a {
public void pt() => Console.WriteLine(client is null);
}
interface a { public void pt(); }
class B([FromKeyedServices(nameof(C))] c C, d D) : b{}
interface b{}
class C() : c{}
interface c{}
class D() : d{}
interface d{}
This issue does not seem to be related to the .NET diagnostics debugger but instead related to Entity Framework or Dependency Injection. If there is a .NET debugger specific issue please provide a reproducible test case removing Entity Framework (dotnet/efcore) and DI (dotnet/extensions). Routing Entity Framework for initial triage.
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
Visual Studio Update 17.9 Worked Fine Thanks!