InvalidOperationException

Sep 4, 2013 at 10:49 AM
Edited Sep 4, 2013 at 10:50 AM
I'm trying to use Linq to AD to fetch some info from AD about Users. My (web service) project compiles but when I try to run it I got the following error:
System.InvalidOperationException: Unable to generate a temporary class (result=1).
error CS0200: Property or indexer 'System.DirectoryServices.Linq.EntryObjects.EntryObject.InternalDn' cannot be assigned to -- it is read only

I don't know what I'm doing wrong. I tried some suggestions that I found on the web concerning granting some rights to the Temp folder of Windows in IIS_IUSR and Network Service users but none of them worked. Any suggestions?
Thanks in advance for your time.
Developer
Sep 4, 2013 at 12:20 PM
I'm not certain what the problem is here, so I'll need some help trying to track this down. If you know which one it is, could you post the query that causes the problem? Even better would be a minimal test case; if you can create the simplest possible query that produces this problem (e.g. context.Users.Count() or context.Users.Where(u => u.Name == "test"), etc.) that would be very helpful.

Cheers,
Tom
Sep 4, 2013 at 1:12 PM
I found out the reason why this problem was happening. Trying to find the solution I published the Web Service to the local IIS and I received a message concerning the fact that InternalDn has no setter, so it's not serializable. So I had to return a class instance which is serializable. Thanks for your time!
Coordinator
Sep 4, 2013 at 4:37 PM
Hello @FotisS,

First of all, thanks for using the framework. Can you post your DirectoryContext class including your entity classes (or the one that is causing you a problem)? i think i know what the problem is and I just want to make sure.

Thanks,

Stephen Baker
Sep 5, 2013 at 8:08 AM
My ContextClass:
public class WorkingDirectoryContext : DirectoryContext
    {
        public WorkingDirectoryContext()
            : base(string.Empty)
        {

        }

        private IEntrySet<User> _users;

        public IEntrySet<User> Users
        {
            get
            {
                if (_users == null)
                {
                    _users = CreateEntrySet<User>();
                }

                return _users;
            }
        }
    }
My User Entity Class:
[DirectoryType("User", "OU=InternalUsers")]
    public class User : UserEntryObject
    {
        private Guid _id;
        private string _email;
        private string _userName;
        private string _address;
        private string _homePhone;
        private string _cellPhone;
        private DateTime? _whenChanged;

        [DirectoryProperty("displayname", true)]
        public string DisplayName
        {
            get { return _displayName; }
            set
            {
                if (_displayName != value)
                {
                    _displayName = value;
                    NotifyPropertyChanged("DisplayName");
                }
            }
        }

        [DirectoryProperty("streetAddress", true)]
        public string Address
        {
            get { return _address; }
            set
            {
                if (_address != value)
                {
                    _address = value;
                    NotifyPropertyChanged("Address");
                }
            }
        }

        [DirectoryProperty("homePhone", true)]
        public string HomePhone
        {
            get { return _homePhone; }
            set
            {
                if (_homePhone != value)
                {
                    _homePhone = value;
                    NotifyPropertyChanged("HomePhone");
                }
            }
        }

        [DirectoryProperty("mobile", true)]
        public string CellPhone
        {
            get { return _cellPhone; }
            set
            {
                if (_cellPhone != value)
                {
                    _cellPhone = value;
                    NotifyPropertyChanged("CellPhone");
                }
            }
        }

        [DirectoryProperty("objectguid", true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
            set
            {
                if (_id != value)
                {
                    _id = value;
                    NotifyPropertyChanged("Id");
                }
            }
        }

        [DirectoryProperty("whenchanged", true)]
        public DateTime? LastModifiedDate
        {
            get
            {
                return _whenChanged;
            }
            set
            {
                _whenChanged = value;
            }
        }

        [DirectoryProperty("samaccountname")]
        public string UserName
        {
            get
            {
                return _userName;
            }
            set
            {
                if (_userName != value)
                {
                    _userName = value;
                    NotifyPropertyChanged("UserName");
                }
            }
        }

        

        [DirectoryProperty("mail")]
        public string Email
        {
            get
            {
                return _email;
            }
            set
            {
                if (_email != value)
                {
                    _email = value;
                    NotifyPropertyChanged("Email");
                }
            }
        }
    }
The exact error message I get is the following one:
Cannot deserialize type 'System.DirectoryServices.Linq.EntryObjects.EntryObject' because it contains property 'InternalDn' which has no public setter.
Any suggestion to use this class instead of the one that I'm converting it to, will be welcome! Thanks again for your time!
Coordinator
Sep 9, 2013 at 7:31 PM
Hello FotisS,

This issue should be fixed now in the latest source code. The problem was, EntryObject.InternalDn property (used for queries on some types of properties) was set as public with an internal setter causing the deserialization to fail. We are going to put together a 2.0 release soon containing quite a few fixes, including this one.

Thanks,
Stephen Baker
Marked as answer by sbaker on 10/7/2013 at 9:41 AM
Apr 10, 2014 at 9:22 AM
Hi,

Any news on this issue and the 2.0 release ?

Btw can you make the 2.0 CLS-Compliant and sign it ?

Many thanks