对于相同的代码,MSBuild 3.5 生成的 IL 与 MSBuild 4 不同

发布于 2024-09-11 07:43:29 字数 1971 浏览 0 评论 0原文

编辑表明 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
  ....

Using Reflector to disassemble the IL to 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

Edited to indicate the VS'08 cannot compile a working dll, though I original said it could

We have a piece of VB code that compiles differently depending on what tools are used to compile it.

I have tried compiling this code on several different computers using Visual Studio '08, '10, and MSBuild 3.5 and 4. MSBuild 3.5 (which our build server uses) and VS'08 always produces a broken dll, while MSBuild4/VS'10 produces a working dll. I compared the Vbc command line parameters between MSBuild 3.5 and 4 the only differences were (/nodstdlib, /sdkpath, /langversion:9) which all appear related to making Vbc 4 compile a 3.5 compatible dll.

In the broken version the code inside the If statement throw an error saying Delegate to an instance method cannot have null 'this'.

A snippet of the relevant code is:

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
  ....

Using Reflector to disassemble the IL to VB, the working dll contains:

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

Using Reflector to disassemble the IL to VB, the broken dll contains:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城泪 2024-09-18 07:43:29

Scott,

Visual Basic 编译器和 MSBuild 团队正在研究您所描述的问题,但在重现该问题时遇到了困难。您能用一个可能只有一个代码文件的小项目重现这个问题吗?在开发工作站上或仅在构建服务器上使用 MSBuild 3.5 进行构建时是否存在此问题?它会影响所有 lambda 还是仅影响此一个?如果您将此代码移至不同的方法或对其进行一些更改,它仍然会错误地构建吗?

如果您不愿意分享有关您的项目的任何其他信息,您可以在 http:// connect.microsoft.com/visualstudio,我们可以私下跟进。

问候,

安东尼·D·格林 |项目经理| Visual Basic编译器

Scott,

The Visual Basic compiler and MSBuild teams are looking into the issue you described but are having trouble reproducing it. Can you reproduce this issue with a small project of perhaps one code file? Does this issue present when building with MSBuild 3.5 on your development workstation or only on the build server? Does it affect all lambdas or only this one? If you moved this code to a different method or changed it a little would it still build incorrectly?

If you don't feel comfortable sharing any additional information about your project you can report this as a bug at http://connect.microsoft.com/visualstudio and we can follow-up privately.

Regards,

Anthony D. Green | Program Manager | Visual Basic Compiler

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文