Iterator equivalent in .net 4.0 - vb.net

Anyone knows about the Iterator equivalent in .net 4.0?
I have a ( Iterator Function / Yield ) code sample which will not compile in my .NET fw 4.0 project.
Need to change it to work in vs.net 2010 .net 4.0, any idea how to proceed?
Thanks.
My sample won't compile in .net 4.0
Private Shared Iterator Function AllNodes(ByVal nodes As NodeCollection) As IEnumerable
For i As Integer = 0 To nodes.Count - 1
Dim node As Node = nodes(i)
Yield node
If node.Nodes.Count > 0 Then
For Each item As Node In AllNodes(node.Nodes)
Yield item
Next item
End If
Next i
End Function

You need the compiler for at least Visual Basic 11 (from Visual Studio 2012) to build code using iterator blocks. IIRC, the .Net 4.0 runtime itself does support this, but you need the newer compiler/build environment.
But Visual Studio 2010 is very old now and completely unsupported. Later versions are free, and can target the older runtime, so take this as a good opportunity to upgrade.

Related

COMInterop - System cannot find file - IDE only

I've an old VB6 program which I have haven't used for several months. The program references numerous C# assemblies (.NetFramework 4.8). Running the programs as binaries, it all works fine.
I have opened the VB6 ide to step some of my code and I am now encountering an automation error "The system cannot find the file specified." (Err 80070002) when trying to instantiate one of the COM Interop classes. This didn't used to happen.
Private Sub InitMessageStore()
Dim l_oBusFactory As IfxBusService.BusFactory <= COM Interop reference
Set l_oBusFactory = New IfxBusService.BusFactory <= ERROR here
l_oBusFactory.InitialiseMessageStore GetConnection(m_oIfxsys.Dbase.Database.Definition)
End Sub
The COM Interop decls
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IBusFactory))]
[Guid("200C6C26-6881-4CB5-A8E7-E0E5532D6D5F")]
public class BusFactory : IBusFactory
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[Guid("5531BD20-2C7B-452B-A7D7-2D05E39EB83E")]
public interface IBusFactory
I have rechecked the registry registrations for the above ... the salient one being
and the file is in the folder location as specified in the registry.
I'm using Win10 Version 10.0.19044 Build 19044. I'm running everything as administrator. I have DEP switched to essential Windows programs and services only.
As I said above, everything works fine when run as binaries, but, to me, it looks like the OS is stopping the VB6 ide from loading a COM Interop assembly.
Any suggestions as to how I can get stepping through (but not necessarily into) my COM Interop code working again.
In the end, I missed that there were 2 entries under the InprocServer32, one of which pointed to the correct file (1.0.0.0), but the other one (5.80.0.111 - which is actually the version no of our com binaries) didn't point to a file:///, but rather the pure .net assembly. Once I deleted the incorrect one, it all started working ok.
Still not sure where the wrong one came from!

Compiling Visual basic adds cast operations

On compiling a visual basic assembly, int32 variables are cast as int64 for calls to adodb methods that require int32. This results in a method not found exceptions at run time. The unnecessary cast operation can be seen when using reflector to inspect the site of the method call and is not present in the source code.
To further muddy the waters when the code is compiled on my 64bit windows 7 machine all is well, but on a 64bit windows 2008 r2 the unnecessary cast is added.
Does any one know how to stop this happening?
Try compiling the app specifically for x86/32bit.
How do I force MSBuild to compile for 32-bit mode?

VB.Net 2008 IDE hanging - MSVB7.dll eating 100% CPU when editing code

