C # - internal static readonly is null for access

I have the following code:

internal class FakeInvitationsRepository : InvitationsRepository
{
    internal readonly static Dictionary<Guid, InvitationDbEntity> Data = new Dictionary<Guid, InvitationDbEntity>()
    {
        { ...

Here is a screenshot of what it's worth:

Screen shot of real code

This is just some fake data in memory, just 3 elements. The class lives inside the ASP.NET WebAPI project, and not in the test DLL, but in the WebAPI library.

An API call comes in and presses a breakpoint in the controller action, where it tries to use this fake data directly, not a single IoC is smart yet.

But the field Datais null. This throws a null ref exception at runtime.

Screen show showing null

The C # language specification says:

( 10.11), . .

, ?

. . Data - , ( readonly afterall).

- :

System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace();
{   at Company.Product.WebAPI.Controllers.RenamedController.<GetInvitations>d__14.MoveNext()
   at Company.Product.WebAPI.Controllers.RenamedController.GetInvitations(Guid id)
   at lambda_method(Closure , Object , Object[] )
   at Company.WebAPI.Product.Areas.RouteDebugger.InspectActionInvoker.InvokeActionAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
   at Company.WebAPI.Product.Areas.RouteDebugger.InspectHandler.<>n__FabricatedMethod12(HttpRequestMessage , CancellationToken )
   at Company.WebAPI.Product.Areas.RouteDebugger.InspectHandler.<SendAsync>d__e.MoveNext()
   at Company.WebAPI.Product.Areas.RouteDebugger.InspectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
}
    FrameCount: 84
    frames: {System.Diagnostics.StackFrame[87]}
    m_iMethodsToSkip: 3
    m_iNumOfFrames: 84

, . .

MStodd. , ; , - 11 .NET.

Data .

, , , .

NullReferenceException - this.Invitations .

, , , , , , , null .

.

+4
1

, Invitations ( Select). , , - , Invitations NULL!). , Data = NULL ! .

+1

All Articles