Unable to load CLR specific version

Author:

Alvin Bruney MVP

COMMUNITY SOLUTIONS CONTENT DISCLAIMER

MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.

SUMMARY

You encounter an exception when you try to target a specific version of the CLR using an application configuration file. This behavior is by design for certain version of the framework.

SYMPTOMS

You receive an exception indicating that the target CLR cannot be loaded. This exception is followed by a BadImageFormat exception in version 2.0 and 3.0 of the CLR. No further error is presented for version 3.5 of the .NET CLR. The application works without issue when built using Visual Studio 2003 targeting earlier versions of the CLR.

CAUSE

The exception is being caused by the .NET framework because key parts of the framework contain version 2.0 specific code. When Visual Studio 2005 is used to create an application, the default CLR target is version 2.0. Previous versions of the framework cannot be loaded. See the More Info section on how to reproduce the issue. Visual Studio 2003 works without issue for versions previous to CLR 1.1. Visual Studio 2005 and Visual Studio 2008 fail consistently when the CLR target is less than version 2.0 of the CLR. CLR targets including 2.0 and later work as intended.

RESOLUTION

There is no suitable, consistent approach to resolve this issue. Either avoid targeting versions prior to CLR 2.0. Or, down-port the code from Visual Studio 2005/8 to Visual Studio 2003. Then, recompile the application to generate a version of the application that targets the correct CLR. This is the recommended approach since, by default, and unless specified otherwise, the CLR version that was used to build the application will be chosen to execute the application.

MORE INFORMATION

Steps to reproduce the problem. Create a Windows Forms application from Visual Studio 2005 or Visual Studio 2008. Add a configuration file. Inside the configuration tags, add these few lines:

<startup>
<requiredRuntimeversion="v1.0.3705"safemode="true"/>
</startup>

Run the application. You will receive an exception indicating that the target CLR cannot be loaded. For Visual Studio 2005, you may receive a further error related to assembly signing. For Visual Studio 2008, no further exception is reported.
 
There are some posted work-arounds that may work for trivial cases. See links:
 
 
The MS Build solution:
– Only works at the command line
 
For this option to work, you will need to install the 1.1 SDK located here:

 
These work-arounds contain serious limitations and are not generally recommended for enterprise applications.
 
Properties

Article ID: 556035 - Last Review: 14 Feb 2017 - Revision: 1

Microsoft .NET Framework Service Pack 2, Microsoft .NET Framework 1.0, Microsoft .NET Framework 1.1, Microsoft .NET Framework Service Pack 1

Feedback