Edit 1: Uninstalled & Reinstalled
Edit 2: Same problem. Seriously? Yes.
I am having a problem with msvb7.dll eating 50%+ cpu on my dual core system. This usually lasts 10-30 seconds or so, during which time the IDE is non-responsive.
This occurs when I do pretty much anything in the text editor, and can be replicated by simply adding blank lines to a function, and then deleting them. Or pasting some code. Or... lotsa stuff.
SP1 installed
I had DevExpress' refactor/coderush, components, and codeit.right installed, but have removed all 3 of them.
(I had installed the latest version of Refactor Pro! (9.3.4), perhaps the day before)
I have tried a VS.NET Repair.
There is a kb that referenced some cpu destroying with vb, but it was included in SP1
Also:
The solution consists of ~30 VB projects and 2 C# projects
8 other developers aren't having any issues with this (or at least not the SAME issues, we all have em)
Clean get from TFS was done
Project builds properly, can can even debug.
This doesn't seem to happen on really small solutions, but perhaps it does and it just goes away super quick.
Any clues at all as to what might be causing this, or how to fix it? I REALLY don't want to lose another day uninstalling and reinstalling and patching and so on =) If that even fixes it.
Edit looking at these two hotfixes. Applied 957912, the first one
KB957912: Updates for Visual Studio 2008 SP1 debugging and breakpoints
KB967631: When you debug in Visual Studio 2008 Service Pack 1, more breakpoints are generated unexpectedly, or the IDE crashes or becomes unresponsive for about 15 seconds
Here is the stack trace (process explorer) that I get from the threads window when the msvb7.dll is churning.
--- title in process explorer [threads] tab for process --------
cpu:49.28% cswitch delta: 300 to 3500 startaddress: [msvb7.dll+0x4218c]
msvb7.dll version: 9.0.30729.1
--- actual stack trace -------
ntkrnlpa.exe!KiUnexpectedInterrupt+0x121
ntkrnlpa.exe!ZwYieldExecution+0x1c56
ntkrnlpa.exe!KiDispatchInterrupt+0x72e
NDIS.sys!NdisFreeToBlockPool+0x15e1
// shortened stack trace. all of these are from msvb7,
msvb7.dll+0x46ce7 <- 0x2676a <- 0x2698e <- 0x38031 <- 0x2659f <- 0x26644
msvb7.dll+0x25f29 <- 0x2ac7a <- 0x27522 <- 0x274a0 <- 0x2b5ce <- 0x2b6e4
msvb7.dll+0x67d0a <- 0x68551 <- 0x6817b <- 0x681f0 <- 0x67c38 <- 0x65fa8
msvb7.dll+0x666c6 <- 0x6672c <- 0x6673d <- 0x6677c <- 0x667b4 <- 0x63c77
msvb7.dll+0x63e97 <- 0x42c3a <- 0x42bc1 <- 0x41bd7
kernel32.dll!GetModuleFileNameA+0x1b4
This is the list of stuff from "copy info" in help->about, shortened to a resonable length.
Microsoft Visual Studio 2008 | Version 9.0.30729.1 SP
Microsoft Visual Studio 2008 Professional Edition - ENU Service Pack 1 (KB945140) KB945140
Microsoft .NET Framework | Version 3.5 SP1
Microsoft Visual Basic 2008
Microsoft Visual C# 2008
Microsoft Visual F# for Visual Studio 2008
Microsoft Visual Studio 2008 Team Explorer | Version 9.0.30729.1
Microsoft Visual Studio 2008 Tools for Office
Microsoft Visual Web Developer 2008
Hotfix for Microsoft Visual Studio 2008 Professional Edition - ENU
KB944899, KB945282, KB946040, KB946308, KB946344, KB946581, KB947171
KB947173, KB947180, KB947540, KB947789, KB948127, KB946260, KB946458, KB948816
Microsoft Recipe Framework Package 8.0
Process Editor WIT Designer 1.4.0.0
Process Editor for Microsoft Visual Studio Team Foundation Server, Version 1.4.0.0
tangible T4 Editor 9.0
tangible T4 Text Template Editor - T4 Editor
tangibleprojectsystem 1.0
Team Foundation Server Power Tools October 2008
SQL Prompt 4.0 (disabled)
Use Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) and trace the activity of Visual Studio when it exhibits this behavior. I have done this many times before with great success.
I am actually monitoring Excel on startup to determine why Excel is having problems with a VSTO Add-in. It turns out Excel is trying to also load a previous version, so I have two add-ins loaded. I figured this out in less that a minute. Without Process Explorer I might have been troubleshooting for hours or days.
I've seen something similar happen when you have a circular reference in a specific way in a class. It's trying to show intellisense and ends up in an infinite loop trying to build the list. I don't remember the exact circumstances now, though.
Given up and wiped VS 2008 & all supporting software. Reinstalling now. It is fun to debug, but I had to cancel a meeting this morning because I couldn't get anything going.
If I get a job at MS then I'll look into it further... but this one is just too hard for
me and my limp debugging skills leftover from years doing .net ;)
DOH! Reinstalled and it is still broke! I may actually have to solve this :(
#amissico: thanks, i had forgotten about that completely.
The problem is somewhere in the parsing thread, and I can't work out how to pinpoint what it is doing wrong. I see lots of FS activity, but nothing that I can identify as wierd. It just keeps building temp files (all the same name?) It just looks like it is doing everything everytime, the slow way. I don't know what it should look like, though.
Startup is fine, this is mostly happening when I edit files. It just starts chewing for intellisense, it appears, but why it takes so long is wierd.

Problem with Statement Completion in Visual Studio 2008 SP1

After installing SP1 of Visual Studio 2008, code completion shows all types when an object member shows the parameter list. Before SP1, parameter list would only show related types.
Take a look at this image for an example: http://img25.imageshack.us/img25/3484/vs2008sp1intellisense.png
Has any one else had this problem? Solutions?
This happens on a Windows 7 and Windows XP machines I have, all services packs installed.
Thanks
Javier Soques
This isn't related to the service pack. I've verified the same behavior on an RTM version of Visual Studio 2008.
What you're seeing here is an issue of overload resolution. In the particular example you are using the MessageBox.Show method which has 21 overloads.
With no arguments and just MessageBox.Show( typed in the editor it's ambiguous as to which version you will be calling. So instead of showing specific types, it will show the completion list for all expression types.
Once the overload is not ambiguous it will show the specific type list. For instance if you type
MessageBox.Show("foo","bar",
It will show only the button enumeration completion.

VB.NET and BITS - Background Intelligent Transfer Service

Has any one used BITs in VB.NET? If so, do you have code samples and advice?
I was looking at SharpBits but I have a VB project that I wanted to use BITS for. Is it possible to use it with my VB.NET program? (.NET 2.0) I was tempted to try to convert each class to VB.NET in the SharpBits.Base folder but figured I'd ask in case someone has headed down this route before.
Edit: Ok folks in case you run across this question. What you can do is in the Sharpbits.Base folder (that you download from codeplex) there is a DLL you can reference in the Bin directory. You can add that into your references to access it. Marking Konrad as answer since he was kind enough to post.
Further edit:
I managed to get sharpbits working with some quick code which I pasted below for anyone who might stumble upon this question. Like I mentioned above add the DLL to your project.
Dim b As New SharpBits.Base.BitsManager
Dim mynewjob As SharpBits.Base.BitsJob = _
b.CreateJob("jobname", SharpBits.Base.JobType.Download)
mynewjob.AddFile("\\server\share\bigfile.zip", "c:\bigfile.zip")
mynewjob.Resume()
You'll need to write some logic to check for the status of the job. Once it hits "Transferred" status you can then mark it as complete. This will write the file from a .bin to the file name you listed. Something that helped me was installing the Windows Support Tools (you can get it from a Windows 2003 Cd/DVD in the sup tools folder)and using Bitsadmin.exe to view the status of the job while debugging. Hope this helps the next rookie. =)
Any reason why you can't simply use SharpBits in VB? The advantage of .NET is precisely that libraries written in the different .NET languages can interoperate seamlessly so you can simply use SharpBits in VB, no matter what .NET-compliant language it was written in.
You could take a look here:
Using Windows XP Background Intelligent Transfer Service (BITS) with Visual Studio .NET
I have started from here to write my own library to manage BITS to transfer big video file across private LAN. Example are for NET 1.1 but should not be difficult port it to NET 2.0.
Here's a new alternative. The BITS team at Microsoft now has a page on Calling into BITS from .NET and C# using reference DLLs plus a complete sample call BITS Manager on GitHub.
I've just tried using them with Visual Basic; my code ended up looking like this:
Imports BITS = BITSReference1_5
Module Module1
Sub Main()
Dim mgr = New BITS.BackgroundCopyManager1_5
Dim jobGuid As BITS.GUID
Dim job As BITS.IBackgroundCopyJob
mgr.CreateJob("My simple job", BITS.BG_JOB_TYPE.BG_JOB_TYPE_DOWNLOAD, jobGuid, job)
job.AddFile("http://www.microsoft.com", "c:\temp\2019\BITS-VB\Downloadfile.html")
job.Resume()
End Sub
End Module
(Note that I also added a reference to a DLL that I downloaded from the BITS Manager source from the Reference DLL directory)