madhatter22 / LinqToLdap

C# LINQ provider built on top of System.DirectoryServices.Protocols for querying and updating LDAP servers.
MIT License
45 stars 23 forks source link

reading UTF-8 encoded entries #6

Closed pbochenski closed 6 years ago

pbochenski commented 6 years ago

Hi, I have a user that has some utf-8 encoded names (see ADSI preview, the string is "Jimåäö") PREVIEW

when tried to read it using annotation it crashed with exception:

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ----> System.InvalidCastException : Unable to cast object of type 'System.Byte[]' to type 'System.String' at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args) at LinqToLdap.QueryCommands.StandardQueryCommand.HandleStandardRequest(DirectoryConnection connection, ILinqToLdapLogger log, Int32 maxSize, Boolean pagingEnabled) at LinqToLdap.QueryCommands.StandardQueryCommand.Execute(DirectoryConnection connection, SearchScope scope, Int32 maxPageSize, Boolean pagingEnabled, ILinqToLdapLogger log, String namingContext) at LinqToLdap.DirectoryQueryProvider.Execute(Expression expression) at LinqToLdap.QueryProvider.Execute[TResult](Expression expression) at LinqToLdap.QueryableExtensions.ToList[TSource](IQueryable1 source) at ******.DirectoryCollectionInternal2.ToList()

So I added custom mapper and it turned out that byte[] that is passed to mapper is UTF-7 encoded. Any reason why this is not UTF-8?

pbochenski commented 6 years ago

turned out I have had bug in my code. no issue in the library :)