Generics & Reflection - GenericArguments[0] violates the constraint of type
Your code tries to create an instance of DocumentLibraryRepository<IRepository<Document>>
instead of DocumentLibraryRepository<Document>
.
You want to use this code instead:
var genericArgument = typeof(T).GetGenericArguments().FirstOrDefault();
if (tempType != null && genericArgument != null)
{
Type newType = tempType.MakeGenericType(genericArgument);