Skip to content

Invalid cast exception when using caching LastModified property #2

@kambg

Description

@kambg

System.InvalidCastException: Unable to cast object of type 'SpiderService.Dto.Book' to type 'SpiderService.Dto.Books'.

at OpenRasta.Caching.Configuration.ResourceMapper`1.<>c__DisplayClass1.b__0(Object resource)
at OpenRasta.Caching.Pipeline.LastModifiedContributor.PostExecution(ICommunicationContext context)
at OpenRasta.Pipeline.PipelineRunner.ExecuteContributor(ICommunicationContext context, ContributorCall call)

This is happening when a given Handler is setup with more that one resources and endpoints.
Requests for /Book/WWW are handled but for /Books/ByCode/WWW throw above exception.

BookSearchHandler setup:

ResourceSpace.Has.ResourcesOfType()
.AtUri("/Books?codeLike={searchTerms}")
.And.AtUri("/Books/ByCode/{searchTerms}").Named("OpenSearch:Book search")
.HandledBy()
.TranscodedBy()
.Map().LastModified(x => new DateTimeOffset(DateTime.Now));

                    ResourceSpace.Has.ResourcesOfType<Book>() 
                            .AtUri("/Book/{bookCode}") 
                            .HandledBy<BookSearchHandler>() 
                            .TranscodedBy<HtmlCodec>() 
                            .Map<Book>().LastModified(x => new DateTimeOffset(DateTime.Now)); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions