Try our conversational search powered by Generative AI!

Dynamic Content throws "Invalid hash value" exception

Ted
Ted
Vote:
 

Has anyone experienced "Invalid hash value" exception when a dynamic content module is loaded? State value is properly saved/retrieved, but immediately after the State setter is invoked an ArgumentException is thrown saying "Invalid hash value".

#44691
Oct 13, 2010 2:35
Vote:
 

Hello Ted

Do you have a code example that re-creates this problem?

David

#44732
Oct 13, 2010 19:58
Vote:
 

Yes, I experienced this after upgrading to CMS6 R2.  I found that I was unable to re-publish any pages with dynamic content if the dynamic content included HTML (i.e. I have a CodeInclude module that would publish successfully with "test", but would throw the "Invalid hash value" exception when I tried to publish "<b>test</b>").  The solution was to encode the HTML string.

However, this solution isn't much good if a lot of dynamic content exists on your site that isn't encoded.  As a result, I've simply added try catch statements to the State property to enable the unencoded content to be loaded, and if re-published, it will be encoded.  For what it's worth, here's my code (in VB, because alas, that's what we use):

    Public Property State As String Implements EPiServer.DynamicContent.IDynamicContent.State
        Get
            Try
                Return Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(strCode.ToString()))
            Catch ex As Exception
                Return strCode.ToString()
            End Try
        End Get
        Set(ByVal value As String)
            If value.Length > 1 Then
                value = Replace(value, "&", "&")
                Try
                    strCode.ParseToSelf(ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(value)))
                Catch ex As Exception
                    strCode.ParseToSelf(value)
                End Try
            End If
        End Set
    End Property

    

#51890
Jun 28, 2011 2:37
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.