1

I have the following code:

using System.Data.SqlClient;
using OPN.SP_Services.Interface;
using wwa.EPR.Services;

namespace OPN.SP_Services
{
    public class TestService : UnitOfWork<ClearviewLocalContext>, ITestService
    {
        public TestService(IDataContext<ClearviewLocalContext> dataContext) : base(dataContext)
        {

        }

        public void test()
        {
            var param = new SqlParameter();
        }
    }
}

namespace OPN.SP_Services.Interface
{
    public interface ITestService
    {
        void test();
    }
}

Dependency config:

container.Register<ITestService, TestService>();

called like this:

_testService.test();

When I step through the code and reach this line:

            var param = new SqlParameter();

and inspect the variable, I see the following in my locals:

enter image description here

Can anyone explain what is going on here?

Alex
  • 3,730
  • 9
  • 43
  • 94
  • Is there a specific reason for you to not add the parameter to an SQLcommand? – Freek W. Jan 16 '18 at 15:47
  • @FreekW. I am using IDataContext and am having this issue. I have tried all the solutions suggested, but none work and I am wondering if this is the cause of the issue so have separated it out. – Alex Jan 16 '18 at 15:48
  • 1
    It's normal for some properties of an object to show as Null Reference Exceptions in the locals window, because that's what would happen if your code accessed them. – stuartd Jan 16 '18 at 15:48
  • 1
    @stuartd do you mean that this code will execute fine unless I try and access one of the null properties? If so, if you put that as the answer I will mark it as correct – Alex Jan 16 '18 at 15:50

1 Answers1

1

All of the properties in red are internal properties, that don't work unless certain preconditions have been met. Usually, you'd never see them or access them out-of-order, precisely because they are internal. They are not required to be as well-behaved as public properties. That said: it isn't unusual for public properties to throw exceptions when accessed in an invalid state.

Basically: nothing to worry about here; no problems; business as normal. This is not the cause of whatever problem you are seeing elsewhere.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900