我已经编写了一个新的DAL和BLL,但是当我尝试创建一个类的实例时,我得到一个Object Reference错误,我应该寻找什么特别的东西?我对这个概念还不熟悉吗?
呼叫是这样的:
Protected Sub btnSignin_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSignin.Click
Dim l As New Log()
l.Log = "Attempted staff login with username [" & txtUsername.Text & "] and password [" & txtPassword.Text & "]"
l.LogId = 0
l.StaffId = 0
l.LogDate = Date.Now()
l.Insert()
我收到引用错误的'Insert'调用,在我的BLL(BLL / Log.vb)中调用这些函数;
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Transactions
Imports System.Text
Imports Harmony.Zizz.DAL
Namespace Harmony.Zizz.BLL.Zizz
Public Class Log
Inherits BaseZizz
Protected _logid As Integer = 0
Protected _log As String = ""
Protected _staffid As Integer = 0
Protected _logdate As DateTime = Date.Now
Public Sub New()
End Sub
Public Sub New(ByVal logid As Integer, ByVal log As String, ByVal staffid As Integer, ByVal logdate As DateTime)
End Sub
'////property setup removed for brevity ////
Public Property LogId() As Integer
Public Property Log() As String
Public Property LogDate() As DateTime
Public Function Insert() As Integer
Return Harmony.Zizz.BLL.Zizz.Log.InsertLog(Me.LogId, Me.Log, Me.StaffId, Me.LogDate)
End Function
Public Shared Function InsertLog(ByVal logid As Integer, ByVal log As String, ByVal staffid As Integer, ByVal logdate As DateTime) As Integer
HttpContext.Current.Trace.Write("Fired InsertLog BLL (log.vb) Line 61")
Using scope As New TransactionScope()
HttpContext.Current.Trace.Write("Within InsertLog BLL Transaction Scope (log.vb) Line 63")
Dim record As New LogDetails(logid, log, staffid, logdate)
HttpContext.Current.Trace.Write("Created LogDetails Object InsertLog BLL (log.vb) Line 65")
Dim ret As Boolean = SiteProvider.Zizz.InsertLog(record)
HttpContext.Current.Trace.Write("Inserted LogDetails object into SiteProvider InsertLog BLL (log.vb) Line 61")
scope.Complete()
Return ret
End Using
End Function
End Class
End Namespace
堆栈跟踪到达Dim ret As Boolean = SiteProvider
行。 SiteProvider调用包含此代码,这是我认为错误起源的地方,但不知道为什么 - 或如何修复---:
Imports Microsoft.VisualBasic
Namespace Harmony.Zizz.DAL
Public NotInheritable Class SiteProvider
Public Shared ReadOnly Property Zizz() As ZizzProvider
Get
Return ZizzProvider.Instance
End Get
End Property
End Class
End Namespace
如果能够给予帮助,将非常感激。 Intellisense强调没有问题,如果我在VS中构建网站,我会在web.config(无关)中收到一些关于架构信息的警告,否则没问题。
帮助表示赞赏。
答案 0 :(得分:1)
如果在行上放置断点
Return ZizzProvider.Instance
你很可能会看到ZizzProvider或ZizzProvider.Instance为空,所以回到SiteProvider.Zizz.InsertLog(记录)行,因为Zizz为空,所以无法调用InsertLog。
答案 1 :(得分:1)