tags:

views:

613

answers:

1

I have a donet 3.5 dll which I want to use in my old C#2 project, currently I don't want to upgrade the C#2 project.

I added the dll as a reference in the c#2 project and everything was wokring fine.

The problem appeared when I want to use method takes System.Func<int,int,IEnumerator<string>> as argument so the compiler does not know anything about it as it requires System.Core assembly, so adding System.Core assembly will solve the problem ? is there better solution?

+3  A: 

If your current project relies on .NET 2.0, you shouldn't add reference to anything from .NET 3.5 - and if your class library uses anything from .NET 3.5, that would be a problem too if you ever deploy the two of them to a machine with only .NET 2.0 on it.

I would strongly consider one of the three options:

  • Upgrade your .NET 2.0 app to .NET 3.5 (I know you don't want to, but it's probably the best option if you possibly can)
  • Downgrade your class library to target .NET 2.0. (You can still use many C# 3.0 features, but not .NET 3.5 classes)
  • Don't use your .NET 3.5 library from the .NET 2.0 app

If your .NET 2.0 app is only ever going to be deployed on .NET 3.5 machines you could just about get away with mixing and matching, but you'd have to make sure that nothing in the public API depended on .NET 3.5. In the case of Func you can just declare your own matching delegate type, but it's a pain to do that all over the place.

Jon Skeet
I will deploy the whole sys into .NET3.5 machine, currently I solved the problem by adding the dll and System.Core into my .NET2 app and everything is working fine is there a problems? w.r.t writing my own FUNC do you mean replace the dotnet delegate with my own one in .NET3.5 dll?
Ahmed Said
As a fourth option, a lot of people have been using and distributing Mono's System.Core on .net 2.0. See http://evain.net/blog/articles/2008/09/14/c-3-and-linq-on-net-2
Jb Evain