How to reference framework version 4.0 4.0 in project 3.5 in VS2008

I have a dll built in VS2010 using framework 4.0 (yes, this is full 4.0, not a client profile). I would like to reference it in a VS2008 project (which means I cannot redirect the referenced project to 4.0 even if I wanted to) and upgrading that project to VS2010 is not an option.

I understand why there are problems referencing 4.0 projects in 3.5 projects, but I do not understand why I am having a problem referencing 4.0 dlls in 3.5 projects. And for everyone I know, it might not be a problem, but I can't imagine what else it might be.

I'm trying to use Fasterflect (http://fasterflect.codeplex.com/), which relies heavily on 4.0 features in my 3.5 project (and again my company isn't ready to shell out money for VS2010 so I might not change that). At first everything seemed to be fine until I tried to compile errors related to the Fasterflect assembly not being signed. So I downloaded the actual source code, signed it, recompiled, and referenced my newly signed assembly. The problem is now it displays a caution symbol and says:

The resolved file has a bad image, no metadata, or is otherwise unavailable. Could not load file or assembly 'C: .... \ Fasterflect.dll' or one of its dependencies. This assembly is built with a runtime that is newer than the currently loaded runtime and cannot load.

I tried the following answer suggested here: http://social.msdn.microsoft.com/Forums/en/clr/thread/36b1a209-55d5-4323-91dc-0919ba2e1d03 . However, I get an error when I do this:

Could not find schema information for element 'SupportedRuntime. C: .... \ DynamicSql \ App.config

And I can't figure out this error either.

Surely there must be SOME way to use this DLL in VS2008 ??

+3


source to share


1 answer


When you create a project that targets a specific version of the framework, you tell the compiler which version of the framework libraries and the runtime that the computer running the project was running on. For example, System.dll in 3.5 and System.dll in 4.0 is not the same as System.dll in 2.0 and 3.5 is not the same.

In theory, you cannot guarantee forward compatibility (3.5, referring to 4.0), because a 4.0 build may use APIs that 3.5 does not. Likewise, you cannot guarantee 2.0 compatibility in 4.0 as some of the APIs may have been deprecated and removed.

In practice, 4.0 has sufficient backward compatibility with 3.5 that it allows 3.5 assemblies to be referenced in 4.0 applications with some caveats (sometimes you need to add directives in your config file, since an assembly in 4.0 changed from 3.5). Unfortunately 3.5 doesn't have much forward compatibility with 4.0 due to the sheer number of new APIs introduced in 4.0, so I don't think you can reference 4.0 builds from 3.5.



You see this exclusion of schema information, probably for this reason. "supportedRuntime" is a configuration item that was introduced with .NET 4.0. But since you are referencing the assembly in version 3.5, the .NET.System.Configuration version that parses the configuration file does not recognize this element and thus throws an exception.

The only way, perhaps, is (1) change the source and recompile, fix all API calls for 4.0 libraries that don't work in 3.5, or (2) do the same, but at the IL level, creating a new assembly (you can do this with al.exe).

+6


source







All Articles