jensenkd / plex-api

.NET Core SDK for Plex Media Server
MIT License
86 stars 27 forks source link

DateTime automapping failure when getting server #27

Closed electricduck closed 3 years ago

electricduck commented 3 years ago

After successfully logging in, and doing account.Servers() and getting any server from the list, I was met with: Cannot connect to server: x.x.x.x

Removing the try/catch from Servers(), I was able to get the exception:

Unhandled exception. AutoMapper.AutoMapperMappingException: Error mapping types.

Mapping types:
AccountServer -> Server
Plex.ServerApi.PlexModels.Account.AccountServer -> Plex.Library.ApiModels.Servers.Server

Type Map configuration:
AccountServer -> Server
Plex.ServerApi.PlexModels.Account.AccountServer -> Plex.Library.ApiModels.Servers.Server

Destination Member:
UpdatedAt

 ---> System.FormatException: 03/24/2021 19:32:51 is not a valid value for DateTime.
 ---> System.FormatException: String '03/24/2021 19:32:51' was not recognized as a valid DateTime.
   at System.DateTimeParse.Parse(ReadOnlySpan`1 s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
   at System.DateTime.Parse(String s, IFormatProvider provider)
   at System.ComponentModel.DateTimeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   --- End of inner exception stack trace ---
   at System.ComponentModel.DateTimeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at System.ComponentModel.TypeConverter.ConvertFrom(Object value)
   at AutoMapper.Mappers.TypeConverterMapper.Map[TSource,TDestination](TSource source)
   at lambda_method2(Closure , AccountServer , Server , ResolutionContext )
   --- End of inner exception stack trace ---
   at lambda_method2(Closure , AccountServer , Server , ResolutionContext )
   at Plex.Library.ApiModels.Servers.Server..ctor(IPlexServerClient plexServerClient, IPlexLibraryClient plexLibraryClient, AccountServer accountServer) in /home/ducky/dev/git/none/plex-cli/lib/plex-api/Source/Plex.Library/ApiModels/Servers/Server.cs:line 41
   at Plex.Library.ApiModels.Accounts.PlexAccount.Servers() in /home/ducky/dev/git/none/plex-cli/lib/plex-api/Source/Plex.Library/ApiModels/Accounts/PlexAccount.cs:line 172
   at PlexCli.Program.Main(String[] args) in /home/ducky/dev/git/none/plex-cli/src/Program.cs:line 49
   at PlexCli.Program.<Main>(String[] args)

Running Plex 1.22.1.4228 on Linux.

jensenkd commented 3 years ago

@electricduck can you try the newest pre-release nuget package and see if that fixes it? For some reason I was converting the date to a string and having Automapper convert it back to date :/

v2.0.0-preview024

electricduck commented 3 years ago

Yep, works as expected in v2.0.0-preview024 :+1:

jensenkd commented 3 years ago

Thanks for the help!