views:

170

answers:

1

in VS2010 write this code and run:

===========

string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework");
string pathV2 = Path.Combine(path, "v2.0.50727");
Assembly assembly = Assembly.Load(File.ReadAllBytes(Path.Combine(pathV2,  System.Windows.Forms.dll")));
Console.Write(assembly.Location); 

================= it will write out: C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll

so, how can I use System.Windows.Forms, Version=2.0.0.0?

thanks

A: 

Why don't you just target .NET 3.5 SP1 (which uses the only System.Windows.Forms assembly)?

Or, if you're going to target .NET 4, then why are you trying to not target .NET 4?

Edit 2: This isn't possible without creating a second assembly that targets .NET 3.5 or earlier.

280Z28
I want to use Control.FromHandle function to get control from another application , I must use System.Windows.Forms.dll Version 2.0, if the target application is base on .net 2.0.
maskx
@maskx: check my edit :)
280Z28
extern alias can not resolve this problemwhen I add refrence of System.Windows.Forms.dll from C:\Windows\Microsoft.NET\Framework\v2.0.50727 , it automatic change to v4.0from my sample code in question, even I load from byte[] ,it will change to v4.0
maskx
@maskx: The only way to do this is create a second assembly that targets the earlier framework and hide the code in there.
280Z28
I have try this way, but failed.careate a assembly base target to fareamework v2.0, when refrence in an application target to framework v2.0 , it is v2.0. but when refrence in an application target to faramework v4.0. all the assembly is change to v4.0, include System.Windows.Forms.dll
maskx
maybe, this problem can not be resolved, refer http://msdn.microsoft.com/zh-cn/library/ee518876(en-us,VS.100).aspx#scenarios
maskx