VB.net继承,仅在一次调用中未找到成员
我在这件事上不知所措。我有一个从“基类”继承的类。基类有一个名为“UpdateData”的受保护成员 我有一个从“UpdateData”继承的类“DataAccess”。DataAccess有许多使用“UpdateData”方法的不同调用。除了“DataAccess”上的一个方法返回“membernotfound”异常外,这一切都很好 我已经进行了清理和重建,它发生在VisualStudio中,也发生在部署到服务器时。对“添加”的调用有效,但对“添加详细信息”的调用失败 我尝试删除下面列出的事务作用域,尝试使用工厂模式为每个调用获取一个新实例,但两者都不起作用。我不想将该方法公开为“public”,因为我们有数百个类使用受保护的“UpdateData”方法,很好吧 非常感谢您的任何帮助或新想法VB.net继承,仅在一次调用中未找到成员,vb.net,inheritance,Vb.net,Inheritance,我在这件事上不知所措。我有一个从“基类”继承的类。基类有一个名为“UpdateData”的受保护成员 我有一个从“UpdateData”继承的类“DataAccess”。DataAccess有许多使用“UpdateData”方法的不同调用。除了“DataAccess”上的一个方法返回“membernotfound”异常外,这一切都很好 我已经进行了清理和重建,它发生在VisualStudio中,也发生在部署到服务器时。对“添加”的调用有效,但对“添加详细信息”的调用失败 我尝试删除下面列出的事务
''''On the base class
Protected Sub UpdateData(ByVal connString As String, ByVal procName As String, ByVal ParamArray params As Object())
UpdateDataWithTimeout(connString, procName, getTimeoutSetting, params)
End Sub
''''On the inherited class. This one works
Protected Friend Overridable Sub Add(ByVal s1 As String, _
ByRef s2 As String, _
ByVal s3 As String, _
ByVal params As List(Of Object))
Try
params.Insert(0, s1)
params.Insert(1, s2)
params.Insert(2, s3)
UpdateData(DB, SPI_PROC1, params.ToArray())
Catch ex As Exception
Throw ex
End Try
End Sub
''''On the inherited "DataAccess" class. This one fails.
Protected Friend Overridable Sub AddDetail(ByVal ParamArray parms As Object())
If Condition1 Then
UpdateData(_sysConn, SPI_PROC, parms)
End If
End Sub
''''This is from a method in the class calling the "DataAccess" code
Dim da As DataAccess
da = New DataAccess(strVariable)
Using scope As New TransactionScope(TransactionScopeOption.RequiresNew)
''''This call works just fine and can find "UpdateData"
da.Add(string1, string2, string3, objectParameterList)
'Separate database, so avoid MSDTC with new transaction scope
Using scope2 As New TransactionScope(TransactionScopeOption.RequiresNew)
''''This call fails to find UpdateData
da.AddDetail(string1, string5, string6, string7, string8, string3)
scope2.Complete()
scope.Complete()
End Using
End Using
附录:这里的IL有一个不同之处,一个是“延迟绑定”(我需要停止),但不确定如何进行
失败的方法
IL_001f: ldstr "UpdateData"
IL_0024: ldc.i4.3
IL_0025: newarr [mscorlib]System.Object
IL_002a: stloc.1
IL_002b: ldloc.1
IL_002c: ldc.i4.0
IL_002d: ldarg.0
IL_002e: ldfld string DataAccess::_sysConn
IL_0033: stelem.ref
IL_0034: ldloc.1
IL_0035: ldc.i4.1
IL_0036: ldloc.0
IL_0037: call object [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::GetObjectValue(object)
IL_003c: stelem.ref
IL_003d: ldloc.1
IL_003e: ldc.i4.2
IL_003f: ldarg.1
IL_0040: stelem.ref
IL_0041: ldloc.1
IL_0042: stloc.2
IL_0043: ldloc.2
IL_0044: ldnull
IL_0045: ldnull
IL_0046: ldc.i4.3
IL_0047: newarr [mscorlib]System.Boolean
IL_004c: stloc.3
IL_004d: ldloc.3
IL_004e: ldc.i4.0
IL_004f: ldc.i4.1
IL_0050: stelem.i1
IL_0051: ldloc.3
IL_0052: ldc.i4.1
IL_0053: ldc.i4.1
IL_0054: stelem.i1
IL_0055: ldloc.3
IL_0056: ldc.i4.2
IL_0057: ldc.i4.1
IL_0058: stelem.i1
IL_0059: ldloc.3
IL_005a: ldc.i4.1
IL_005b: call object [Microsoft.VisualBasic]Microsoft.VisualBasic.CompilerServices.NewLateBinding::LateCall(object,
class [mscorlib]System.Type,
string,
object[],
string[],
class [mscorlib]System.Type[],
bool[],
bool)
IL_0060: pop
IL_0061: ldloc.3
IL_0062: ldc.i4.0
IL_0063: ldelem.i1
IL_0064: brfalse.s IL_0088
IL_0066: ldarg.0
IL_0067: ldloc.2
IL_0068: ldc.i4.0
IL_0069: ldelem.ref
IL_006a: call object [mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::GetObjectValue(object)
从工作方法来看,这里是IL
IL_003b: ldarg.0
IL_003c: ldstr "conn"
IL_0041: ldstr "proc"
IL_0046: ldarg.0
IL_0047: callvirt instance string DataAccess::get_SYSCODE_SPAPPEND()
IL_004c: call string [mscorlib]System.String::Concat(string,
string)
IL_0051: ldarg.s params
IL_0053: callvirt instance !0[] class [mscorlib]System.Collections.Generic.List`1<object>::ToArray()
IL_0058: callvirt instance void [BaseClass]BaseClass::UpdateData(string,
string,
object[])
IL_003b:ldarg.0
IL_003c:ldstr“连接”
IL_0041:ldstr“程序”
IL_0046:ldarg.0
IL_0047:callvirt实例字符串DataAccess::get\u SYSCODE\u SPAPPEND()
IL_004c:call string[mscorlib]System.string::Concat(string,
(字符串)
IL_0051:ldarg.s参数
IL_0053:callvirt实例!0[]类[mscorlib]System.Collections.Generic.List`1::ToArray()
IL_0058:callvirt实例void[BaseClass]BaseClass::UpdateData(字符串,
一串
对象[])
当然,你一问这个问题,答案就来了
我将SPI_PROC和SPI_PROC1的字符串变量更改为类上的私有常量,而不是变量。。。在类构造函数中设置_sysConn和DB,它将所有内容切换到早期绑定
所以问题解决了。希望这能为其他人节省几个小时的时间