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