Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3610766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:47:34+00:00 2026-05-18T21:47:34+00:00

Ok, so once upon a time, my code worked. Since then I did some

  • 0

Ok, so once upon a time, my code worked. Since then I did some refactoring (basic stuff so I thought) but now I’m getting a null reference exception, and I can’t bloody well figure out why.

Here’s where it starts. note, this is the logout method, but all of my ActivityLogs sections are throwing this error

Function LogOut(ByVal go As String) As ActionResult
    ActivityLogService.AddActivity(AuthenticationHelper.RetrieveAuthUser.ID, _
                                   IActivityLogService.LogType.UserLogout, _
                                   HttpContext.Request.UserHostAddress)
    ActivityLogService.SubmitChanges()
    'more stuff happens after this'
End Function

The service is pretty straight forward (notice the ERROR THROWN HERE)

    Public Sub AddActivity(ByVal userid As Integer, ByVal activity As Integer, ByVal ip As String) Implements IActivityLogService.AddActivity
        Dim _activity As ActivityLog = New ActivityLog With {.Activity = activity,
                                                             .UserID = userid,
                                                             .UserIP = ip.IPAddressToNumber,
                                                             .ActivityDate = DateTime.UtcNow}

        ActivityLogRepository.Create(_activity)  ''#ERROR THROWN HERE
    End Sub

And the Interface that the Service uses looks like this

Public Interface IActivityLogService
    Sub AddActivity(ByVal userid As Integer, ByVal activity As Integer, ByVal ip As String)
    Function GetUsersLastActivity(ByVal UserID As Integer) As ActivityLog
    Sub SubmitChanges()

    ''' <summary> '
    ''' The type of activity done by the user '
    ''' </summary>
    ''' <remarks>Each int refers to an activity. There can be no duplicates or modifications  after this application goes live</remarks> '
    Enum LogType As Integer
        ''' <summary> '
        ''' A new session started '
        ''' </summary> '
        SessionStarted = 1
        ''' <summary> '
        ''' A new user is Added/Created '
        ''' </summary> '
        UserAdded = 2
        ''' <summary> '
        ''' User has updated their profile '
        ''' </summary> '
        UserUpdated = 3
        ''' <summary> '
        ''' User has logged into they system '
        ''' </summary> '
        UserLogin = 4
        ''' <summary> '
        ''' User has logged out of the system '
        ''' </summary> '
        UserLogout = 5
        ''' <summary> '
        ''' A new event has been added '
        ''' </summary> '
        EventAdded = 6
        ''' <summary> '
        ''' An event has been updated '
        ''' </summary> '
        EventUpdated = 7
        ''' <summary> '
        ''' An event has been deleted '
        ''' </summary> '
        EventDeleted = 8
        ''' <summary> '
        ''' An event has received a Up/Down vote '
        ''' </summary> '
        EventVoted = 9
        ''' <summary> '
        ''' An event has been closed '
        ''' </summary> '
        EventCloseVoted = 10
        ''' <summary> '
        ''' A comment has been added to an event '
        ''' </summary> '
        CommentAdded = 11
        ''' <summary> '
        ''' A comment has been updated '
        ''' </summary> '
        CommentUpdated = 12
        ''' <summary> '
        ''' A comment has been deleted '
        ''' </summary> '
        CommentDeleted = 13
        ''' <summary> '
        ''' An event or comment has been reported as spam '
        ''' </summary> '
        SpamReported = 14
    End Enum
End Interface

And the repository is equally straight forward

Public Class ActivityLogRepository : Implements IActivityLogRepository
    Private dc As MyAppDataContext
    Public Sub New()
        dc = New MyAppDataContext
    End Sub

    ''' <summary> '
    ''' Adds the activity. '
    ''' </summary> '
    ''' <param name="activity">The activity.</param>
    Public Sub Create(ByVal activity As ActivityLog) Implements IActivityLogRepository.Create
        dc.ActivityLogs.InsertOnSubmit(activity)
    End Sub

    ''' <summary> '
    ''' Gets the activities. '
    ''' </summary> '
    ''' <returns>results AsQueryable</returns>
    Public Function Read() As IQueryable(Of ActivityLog) Implements IActivityLogRepository.Read
        Dim activity = (From a In dc.ActivityLogs
                        Order By a.ActivityDate Descending
                        Select a)
        Return activity.AsQueryable
    End Function

    ''' <summary> '
    ''' Submits the changes. '
    ''' </summary> '
    Public Sub SubmitChanges() Implements IActivityLogRepository.SubmitChanges
        dc.SubmitChanges()
    End Sub
End Class

The stack trace is as follows

[NullReferenceException: Object reference not set to an instance of an object.]
MyApp.Core.Domain.ActivityLogService.AddActivity(Int32 userid, Int32 activity, String ip) in E:\Projects\MyApp\MyApp.Core\Domain\Services\ActivityLogService.vb:49
MyApp.Core.Controllers.UsersController.Authenticate(String go) in E:\Projects\MyApp\MyApp.Core\Controllers\UsersController.vb:258
lambda_method(Closure , ControllerBase , Object[] ) +163
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +51
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +409
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) +52
System.Web.Mvc.<>c__DisplayClass15.b__12() +127
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +436
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +61
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList
1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +305
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
System.Web.Mvc.Controller.ExecuteCore() +136
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +232
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +68
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
System.Web.Mvc.Async.<>c__DisplayClass8
1.b__7(IAsyncResult _) +42
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.<>c__DisplayClasse.b__d() +61
System.Web.Mvc.SecurityUtil.b__0(Action f) +31
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +56
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +110
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +690
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +194

here’s an image of the error when attached to the debugger.

alt text

And here’s an image of the DB schema in question

alt text

Can anyone shed some light on what I might be missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:47:35+00:00Added an answer on May 18, 2026 at 9:47 pm

    @gbs pointed me in the right direction.

    I had the following in my service

        Private ActivityLogRepository As IActivityLogRepository
    
        Public Sub New(ByVal ActivityLogRepository As IActivityLogRepository)
            ActivityLogRepository = ActivityLogRepository
        End Sub
    

    Not sure how I missed it, changed to this and it works

        Private ActivityLogRepository As IActivityLogRepository
    
        Public Sub New(ByVal _ActivityLogRepository As IActivityLogRepository)
            ActivityLogRepository = _ActivityLogRepository
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Once upon a time I read how you detect programmatically for mounted NTFS folders
Once upon a time, to write x86 assembler, for example, you would have instructions
I ran across something once upon a time and wondered if it was a
Once again a very beginner-ish question, but here I go: I would like to
Once again one of those: Is there an easier built-in way of doing things
Once I've created a variable in the immediate window in C# (VS2008), is there
Once a user starts a session (or logs in, for a registered user, to
Once I have all the files I require in a particular folder, I would
Once a programmer decides to implement IXmlSerializable , what are the rules and best
Once it is compiled, is there a difference between: delegate { x = 0;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.