1

is it ok if i have this X project using .net2.0, and that X project is calling Y project which is using .net3.5.. i got customized buttons in Y project and im using that button in X project also, there's a method in Y project that has LINQ and X project is calling that method... i cant test it because i installed the latest .net framework.. :)

this is my code in project that has the .net3.5

    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    public static extern int GetDriveType(string lpRootPathName);        

    public enum DriveType : int
    {
        Unknown = 0,
        NoRoot = 1,
        Removable = 2,
        Localdisk = 3,
        Network = 4,
        CD = 5,
        RAMDrive = 6
    }
    var selectedDrives = from s in Environment.GetLogicalDrives() where Enum.GetName(typeof(DriveType), GetDriveType(s)).Equals(DriveType.Removable) select s;
        foreach (String drives in selectedDrives)
        {
            MessageBox.Show(drives);

        }

correct also the LINQ statement if i did it wrong.. :)

1
  • will a string (GetName) ever equal an int/enum ? I'm thinking: not. Commented Jun 6, 2011 at 13:36

2 Answers 2

3

If the 3.5 framework is not installed on the machine that executes this, it will fail as System.Linq.dll won't exist. You can use LINQBridge with .NET 2.0 and C# 3.0 (which will give you access to a re-implementation of LINQ-to-Objects) but in reality it may be easier to get the client to upgrade. 2.0 is pretty old now.

Alternatively... if all you need is a where, there are easier routes. For example:

foreach (String drives in Environment.GetLogicalDrives())
{
    if(!Enum.GetName(typeof(DriveType), GetDriveType(s))
        .Equals(DriveType.Removable))
    {
        continue;
    }
    MessageBox.Show(drives);
}
Sign up to request clarification or add additional context in comments.

2 Comments

but in the case of using linq, is code in my question is also working?
@vrynxzent allow me to repeat: it depends on whether the 3.5 framework is installed on the machine that executes it. If yes: yes. If no: no.
0

A .NET 2.0 project cannot call a method in a .NET 3.5 project.

3 Comments

Actually, it can. Especially if you compile in VS2008 which is less fussy. Or use reflection. Or various other things. The key question is: "does the target machine have .NET 3.5?"
I hesitated to post the answer after I typed it. I decided to, hoping someone would post something similar to what you did (w/ details, like those you mentioned, that I didn't have the knowledge to anticipate). A better answer would have said that trying to call a .NET 3.5 method from a .NET 2.0 project might not be advisable for someone new to .NET (or programming in general).
Even if the target machine doesn't have .NET 3.5, a .NET 2.0 project can use .NET 3.5 stuff if it includes the proper dlls from .NET 3.5, though actually taking advantage of this is potentially a violation of a license and definitely bad practice. I don't think the 3.5 dlls are supposed to be redistributed piecemeal. Keep in Mind that .Net 2.0 and .NET 3.5 use the same CLR.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.