Error CS0016: Could not write to output file

No Comments »

If you attempt to run an ASP.NET application hosted on IIS running on Windows Home Basic or Premium, you may receive the following error:

error CS0016: Could not write to output file ‘c:WindowsMicrosoft.NETFramework…

More information >

Step into: Stepping over method without symbols

2 Comments »

When debugging a project line-by-line in Visual Studio, you may receive this error:

Step into: Stepping over method without symbols ‘namespace’

This error occurs when you attempt to debug a DLL or EXE that is lacking a symbols (.pdb) file. 

Check the project’s binDebug folder to ensure the DLL/EXE in question has a corresponding pdb file.  If not, be sure to build the DLL/EXE with its project configuration set to “Debug” so that it will generate a pdb file. 

If the problem occurs with a third-party library, you may be out of luck because most third-party libraries do not include a pdb file, and therefore you cannot debug into them.

A StackOverflow article says this error may also occur if you attempt to debug a yield expression in a method that returns an IEnumerable, though I have not confirmed this.

Visual Studio Startup Project Not Saved in Solution File

No Comments »

If you have multiple Projects in a Visual Studio Solution, you can specify the “Startup Project,” which is the project that runs when you “Start Debugging” or “Start Without Debugging”.  The Startup Project appears bold in the Visual Studio Solution Explorer.  Step-by-step instructions to set the Startup Project can be found here.

If you use a source repository, perform automated builds, or do any Visual Studio solution file hacking, you may be disappointed to discover that the Startup Project is not saved in the Solution file (.sln), but rather in the Solution User Options file (.suo). 

The Solution User Options file contains settings — such as breakpoints, open files and views — that are specific to the current user.  Therefore the User Options file is not usually saved in a source repository, so it’s difficult to share the Startup Project across a team.

In addition, while the Solution File is an easy-to-modify XML file, the Solution User Options file is a hard-to-modify binary file, so it’s nearly impossible to programmatically set the Startup Project.

Which means that each developer must manually set the Startup Project for each Visual Studio Solution.

Run ASP.NET and IIS on Windows Vista and 7 Home Premium

2 Comments »

If you attempt to run an ASP.NET application hosted on IIS7.0 running on Windows Home Basic or Premium (Vista or Windows 7, x86 or x64), you may receive the following error:

error CS0016: Could not write to output file ‘c:WindowsMicrosoft.NETFramework64v2.0.50727Temporary ASP.NET Files…

Apparently this problem occurs because Windows Home Basic and Premium lack Windows Authentication.  So the common response on the Web is to upgrade to Windows Home Ultimate, Business or Professional.  However, there is no need to upgrade, as you can solve this problem with a few mouse clicks:

Read the rest of this entry »

Load a .NET Assembly into a Separate AppDomain So You Can Unload It

3 Comments »

There may be times when you wish to temporarily load a .NET assembly to inspect it, but you don’t want the assembly to remain in your program’s memory taking up resources.  Unfortunately, once your program loads an assembly, there is no way to unload it.  The best way is to create a separate AppDomain, load the assembly into that AppDomain, then unload the AppDomain when you are finished.

The following sample code loads a .NET assembly from disk, displays the name of every type defined in the assembly, then unloads the assembly:

AppDomain appDomain = null; 
try 
{ 
    string path = @"C:myAssembly.dll"; 
    byte[] buffer = File.ReadAllBytes( path ); 

    appDomain = AppDomain.CreateDomain( "Test" ); 
    Assembly assm = appDomain.Load( buffer ); 

    Type[] types = assm.GetTypes(); 
    foreach (Type type in types) 
    { 
        Console.WriteLine( type.FullName ); 
    } 
} 
catch (Exception ex) 
{ 
    Console.WriteLine( ex.Message ); 
} 
finally 
{ 
    if (appDomain != null) 
        AppDomain.Unload( appDomain ); 
}

Solution file error MSB5014

1 Comment »

The following error may occur when building a Visual Studio solution with the MSBuild program:

Solution file error MSB5014: File format version is not recognized.  MSBuild can only read solution files between versions 7.0 and 9.0, inclusive.

This error may occur when compiling a solution for Visual 2008 or 2010 with the MSBuild program that came with Visual Studio 2005.  The problem is that VS 2005 does not understand the newer solution file formats.  To eliminate this error, use the newest version of MSBuild available (check your system):

C:WindowsMicrosoft.NETFrameworkv3.5msbuild.exe
C:WindowsMicrosoft.NETFrameworkv4.0.30319msbuild.exe

ComboBox Exception: “Too many items in the combo box”

1 Comment »

The .NET ComboBox may throw a cryptic OutOfMemoryException with the following message:

Too many items in the combo box.

This poorly-worded exception results when you Add an object to the ComboBox whose ToString() method returns a null or empty string. 

To fix this error, make sure that for every object that you add to the ComboBox, the ToString() method returns a non-empty string.

How to Launch a Process Synchronously

1 Comment »

Most developers use the Process.Start static method to run an external application from within C# code.  The Start method launches the external process asynchronously, meaning that your C# code continues executing and does not wait for the process to finish.

But occasionally you may wish to halt your program and wait for the external process to finish.  So to launch a process synchronously from a C# application, the key is to create a Process object and call the WaitForExit method after you start the process.  Be sure to finish with a call to the process Close method.  Here is some sample code:

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo( "notepad.exe" );
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
process.Close();
MessageBox.Show( "Process Complete" );

Where to Find SN.exe

1 Comment »

SN.exe is a Strong Name tool that can sign assemblies, manage strong name keys, and generate and verify signatures.  You will typically find it here:

C:Program Files (x86)Microsoft Visual Studio 8SDKv2.0Bin

If you cannot find it there, check “C:Program Files” on 32-bit systems.  Also check the folders corresponding to other versions of Microsoft Visual Studio, such as “Microsoft Visual Studio 9.0” etc.  If you still cannot find it, run a search on your C: drive. 

If SN.exe is not installed on your hard drive, you can download it here:

.NET Framework 2.0 Software Development Kit (SDK)
x86   x64

According to Microsoft, since .NET Framework versions 3.0 and 3.5 are built incrementally on the .NET Framework version 2.0, many of the tools included in the .NET Framework 2.0 SDK are the latest versions available.  But just in case, you can download the newest version of .NET:

.NET Framework 4 redistributable package

Display Icons in a ListBox

No Comments »

The standard Windows Forms ListBox control is not designed to display an icon with each item.  You can modify the ListBox to handle the DrawItem event and manually draw the items and their associated icons, as shown here and here

However, if you were hoping to use a standard off-the-shelf control with full icon support, your best bet is to use the ListView control.

keep looking »