diff --git a/src/Generator/Passes/StripUnusedSystemTypesPass.cs b/src/Generator/Passes/StripUnusedSystemTypesPass.cs
index 9422f438..4d111cb7 100644
--- a/src/Generator/Passes/StripUnusedSystemTypesPass.cs
+++ b/src/Generator/Passes/StripUnusedSystemTypesPass.cs
@@ -59,8 +59,16 @@ namespace CppSharp.Passes
             var templateType = desugared as TemplateSpecializationType;
             if (templateType != null)
             {
-                MarkAsUsed(templateType.Template);
-                MarkAsUsed(templateType.Template.TemplatedDecl);
+                var template = templateType.Template;
+                if (template.TemplatedDecl is TypeAlias typeAlias &&
+                    typeAlias.Type.Desugar() is TemplateSpecializationType specializationType)
+                {
+                    MarkAsUsed(template);
+                    MarkAsUsed(template.TemplatedDecl);
+                    template = specializationType.Template;
+                }
+                MarkAsUsed(template);
+                MarkAsUsed(template.TemplatedDecl);
                 return true;
             }
 
@@ -90,6 +98,6 @@ namespace CppSharp.Passes
             }
         }
 
-        private HashSet<Declaration> usedStdTypes = new HashSet<Declaration>();
+        private readonly HashSet<Declaration> usedStdTypes = new HashSet<Declaration>();
     }
 }
diff --git a/src/Generator/Passes/TrimSpecializationsPass.cs b/src/Generator/Passes/TrimSpecializationsPass.cs
index 3c0df019..22f71839 100644
--- a/src/Generator/Passes/TrimSpecializationsPass.cs
+++ b/src/Generator/Passes/TrimSpecializationsPass.cs
@@ -158,7 +158,7 @@ namespace CppSharp.Passes
                                let module = arg.Type.Type.GetModule()
                                where module != null
                                select module).ToList().TopologicalSort(m => m.Dependencies);
-                if (modules.Any())
+                if (modules.Count > 0)
                 {
                     var module = modules.Last();
                     module.ExternalClassTemplateSpecializations.Add(specialization);
diff --git a/tests/NamespacesDerived/NamespacesDerived.Tests.cs b/tests/NamespacesDerived/NamespacesDerived.Tests.cs
index b2a3d4c8..09366402 100644
--- a/tests/NamespacesDerived/NamespacesDerived.Tests.cs
+++ b/tests/NamespacesDerived/NamespacesDerived.Tests.cs
@@ -15,6 +15,7 @@ public class NamespaceDerivedTests
         using (new DerivedFromSecondaryBaseInDependency()) { }
         using (var der2 = new Derived2())
         using (der2.LocalTypedefSpecialization) { }
+        Assert.That(typeof(Derived2).Assembly.GetTypes().Any(t => t.FullName.Contains("Std.Vector")), Is.True);
     }
 
     [Test]
diff --git a/tests/NamespacesDerived/NamespacesDerived.h b/tests/NamespacesDerived/NamespacesDerived.h
index 5d14ebe2..9615a0e9 100644
--- a/tests/NamespacesDerived/NamespacesDerived.h
+++ b/tests/NamespacesDerived/NamespacesDerived.h
@@ -109,10 +109,13 @@ private:
     std::basic_string<char, std::char_traits<char>, CustomAllocator<char>> customAllocatedString;
 };
 
+template<class T, class Alloc = CustomAllocator<T>>
+using vector = ::std::vector<T, Alloc>;
+
 class DLL_API StdFields
 {
 private:
-    std::vector<unsigned int, CustomAllocator<unsigned int>> customAllocatedVector;
+   vector<unsigned int, CustomAllocator<unsigned int>> customAllocatedVector;
 };
 
 DLL_API bool operator<<(const Base& b, const char* str);