Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries for May, 2010

An “could not copy temporary files to the output directory” error is generated in Visual Studio .NET or in Visual Studio 2005

Symptoms
When you build a project in Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, the build fails and you receive the following compile-time error message:

Could not copy temporary files to the output directory. For more information about another cause for this symptom, click the following article number to view the article in the Microsoft Knowledge Base:
313512?(http://support.microsoft.com/kb/313512/) BUG: “Could not copy temporary files to the output directory” error message when you build a solution that contains multiple projects
Resolution
This behavior may occur for one of the following reasons.
Cause 1You may receive this error message when you compile a component that is currently being used by another process. For example, you may try to compile a class library or a user control project. For example, this behavior may occur when the following conditions are true: Multiple instances of Visual Studio .NET or Microsoft Visual Studio 2005 are open. In one instance, you have a UserControl or class library project. In the other instance, you have a project that references the component and the project of the component is open in the first instance.The second instance uses a file reference to the assembly and the Copy Local property of the assembly is set to False.The assembly has been loaded into memory of the second instance of Visual Studio .NET or Microsoft Visual Studio 2005.If the Copy Local property is set to False for the referenced assembly, and the assembly is not installed in the global assembly cache, the assembly will not be copied to the local \Bin folder of the consuming project. To resolve the location of the referenced assembly, Visual Studio .NET or Microsoft Visual Studio 2005 will search the paths that are listed in the Reference Path property of the project until it finds the assembly. In a scenario where the assembly has been loaded, such as a UserControl loaded in the Windows Form designer, the assembly is being used and cannot be overwritten when you try to build it. When this behavior occurs, you receive the error message that is mentioned in the “Symptoms” section.
As soon as the assembly has been loaded in memory of the Visual Studio .NET or Microsoft Visual Studio 2005 IDE, the assembly will not be unloaded until you exit and then restart the Visual Studio .NET or Microsoft Visual Studio 2005 IDE. For more information, see the “Resolution” section.
Cause 2 This behavior also occurs if you try to build the application when you are currently running an instance of the application from its \Bin folder, externally of the Visual Studio .NET or Microsoft Visual Studio 2005 IDE.
During the build process, the compiler builds the project to an intermediate folder, such as Obj\configname. In this folder name, configname is the name of the project. When the build process has completed, the files are copied from the intermediate folder into the output folder. The “Could not copy temporary files to the output directory” error message indicates that the compiler could not copy these files from the intermediate folder to the output folder. If you run the application that is being built from the output directory, the compiler cannot overwrite these files because they are currently being used. For more information, see the “Resolution” section.

A string that you pass to an unmanaged Win32 API in Visual Studio .NET or in Visual Studio 2005 returns empty

Symptoms
When you pass a String data type variable to a Win32 application programming interface (API) as an out parameter, the string that the Win32 function call returns does not change.
Resolution
This problem occurs because you cannot modify Visual Basic .NET, Visual Basic 2005, and Visual C# strings. By default, you cannot change the String class after the String class is created. For more information about the String class, see the “References” section.

“Unable to set the next statement to this location” error message when you are debugging a Visual Studio 2005 application

Symptoms
When you are debugging a Microsoft Visual Studio 2005 application and you try to set the next statement, you may receive an error message that resembles the following error message:

Unable to set the next statement to this location. There is no executable code at this location in the source code.
Resolution
The Debugger Engine is picking the statements in sequence. As long as the caret is at the end of the line, the Debugger Engine will set the next statement on the next line. If there is no executable code from the next line, an error message will occur.

“Name ‘DTE’ is not declared” error message while running the “Item Method (General Extensibility)” MSDN sample code

Symptoms
This article describes problems that you may experience when you follow the documentation for the Item Method (General Extensibility) that appears in the following Microsoft Developer Network (MSDN) article:
http://msdn2.microsoft.com/en-us/library/aa301425(VS.71).aspx(http://msdn2.microsoft.com/en-us/library/aa301425(VS.71).aspx)When you paste the sample code from the Example section of the article to a Visual Basic .NET application, and then you try to compile the file, you receive the following error message:

Name ‘DTE’ is not declared.When you try to assign the return value of the EnvDTE.Documents.Item method to an AddIn type variable, you receive the following error message:

An unhandled exception of type ‘System.InvalidCastException’ occurred in ApplicationName.exe
Additional information: Specified cast is not valid.When you pass an Object parameter to the EnvDTE.Documents.Item method, you receive the following error message:

An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in ApplicationName.exe
Additional information: Type mismatch.
Resolution
You receive the “Name ‘DTE’ is not declared” error message because the variable named DTE is not declared in the sample code that is provided in the MSDN article. You receive theInvalidCastException error message because the MSDN article states that the return value for the EnvDTE.Documents.Item method is an AddIn type. However, the EnvDTE.Documents.Item method returns a Document type object. Therefore, when you try to assign a Document type object to an AddIn type variable, you receive the error message.You receive the Type mismatch error message when you try to pass a parameter that is not an Integer or a String to the EnvDTE.Documents.Item method. The EnvDTE.Documents.Item method is used to gain access to the elements of the EnvDTE.Documents collection. The EnvDTE.Documents.Item method can accept only two types of parameters:Integer – for the index value of the documents in the EnvDTE.Documents collectionString – for the key of the documents in the EnvDTE.Documents collection

“Invalid command” or “Installation wizard” errors during Setup after the CD key prompt

Symptoms
After you start the installation of Visual Studio 6 (or a standalone Visual Studio product), Visual Studio 6 Service Pack 5, or Visual Studio 6 Service Pack 6 on Microsoft Windows NT, on Microsoft Windows 2000, or on Microsoft Windows XP, you may receive one of the following error messages before or after you enter the CD key:

Setup has encountered a problem and needs to close

Installation wizard couldn’t find Acme setup

Installation wizard cannot find Acme setup

Setup error 530 invalid command line

Setup Error 530 invalid command option in settings \administrators\localsettings\temp\vs60wiz.exe

Setup error 725 invalid command line

Application Error in VS60wiz.exe

Setup initialization error; there is insufficient memory to run setup

Setup initialization error; there is insufficient disk space to run setup

The specified path does not exist. Check the path and then try again
Resolution
Setup does not succeed at the Windows NT Virtual DOS Machine (NTVDM) level as installation is handed off to Acmsetup. This is caused by a corrupt 16-bit subsystem.

“Differences Between Visual Basic .NET and Visual C# .NET” white paper is available

Symptoms
This article points to the “Differences Between Microsoft Visual Basic .NET and Microsoft Visual C# .NET” white paper.
Resolution
Because of the previous differences between Visual Basic and C/C++, many developers assume incorrectly about the capabilities of Visual Basic .NET. Many Visual Basic developers think that Visual C# is a more powerful language than Visual Basic. In other words, Visual Basic developers assume that you can do many things in Visual C# that you cannot do in Visual Basic .NET, just as there are many things that you can do in C/C++ but cannot do in Microsoft Visual Basic 6.0 or earlier. This assumption is incorrect.
Although there are differences between Visual Basic .NET and Visual C# .NET, both are first-class programming languages that are based on the Microsoft .NET Framework, and they are equally powerful. Visual Basic .NET is a true object-oriented programming language that includes new and improved features such as inheritance, polymorphism, interfaces, and overloading. Both Visual Basic .NET and Visual C# .NET use the common language runtime. There are almost no performance issues between Visual Basic .NET and Visual C# .NET. Visual C# .NET may have a few more “power” features such as handling unmanaged code, and Visual Basic .NET may be skewed a little toward ease of use by providing features such as late binding. However, the differences between Visual Basic .NET and Visual C# .NET are very small compared to what they were in earlier versions.
The “Differences Between Microsoft Visual Basic .NET and Microsoft Visual C# .NET” white paper describes some of the differences between Visual Basic .NET and Visual C# .NET. However, remember that the .NET Framework is intended to be language independent. When you must select between Visual Basic .NET and Visual C# .NET, decide primarily based on what you already know and what you are comfortable with. It is easier for Visual Basic 6.0 developers to use Visual Basic .NET and for C++/Java programmers to use Visual C# .NET. The existing experience of a programmer far outweighs the small differences between the two languages.
No matter which language you select based on your personal preference and past experience, both languages are powerful developer tools and first-class programming languages that share the common language runtime in the .NET Framework.
The following file is available for download from the Microsoft Download Center:

Collapse this imageExpand this image
Download the “Differences between Microsoft Visual Basic .NET and Microsoft Visual C# .NET” white paper package now.(http://download.microsoft.com/download/6/3/5/6354bf47-c597-4029-89e9-2495e7539ab9/vbcsharpwp.exe)Release Date: June 18, 2002
For more information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591?(http://support.microsoft.com/kb/119591/)How to obtain Microsoft support files from online servicesMicrosoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help prevent any unauthorized changes to the file.