Monthly Archives: January 2012

CLR Profiler – message “Waiting for application to start common languange runtime”

Sometimes you may get this message when you start CLR profiler, this means that you don’t have enough permissions to run clr profiler or wrong clr version selected

You can start the clr profiler as “Run as Administrator” if that could solve then fine else check the proper clr version mostly for silverlight applications use “Core CLR version”.

Most of the microsoft products run the 32-bit so try using 32 bit binaries.

Dynamic in VB.Net and Creating a wrapper

I was trying some new things and its not that difficult to implement Dynamic Object in VB.Net either. I tried by creating a dynamic class which can take any number of fields by using a dictionary object

Initially i created SomeDictionary Class

Public Class SomeDictionary
Private ReadOnly _values As Dictionary(Of String, Object)
Private ReadOnly _oldValues As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()

Public Sub New()
_values = New Dictionary(Of String, Object)
End Sub

Public Sub New(values As IDictionary(Of String, Object))
_values = values
End Sub

Default Public Property SomeDictionary(key As String) As Object
Get
Dim result As Object = Nothing
_values.TryGetValue(key, result)
Return result
End Get
Set(value As Object)
If Not _oldValues.ContainsKey(key) Then
Dim oldValue As Object = Nothing
_values.TryGetValue(key, oldValue)
_oldValues(key) = oldValue
End If
_values(key) = value
End Set
End Property

Public Function GetChanges() As IDictionary(Of String, Object)
Dim result = (From key In _oldValues.Keys
Let oldValue = _oldValues(key)
Let newValue = _values(key)
Where Not Object.Equals(oldValue, newValue)
Select New With {.Key = key, .Value = newValue}).ToDictionary(Function(p) p.Key, Function(p) p.Value)
Return result
End Function

End Class

Once this is done, I created a sample Dynamic class

Public Class SomeCommonClass
Inherits Dynamic.DynamicObject
Dim _tracking As SomeDictionary
Public Sub New()
_tracking = New SomeDictionary()
End Sub
Public Overrides Function TrySetMember(binder As Dynamic.SetMemberBinder, value As Object) As Boolean
Try
If _tracking Is Nothing Then
Return False
End If
_tracking(binder.Name) = value
Catch ex As Exception

End Try
Return True
End Function

Public Overrides Function TryGetMember(binder As Dynamic.GetMemberBinder, ByRef result As Object) As Boolean
Try
If _tracking Is Nothing Then
Return False
End If
If _tracking(binder.Name) Is Nothing Then
result = Nothing
Return False
End If
result = _tracking(binder.Name)
Catch ex As Exception

End Try
Return True
End Function

Public Overrides Function TryInvokeMember(binder As Dynamic.InvokeMemberBinder, args() As Object, ByRef result As Object) As Boolean
Try

Dim mInfo = GetType(SomeDictionary).GetMethod(binder.Name)
If mInfo Is Nothing Then
result = Nothing
Return False
Else
result = mInfo.Invoke(_tracking, args)
End If
Return True
Catch ex As Exception
result = Nothing
Return False
End Try
End Function
End Class

We can override the setmember and getmember methods of DynamicObject class and use it the way we like it.
We can also override the InvokeMember method also so that we can implement the kind of response we want when the user calls a method. Here just for example I used the same Dictionary class to implement this method we can use any other method also in case if you are creating a dyanamic class as a wrapper:
Calling the Dynamic class is also very simple

Dim some As Object = New SomeCommonClass
some.Name = "Kishore Patil"
some.Phone = "12124455"
some.Address_City = "Cincinnati"
some.Address_Street = "8000 Some Dr"
some.Address_State = "Ohio"

We can use this particular class to have any kind of field stored and retrived using the Dictionary.
The following is the example converted to VB.Net originally published here for C#

Public Class DynamicXmlNode
    Inherits Dynamic.DynamicObject
    Dim node As XElement

    Public Sub New(node As XElement)
        Me.node = node
    End Sub

    Public Sub New()

    End Sub

    Public Sub New(name As String)
        node = New XElement(name)
    End Sub
    Public Overrides Function TryConvert(binder As Dynamic.ConvertBinder, ByRef result As Object) As Boolean

        If binder.Type = GetType(String) AndAlso binder.ReturnType = GetType(String) Then
            result = node.Value
            Return True
        ElseIf binder.Type = GetType(Integer) AndAlso binder.ReturnType = GetType(Integer) Then
            result = node.Value
            Return True
        End If
        Return True
    End Function

    Public Overrides Function TrySetMember(binder As Dynamic.SetMemberBinder, value As Object) As Boolean
        Dim setNode As XElement = node.Element(binder.Name)
        If Not setNode Is Nothing Then
            setNode.SetValue(value)
        Else
            If value.GetType = GetType(DynamicXmlNode) Then
                node.Add(New XElement(binder.Name))
            Else
                node.Add(New XElement(binder.Name, value))
            End If

        End If
            Return True
    End Function

    Public Overrides Function TryGetMember(binder As Dynamic.GetMemberBinder, ByRef result As Object) As Boolean
        Dim getNode As XElement = node.Element(binder.Name)
        If Not getNode Is Nothing Then
            If getNode.HasElements Or String.IsNullOrEmpty(getNode.Value) Then
                result = New DynamicXmlNode(getNode)
            Else
                result = getNode.Value
            End If

            Return True
        Else
            result = Nothing
            Return False
        End If
    End Function

    Public Overrides Function TryInvokeMember(binder As Dynamic.InvokeMemberBinder, args() As Object, ByRef result As Object) As Boolean
        Try
            Dim xmlType As Type = GetType(XElement)
            result = xmlType.InvokeMember(binder.Name, Reflection.BindingFlags.InvokeMethod Or Reflection.BindingFlags.Public Or Reflection.BindingFlags.Instance, Nothing, result, args)
            Return True
        Catch ex As Exception
            result = Nothing
            Return False
        End Try

    End Function
End Class

To use Convert in VB we need to something like this CTypeDynamic(node.Address.City, GetType(String)). It’s very helpful in writing wrappers only drawback being its slow and no intellisense will be available.

Jailbreaking appleTV 2 (4.4.4) Untethered

Atlast this weekend I was able to successfully jailbreak(Untethered) my apple tv 2 (4.4.4) using Seas0npass. Followed the instructions from here.

I was able to install nitoTV, XBMC (11) successfully. There was freeze while using XBMC and Airplay. I had to update the XBMC settings to allow airplay. Installed IceFilms plugin on XBMC to get the movies from MegaUpload. There was a script plugin error: plugins.video.icefilms.
After doing some research found out there was some change on the MegaUpload side, so had to modified Megaroutines.py file as per the suggestions on this thread. Working again.

Hope there are no more issues.