2
Vote

directory attribute update fails when value is String.Empty

description

Hope this will help someone else as well.
For example if you clear the address details of a user and update the context, DirectoryEntry CommitChanges will fail.
There are two work arounds for this issue - in your higher level classes (Entity or even higher) check if value is "" \ string.empty and change it to null.
 
2nd option: In DirectorySource class inside Update() method:
replace instances of i.GetValue(e.Key, null) with
(i.GetValue(e.Key, null)==String.Empty?null:i.GetValue(e.Key, null))
 
this should correct the issue from a lower level class.
 
Please note i have NOT tested this for attributes which as of ActiveDS type.
 
regards
 
afraan

comments

afraan wrote Apr 9, 2009 at 4:37 AM

acutally might get compile type warnings so changed code to the following:

(i.PropertyType==typeof(String)&& ((String)i.GetValue(e.Key, null))==String.Empty?null:i.GetValue(e.Key, null))

wrote Jun 8, 2009 at 9:48 PM

rauh_ryan wrote Jun 8, 2009 at 9:48 PM

I've ran into the exact same issue

lookitstony wrote Jan 8, 2010 at 5:11 PM

Thanks! I can see where this would have been an issue for me.

wrote Feb 14, 2013 at 6:56 PM