tags:

views:

3220

answers:

7

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)

+5  A: 

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.

JaredPar
You're definitely more qualified on this topic than most, but might I suggest *should not* instead of *cannot*?
Rex M
@Rex, I changed it to "should not". I added the cannot originally because I figured there was a legal issue why you could not deploy. But I'm not a lawyer so I rescinded to simply my programming opinion of you "really" shouldn't be doing this :).
JaredPar
A: 

IIRC you'll get an error on startup as it tries to load the appropriate assembly (as the assembly versions won't match with the 2.0 version and the one you reference).

SnOrfus
+3  A: 

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)

NotDan
+6  A: 

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.

Rex M
A: 

.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...

Software Enthusiastic
A: 

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.

saret
Just a caveat around this: you can have issues around Assembly signing, but more to the point the Mono one requires TZ files that it parses - you'd need to set the location to these files to get it to work (a static property on TimeZoneInfo does this: TimeZoneDirectory). You can get these files from here:ftp://elsie.nci.nih.gov/pubThese files are Public Domain in case anyone is worried about the license around them
saret
A: 

I have been doing this for more than 1 year with no problems http://abdullin.com/how-to-use-net-35-syntax-and-compiler-features-for-net-20/

Sameer Alibhai