File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed
Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4+ using System . Linq ;
45using System . Reflection ;
56using System . Reflection . Emit ;
67using System . Text ;
8+ using BepInEx ;
79using Mono . CSharp ;
810
911namespace ScriptLoader
@@ -101,14 +103,33 @@ SeekableStreamReader GetFile(SourceFile file)
101103 return ass . Builder ;
102104 }
103105
106+ private static AssemblyName ParseName ( string fullName )
107+ {
108+ try
109+ {
110+ return new AssemblyName ( fullName ) ;
111+ }
112+ catch ( Exception )
113+ {
114+ return null ;
115+ }
116+ }
117+
104118 private static void ImportAppdomainAssemblies ( Action < Assembly > import )
105119 {
106- foreach ( var assembly in AppDomain . CurrentDomain . GetAssemblies ( ) )
120+ // In some cases there could be multiple versions of the same assembly loaded
121+ // In that case we decide to simply load only the latest one as it's easiest to handle
122+ var dedupedAssemblies = AppDomain . CurrentDomain . GetAssemblies ( )
123+ . Select ( a => new { ass = a , name = ParseName ( a . FullName ) } )
124+ . Where ( a => a . name != null )
125+ . GroupBy ( a => a . name . Name )
126+ . Select ( g => g . OrderByDescending ( a => a . name . Version ) )
127+ . First ( ) ;
128+ foreach ( var ass in dedupedAssemblies )
107129 {
108- var name = assembly . GetName ( ) . Name ;
109- if ( StdLib . Contains ( name ) || compiledAssemblies . Contains ( name ) )
130+ if ( StdLib . Contains ( ass . name . Name ) || compiledAssemblies . Contains ( ass . name . Name ) )
110131 continue ;
111- import ( assembly ) ;
132+ import ( ass . ass ) ;
112133 }
113134 }
114135
You can’t perform that action at this time.
0 commit comments