jeremychan
jeremychan

Reputation: 4479

error due to different .net version?

class Program
{
    static string path = "C:\\Work\\6.70_Extensions\\NightlyBuild\\";

    static void Main(string[] args)
    {
        var di = new DirectoryInfo("C:\\Work\\6.70_Extensions\\NightlyBuild");

        foreach (var file in di.GetFiles("*", SearchOption.AllDirectories))
            file.Attributes &= ~FileAttributes.ReadOnly;

        var files = Directory.GetDirectories(path, "SASE Lab Tools.*");
        foreach(var file in files)
        Console.WriteLine(file);
        foreach(var file in files.OrderByDescending(x=>x).Skip(7))
        Console.WriteLine(file);
        foreach(var file in files.OrderByDescending(x=>x).Skip(7))
        Directory.Delete(file);
    }
}

The above is my code which i complied in VS2008 .net version 3.5. However, when i transfer this to another machine with .net version 3.0, an error occured even under the same environment.

Error:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

I do not have VS2008 installed on that machine and i was wondering if my code has something to do with the error? I tried to go to msdn and researched on Directory.GetDirectories(string, Searchpattern) and only this appeared for the 3.5

Upvotes: 4

Views: 3040

Answers (5)

Botz3000
Botz3000

Reputation: 39670

Code like files.OrderByDescending(x=>x).Skip(7) uses LINQ, which is in System.Core, which is installed with 3.5 and higher. So either install .NET Framework 3.5, or (if you can't) replace the mentioned snippet with your own selection method.

Upvotes: 1

Rowland Shaw
Rowland Shaw

Reputation: 38128

It's failing as v3.5 of the framework is not installed, and your executable references assemblies that are included with it to support the LINQ query in that snippet. Either install v3.5 of the framework (or later) or change your application to target a lower version of the framework (which would mean you'd have to rewrite your LINQ query as "normal" code)

Upvotes: 2

ariel
ariel

Reputation: 16140

You need to change your program to use .net 3.0 (and then replace GetDirectories with some other function), or install .net 3.5 wherever you want to use your program.

Upvotes: 0

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174477

Install .NET 3.5 in the other machine...
The error message can't be any clearer: You linked your program to .NET 3.5 DLLs but they are not installed, so you get an error.

Upvotes: 2

Mr47
Mr47

Reputation: 2655

You are using a DLL that is part of the 3.5 version of the framework. In order for this to work you will of course need this DLL on the client PC.

Upvotes: 1

Related Questions