编辑表明 VS'08 无法编译工作的 dll,尽管我最初说它可以
我们有一段 VB 代码,其编译方式不同,具体取决于用于编译它的工具。
我尝试使用 Visual Studio '08、'10 和 MSBuild 3.5 和 4 在几台不同的计算机上编译此代码。MSBuild 3.5(我们的构建服务器使用)和 VS'08 总是产生损坏的 dll,而 MSBuild4/VS'10产生一个工作的dll。我比较了 MSBuild 3.5 和 4 之间的 Vbc 命令行参数,唯一的区别是(/nodstdlib、/sdkpath、/langversion:9),它们似乎都与使 Vbc 4 编译 3.5 兼容的 dll 有关。
在损坏的版本中,If 语句中的代码会抛出错误,指出委托给实例方法不能具有 null 'this'。
相关代码的片段是:
Dim folders As SortedList(Of String, FolderInfo) = FolderManager.Instance.GetFoldersSorted(portalId)
Dim inventory As New List(Of FolderInventoryItem)
'create a FileSysItem for every folder
For Each folderItem In folders.Values
Dim currentFolder = folderItem
If (Not inventory.Any(Function(f) f.UniqueId = currentFolder.UniqueId)) Then
....
使用 Reflector 将 IL 反汇编为 VB,工作 dll 包含:
Dim foldersSorted As SortedList(Of String, FolderInfo) = ComponentBase(Of IFolderManager, FolderManager).Instance.GetFoldersSorted(portalId)
Dim source As New List(Of FolderInventoryItem)
Dim info As FolderInfo
For Each info In foldersSorted.Values
Dim e$__ As _Closure$__2
e$__ = New _Closure$__2(e$__) { _
.$VB$Local_currentFolder = info _
}
If Not source.Any(Of FolderInventoryItem)(New Func(Of FolderInventoryItem, Boolean)(AddressOf e$__._Lambda$__6)) Then
使用Reflector将IL反汇编成VB,破解的dll包含:
Dim foldersSorted As SortedList(Of String, FolderInfo) = ComponentBase(Of IFolderManager, FolderManager).Instance.GetFoldersSorted(portalId)
Dim source As New List(Of FolderInventoryItem)
Dim info As FolderInfo
For Each info In foldersSorted.Values
Dim e$__ As _Closure$__2
Dim e$__2 As _Closure$__3
e$__ = New _Closure$__2(e$__) { _
.$VB$Local_currentFolder = info _
}
If Not source.Any(Of FolderInventoryItem)(New Func(Of FolderInventoryItem, Boolean)(AddressOf e$__2._Lambda$__6)) Then