Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael Falk 37 posts 59 karma points
    Jun 18, 2013 @ 17:51
    Michael Falk
    0

    Weird InvalidCastExceptions when using ContentService

    Hi There

    I am using umbraco 6.1.1

    I have a webservice which is retrieving some data from Umbraco using the contentservice, like this:

     var replies = contentService.GetContentOfContentType(1065).Where(t => 
                        (t.GetValue("importedInBackend") == null || 
                        string.IsNullOrEmpty(t.GetValue("importedInBackend").ToString()))
                        && t.GetValue("submittedDate") != null && 
                        !string.IsNullOrEmpty(t.GetValue("submittedDate").ToString()));
                    try
                    {
                        foreach (var rs in replies)
                        {
                            QuestionnaireReply r = new QuestionnaireReply();
    
                            var quest = contentService.GetById(rs.GetValue<int>("questionnaire"));

    I have several issues:

    1. The where statement is not very elegant. It is basically some date fields i need to check on

    2. The last line rs.GetValue<int> sometimes fails

    The problem is that sometimes Umbraco thinks that all the fields are strings, and sometimes they are having the correct datatype.

    Obviuosly i want the datatypes to be correct all the time. ANybody that have anything that can help here?

    br

    Michael

     

  • Michael Falk 37 posts 59 karma points
    Jun 18, 2013 @ 18:04
    Michael Falk
    0

    Hi Again

    Just discovered that on first rebuild in Visual Studio it works. After that it fails. Very strange???

    I am using VS 2010, and the Nuget package for the binary, and a MVC 4.0 project

  • Michael Falk 37 posts 59 karma points
    Jun 19, 2013 @ 10:38
    Michael Falk
    0

    I have narrowed it down to be a caching issue. When data is read from the database everything is fine, but after af publish, then the next time it reads it from the cache, and here everything is strings:

    Problem is in RepositoryBase:

     public TEntity Get(TId id)
            {
                Guid key = id is int ? ConvertIdToGuid(id) : ConvertStringIdToGuid(id.ToString());
                var rEntity = _cache.GetById(typeof(TEntity), key);
                if (rEntity != null)
                {
                    return (TEntity)rEntity;
                }
    
                var entity = PerformGet(id);
                if (entity != null)
                {
                    _cache.Save(typeof(TEntity), entity);
                }

  • Benoit 14 posts 34 karma points
    Aug 27, 2013 @ 11:22
    Benoit
    0

    Hi,

     

    I'm having the same kind of issues with the mediaservice, using Umbraco 6.0.6.

    Has there been a solution/fix for this problem by now?

    regards

     

    Benoit

  • Michael Falk 37 posts 59 karma points
    Aug 27, 2013 @ 11:23
    Michael Falk
    0

    Yes it is fixed in 6.1.4

Please Sign in or register to post replies

Write your reply to:

Draft