How to reference framework 4.0 dll in project targetting 3.5 in VS2008

后端 未结 1 744
醉话见心
醉话见心 2021-02-10 16:12

I have a dll created in VS2010 using the 4.0 framework (yes it\'s the full 4.0, NOT the client profile). I would like to reference it in a VS2008 project (meaning I can\'t re-t

1条回答
  •  情深已故
    2021-02-10 17:07

    When you create a project that targets a specific version of the framework, you're telling the compiler which version of the framework libraries and runtime that the computer on which the project will run has installed. For example, System.dll in 3.5 and System.dll in 4.0 aren't the same, much like why System.dll in 2.0 and 3.5 aren't the same.

    In theory, you can't guarantee forwards compatibility (3.5 referencing a 4.0) because the 4.0 assembly may use APIs that aren't present in 3.5. Likewise, you can't guarantee 2.0 backwards compatibility in 4.0 because some of the APIs may have been deprecated and removed.

    In practice, 4.0 has enough backwards compatibility with 3.5 that they allow you to reference 3.5 assembles in 4.0 applications, with some caveats (you sometimes need to add a directive in your configuration file, since assembly loading in 4.0 changed from 3.5). Unfortunately, 3.5 doesn't have much forwards compatibility with 4.0 due to the massive number of new APIs that 4.0 introduced, so I don't think that you can reference 4.0 assemblies from 3.5.

    You're seeing that schema information exception for probably this reason. the "supportedRuntime" is a configuration element that was introduced with .NET 4.0. But since you're referencing the assembly in 3.5, the .NET 3.5 version of System.Configuration, which parses the configuration file, doesn't recognize that element and thus throws an exception.

    The only way is probably to (1) change the source and re-compile, fixing all the API calls to 4.0 libraries that don't work in 3.5, or (2) do the same thing, but at the IL level, generating a new assembly (you can do this with al.exe).

    0 讨论(0)
提交回复
热议问题