{"id":3672,"date":"2014-03-29T07:47:04","date_gmt":"2014-03-29T07:47:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/define-a-typed-dataset-dynamically-collection-of-common-programming-errors\/"},"modified":"2014-03-29T07:47:04","modified_gmt":"2014-03-29T07:47:04","slug":"define-a-typed-dataset-dynamically-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/define-a-typed-dataset-dynamically-collection-of-common-programming-errors\/","title":{"rendered":"Define a typed dataset dynamically?-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1a3521db0840c883d6ecb38d6d82ab08?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nNoah<\/p>\n<p>I am trying to create an instance of a typed dataset dynamically in my code at runtime. I have the type available to me, but when I try to do this:<\/p>\n<pre><code>object obj = Activator.CreateInstance(Type.GetType(\"TYPED DATASET TYPE HERE\"));\n<\/code><\/pre>\n<p>The problem is the type doesn&#8217;t seem to be valid according to the code when I try and run it. What could I be doing wrong here?<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/graph.facebook.com\/100000653737180\/picture?type=large\" \/><br \/>\nMarc Gravell<\/p>\n<p>Where is the type defined? (which assembly).<\/p>\n<p>Unless you give it an assembly qualified name, it will only look in the <em>calling<\/em> assembly, and a few other key assemblies. Options:<\/p>\n<ul>\n<li>use an assembly qualified name (&#8220;somen.amespace.sometype, someassembly, &#8230;&#8221;)<\/li>\n<li>get the <code>Assembly<\/code> instance (from a known type in that assembly), and use <code>GetType(fullyQualifiedName)<\/code> on the <code>Assembly<\/code> instance<\/li>\n<\/ul>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/5b5c1c8d2cd9e9b370e30c5a1d09fbce?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPeter<\/p>\n<p>Assuming you are emitting the correct dataset code you may also need to load the assembly.<\/p>\n<p>Look into the following .net namespaces reflection.emit, and reflection.<\/p>\n<p>You could also look at the open source projects such as windsor which use reflection to emit new classes to create interceptors. There may be code in there that you can learn from.<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Noah I am trying to create an instance of a typed dataset dynamically in my code at runtime. I have the type available to me, but when I try to do this: object obj = Activator.CreateInstance(Type.GetType(&#8220;TYPED DATASET TYPE HERE&#8221;)); The problem is the type doesn&#8217;t seem to be valid according to the code when I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3672","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3672"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3672\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}