UPDATE The following steps are no longer necessary if one is using Mathematica version 9 -- it comes preconfigured to use .NET 4.0.
NETLink uses an interlude .NET application to broker communication with the framework. The application is called InstallableNET.exe (InstallableNET32.exe on 32-bit systems) and can be found in this directory:
SystemOpen @
FileNameJoin[{$InstallationDirectory, "SystemFiles", "Links", "NETLink"}]
The application will use the version of the .NET framework that is configured in its .config file. To make it use version 4.0, add a new line within the startup element:
<supportedRuntime version = "v4.0"/>
Versions are tried in the order that they appear in the file, so place the preferred version first. The updated InstallableNET.exe.config will look something like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<!-- The supportedRuntime lines control which version of the .NET Framework will
be used when .NET/Link is launched with InstallNET[].
.NET/Link requires at least .NET 2.0. If you have .NET 3.0 installed,
it will be used (note that the 3.0 version is really just the 2.0
version with some extra assemblies).
-->
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
Note: If you're using Mono instead of Microsoft's CLR, you'll have to delete the first few (invisible) bytes from the XML file due to a Mono bug. One way to do this would be to tell your text editor to save the XML file as ASCII instead of Unicode. Another way would be to copy and paste the body of the file into a new file and then copy the new file over the previous InstallableNET.exe.config file.