我正在构建导入.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.dllC:\的Windows \ Microsoft.NET \组件\ GAC_MSIL \ Microsoft.VisualBasic程序\ v4.0_10.0.0.0__b03f5f7f11d50a3a。
当尝试通过Project添加引用时,不会保持检查 - >添加引用并浏览它。我可以检查它,但是当我返回参考管理器时,再次取消选中DLL。
如果重要,则功能使用反射,如下所示(导入显示为大小写):
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核心应用程序?