Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Services
I am trying to get the list of sub-directories of a directory from svc service, but it shows an error --
The type System.IO.FileSystemInfo cannot be deserialized as it doesn't has parameter less public constructor.
Please help me out from this situation.
Code Snippet--
private System.Collections.Generic.List<DirectoryInfo> GetSubDirectories(string directoryPath)
        DirectoryInfo dir = new DirectoryInfo(directoryPath);
        DirectoryInfo[] dirs = dir.GetDirectories();
        System.Collections.Generic.List<DirectoryInfo> childs = new System.Collections.Generic.List<DirectoryInfo>();
        foreach (DirectoryInfo dir1 in dirs)
           // XmlObjectSerializer xml_serial = new XmlObjectSerializer(typeof(XML_directory));
        return childs;
    catch (Exception) { return null; }
    //return null;
Posted 8-Mar-13 6:28am
Edited 8-Mar-13 7:14am
sjelen at 8-Mar-13 12:11pm
Improve your question with some relevant code, so we can see what you are trying to do.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

My first suggestion would have been to try to create an inherited object from the directoryinfo class. But it is sealed. Anyway I would not recomend to you to return with a list of DirectoryInfo. I would create a DTO (Data Transfer Object). See the following:
The DTO:
public Class DirectoryInfoDTO
  public DateTime CreationTime {get ; set;}
  public string Name {get ; set;}
And then the code: // Include: System.Linq;
var result = dirs.Select((a,b) => new DirectoryInfoDTO()
                      Name = a.FullName,
                      CreationTime = a.CreationTime
the result will be a collection of DirectoryInfoDTO

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 645
1 Maciej Los 225
2 Abhinav S 171
3 Richard Deeming 160
4 Suvendu Shekhar Giri 159
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 9,135
2 Peter Leow 5,042
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,581

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100