title: JsonConvert.DeserializeObject knowing class name (string)
body: <p>I've a vb.net class that includes some serializable sub-classes</p>
  <pre><code>Public Class Model
      &lt;Serializable&gt;
      Public class foo
          Public Property id as Integer
          Public Property name as String
      End Class
  
      &lt;Serializable&gt;
      Public Class bar
          Public Property grading as Integer
          Public Property minWage as Decimal
          Public Property maxWage as Decimal
      End Class
  End Class
  </code></pre>
  <p>Now I receive from a web service, an object (as json formated string) and its class name (as string) and I'd like to Deserialize it as my object.</p>
  <p>I could do, as it is actually working, a</p>
  <pre><code>Imports Newtonsoft.Json
      
  Public Shared Function Deserialize(ByVal Json As String, ByVal name As String) As Object
     
      Select Case name
          Case &quot;foo&quot;
              Return JsonConvert.DeserializeObject(of Model.foo)(Json)
          Case &quot;bar&quot;
              Return JsonConvert.DeserializeObject(of Model.bar)(Json)
      End Select
  End Function
  </code></pre>
  <p>But as you can imagine, I've a ton of classes, not just 2, so I tried to use Reflection</p>
  <pre><code>Imports System.Reflection
  Imports Newtonsoft.Json
  
  Public Shared Function Deserialize(ByVal Json As String, ByVal name As String) As Object
  
      Dim assembly As Assembly = Assembly.GetAssembly(GetType(Model))
      Dim type As Type = assembly.[GetType](&quot;Model.&quot; &amp; name) ' Why is this always Nothing?
      Dim objInstance As Object = Activator.CreateInstance(type)
      '        objInstance = JsonConvert.DeserializeObject(Of ???)(Json)
  
      Return objInstance 
  End Function
  </code></pre>
  <p>But on one hand the type variable is always Nothing, and on the other hand, I don't know what to put instead of the comment.</p>
  <p>Can you please advise ?</p>