提问人:user 提问时间:3/9/2018 最后编辑:user 更新时间:5/4/2023 访问量:5555
无法加载类型 Microsoft.VisualBasic.Information
Could Not Load Type Microsoft.VisualBasic.Information
问:
我正在构建导入 .Net Framework 4.6.1 项目类库的 .Net Core 2.0 Web 应用程序。该解决方案构建正确,但是,当达到以下功能时,我收到此错误:
System.TypeLoadException: Could not load type 'Microsoft.VisualBasic.Information' from assembly 'Microsoft.VisualBasic, Version=10.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
我在以下位置找到了Microsoft.VisualBasic.dll:C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a
但是,在尝试添加引用并浏览引用时,引用不会保持选中状态。我可以检查它,但是当我返回到引用管理器时,DLL再次被取消选中。Project -> Add Reference
如果很重要,该功能使用反射,如下所示(在案例中显示导入):
Imports System.Data.SqlClient
Imports System.Reflection
Imports Microsoft.Win32
Shared Function GetContentCostFieldMapping(Optional ByVal busGrp As String = Nothing, Optional ByVal program As String = Nothing) As CostFieldMapping
Dim _conn As SqlConnection = Nothing
Dim _row As CostFieldMapping = New CostFieldMapping
Try
_conn = New SqlConnection(_sqlDB)
_conn.Open()
Dim _cmd As SqlCommand
Dim _dr As SqlDataReader
_cmd = New SqlCommand("GetContentCostFieldMapping", _conn)
_cmd.CommandType = CommandType.StoredProcedure
_cmd.Parameters.Add("@BusGrp", SqlDbType.NVarChar).Value = busGrp
_cmd.Parameters.Add("@Program", SqlDbType.NVarChar).Value = program
_dr = _cmd.ExecuteReader
_row = SharedManager.GenericGet(Of CostFieldMapping)(_dr, False)
Return _row
Catch ex As Exception
Helpers.LogMessage("Error: " + ex.Message + ". Stacktrace: " + ex.StackTrace)
Finally
If _conn IsNot Nothing AndAlso Not _conn.State = ConnectionState.Closed Then
_conn.Close()
End If
End Try
Return _row
End Function
Public Shared Function GenericGet(Of T As {Class, New})(dr As SqlDataReader, ByVal listFlag As Boolean)
Dim results As Object
If listFlag Then
results = New List(Of T)()
End If
Dim businessEntityType As Type = GetType(T)
Dim hashtable As New Hashtable()
Dim properties As PropertyInfo() = businessEntityType.GetProperties()
For Each info As PropertyInfo In properties
hashtable(info.Name.ToUpper()) = info
Next
While dr.Read()
Dim newObject As New T()
For index As Integer = 0 To dr.FieldCount - 1
Dim info As PropertyInfo = DirectCast(hashtable(dr.GetName(index).ToUpper()), PropertyInfo)
If (info IsNot Nothing) AndAlso info.CanWrite AndAlso IsDBNull(dr.GetValue(index)) = False Then
SetValue(newObject, info, dr.GetValue(index))
End If
Next
If listFlag Then
results.Add(newObject)
Else
results = newObject
End If
End While
dr.Close()
Return results
End Function
无法添加DLL是主要问题,但是,当我继续调试时,调试器不断抛出有关缺少库的错误。这两个项目不兼容吗?是否有一种干净的方法来导入 .NET Framework 代码库以在 .NET Core 应用程序中使用?
答: 暂无答案
评论
IsDBNull
Microsoft.VisualBasic namespace, e.g.
,
IsDBNull