views:

105

answers:

1

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
+1  A: 

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

Anthony D. Green
This issue occurs when using MSBuild 3.5 on all computers where we have tried it. This is the only lambda affected, there are many others in the assembly. I will try to create a simplified version which has the same problem.
ScottS
@Anothony D. Green I have submitted an issue on connect at https://connect.microsoft.com/VisualStudio/feedback/details/581743/vbc-3-5-produces-different-il-than-vbc-4-for-the-same-codeI was unable to reproduce this problem in a simpler way, we can privately share source for the dll there, if required.
ScottS
@ScottS. That link is broken....
LordHits