<p>I have a generic Repository&lt;T&gt; class I want to use with an ObjectDataSource. Repository&lt;T&gt; lives in a separate project called DataAccess. According to <a href="http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/767f1a821d9b23da/b1e045958ae427a5?lnk=st#b1e045958ae427a5" rel="noreferrer">this post from the MS newsgroups</a> (relevant part copied below):</p>

<blockquote>
  <p>Internally, the ObjectDataSource is calling Type.GetType(string) to get the
  type, so we need to follow the guideline documented in Type.GetType on how
  to get type using generics. You can refer to MSDN Library on Type.GetType:</p>
  
  <p><a href="http://msdn2.microsoft.com/en-us/library/w3f99sx1.aspx" rel="noreferrer">http://msdn2.microsoft.com/en-us/library/w3f99sx1.aspx</a></p>
  
  <p>From the document, you will learn that you need to use backtick (`) to
  denotes the type name which is using generics.</p>
  
  <p>Also, here we must specify the assembly name in the type name string.</p>
  
  <p>So, for your question, the answer is to use type name like follows:</p>
  
  <p>TypeName="TestObjectDataSourceAssembly.MyDataHandler`1[System.String],TestObjectDataSourceAssembly"</p>
</blockquote>

<p>Okay, makes sense. When I try it, however, the page throws an exception:</p>

<pre><code>&lt;asp:ObjectDataSource ID="MyDataSource" TypeName="MyProject.Repository`1[MyProject.MessageCategory],DataAccess" /&gt;
</code></pre>

<blockquote>
  <p>[InvalidOperationException: The type specified in the TypeName property of ObjectDataSource 'MyDataSource' could not be found.]</p>
</blockquote>

<p>The curious thing is that this only happens when I'm viewing the page. When I open the "Configure Data Source" dialog from the VS2008 designer, it properly shows me the methods on my generic Repository class. Passing the TypeName string to Type.GetType() while debugging also returns a valid type. So what gives?</p>

[{'answer_id': 53106, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 5, 'selected': True, 'text': '<p>Do something like this.</p>\n\n<pre><code>Type type = typeof(Repository&lt;MessageCategory);\nstring assemblyQualifiedName = type.AssemblyQualifiedName;\n</code></pre>\n\n<p>get the value of assemblyQualifiedName and paste it into the TypeName field. Note that Type.GetType(string), the value passed in must be</p>\n\n<blockquote>\n  <p>The assembly-qualified name of the type to get. See <a href="http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx" rel="noreferrer">AssemblyQualifiedName</a>. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace.</p>\n</blockquote>\n\n<p>So, it may work by passing in that string in your code, because that class is in the currently executing assembly (where you are calling it), where as the ObjectDataSource is not.</p>\n\n<p>Most likely the type you are looking for is </p>\n\n<pre><code>MyProject.Repository`1[MyProject.MessageCategory, DataAccess, Version=1.0.0.0, Culture=neutral, PublicKey=null], DataAccess, Version=1.0.0.0, Culture=neutral, PublicKey=null\n</code></pre>\n'}, {'answer_id': 1499638, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>Darren,</p>\n\n<p>Many, many thanks for your post. I've been fighting with this all day. Strangely, in my case, I need to double the square brackets, e.g. for your piece of code:</p>\n\n<p>MyProject.Repository`1[[MyProject.MessageCategory, DataAccess, Version=1.0.0.0, Culture=neutral, PublicKey=null]], DataAccess, Version=1.0.0.0, Culture=neutral, PublicKey=null</p>\n\n<p>Roger</p>\n"}, {'answer_id': 26492169, 'author': 'Philip Johnson', 'author_id': 3365923, 'author_profile': 'https://Stackoverflow.com/users/3365923', 'pm_score': 1, 'selected': False, 'text': '<p>I know this is an old post but I have recently had this problem myself. Another solution would be to replace the inheritance with object composition, e.g.</p>\n\n<pre><code>[DataObject]\npublic class DataAccessObject {\n    private Repository&lt;MessageCategory&gt; _repository;\n\n    // ctor omitted for clarity\n    // ...\n\n    [DataObjectMethod(DataObjectMethodType.Select)]\n    public MessageCategory Get(int key) {\n        return _repository.Get(key);\n    }\n}\n</code></pre>\n\n<p>This way the ObjectDataSource doesn\'t know about the repository because its hidden within the class. I have a class library in my facade layer that is a perfectly reasonable place to put this code in the project I am working on.</p>\n\n<p>In addition, if you are using Resharper and interfaces, its possible to get Resharper to do the refactoring using Resharpers "Implement using field" function.</p>\n'}]
['https://Stackoverflow.com/questions/52989', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4160/']