简体   繁体   中英

Can I add a reference to System.Core.dll (.net 3.5) to a .net 2.0 application and use it

Can I add a reference to System.Core.dll (.net 3.5) to a .net 2.0 application and use it

I am trying to use the TimeZoneInfo class which is available in .net 3.5 only, by referencing System.Core.dll

Alternatively, is their an alternate for TimeZoneInfo in .net 2.0 (or a customised class)

No you really should not . You must install 3.5 on the target machine or you will run into unpredictable behavior in the running program. The 3.5 framework including System.Core.dll depend on several bug fixes / features that were added to CLR 2.0 SP1 (this is a part of 3.5 framework). If you run against an unpatched CLR you will be essentially running untested code and will likely hit several bugs.

Scott Hanselman wrote a blog post describing how to run an early version of MVC on the 2.0 framework. He noted that the dependencies on System.Core will probably be OK as long as you are very careful not to call any routines that depend on CLR features specific to 3.0+ (for example, LINQtoSQL).

He rightly plastered the blog post with disclaimers that it is not supported, it very well might not work for you, but he got it to work and if you can, then yay for you.

I'm not sure if you can do this with System.Core.dll, but we have done this before with the Linq2Sql dlls for a .net 2.0 application. .net 3.5 uses the same version of the CLR with new assemblies built upon the .net 2.0 runtime. If you can get all of the dependencies, it might work. As I said, this worked for us with Linq2Sql dlls, but is not guaranteed for all scenarios. (For example, you probably wont be able to get WPF to run on Windows 2000, but you might be able to get Linq to Objects to work)

You can do this, currently doing the same thing for a tool for work - also to utilize the TimeZoneInfo stuff. As long as thats all you're using you shouldn't run into any issues (at least I haven't).

However I'm not entirely sure of the legalities of bundling System.Core with your app. From what I know you're not allowed to.

I ended up utilizing the one from Mono for the tool that uses it.

.net 3.5 runs on .net 2.0 runtime. So you should be able to use it... But referencing a single dll would lead to unexpected behaviour as you don't know all the dependencies system.core.dll have.... I would recommend not to do that...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM