I am building .Net Core 2.0 web application that imports a .Net Framework 4.6.1 project class library. The solution builds properly, however, when reaching the below functionality, I receive this error:
System.TypeLoadException: Could not load type 'Microsoft.VisualBasic.Information' from assembly 'Microsoft.VisualBasic, Version=10.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
I have found Microsoft.VisualBasic.dll in:
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a
However, the reference does not remain checked when attempting to add the it via Project -> Add Reference
and browsing for it. I can check it, but when I return to the Reference Manager, the DLL is unchecked again.
The references and imported namespaces in the class library are as follows:
In case it matters, the functionality uses reflection, and is as follow (imports shown in case):
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
Not being able to add the DLL is the main issue, however, as I continue to debug, the debugger keeps throwing errors about missing libraries. Are the two projects incompatible? Is there a clean way to import a .NET Framework code library for use in a .NET core application?