mkn07 0 Newbie Poster

Hi, friends
I have a problem with the web service return value.
I have to do returning complex value from the service but when try to do, i take the below message. I succeeded the case with another method as creating class for the returning value but for System.IO.FileInfo, i cannot create a new class. How can i correct this error? Please, help.

The error message:
System.InvalidOperationException: System.IO.FileInfo cannot be serialized because it does not have a parameterless constructor.

code:

[WebMethod]
        [XmlInclude(typeof(FSDirectory))]
        [XmlInclude(typeof(FileInfo))]
        public FSDirectory getfilename(string filename, bool create)
        {
            FileInfo file = new FileInfo(GetIndex() + "//"+filename);
            FSDirectory dir;
            dir = FSDirectory.GetDirectory(file, false);
            file = new FileInfo(file.FullName);
            //FSDirectory dir;
            lock (DIRECTORIES.SyncRoot)
            {
                dir = (FSDirectory)DIRECTORIES[file];
                if (dir == null)
                {
                    try
                    {
                        dir = (FSDirectory)System.Activator.CreateInstance(IMPL);
                    }
                    catch (System.Exception e)
                    {
                        throw new System.SystemException("cannot load FSDirectory class: " + e.ToString());
                    }
                    dir.Init(file, create);
                    DIRECTORIES[file] = dir;
                }
                else if (create)
                {
                    dir.Create();
                }
            }
            lock (dir)
            {
                dir.refCount++;
            }
            return dir;
        }

note: Also, i add xmlinclude for System.IO.FileInfo, i had same error and no change...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.