|
80 | 80 | <None Include="THIRD_PARTY_LICENSES.txt" CopyToOutputDirectory="Always" /> |
81 | 81 | </ItemGroup> |
82 | 82 |
|
83 | | - <!-- ignore warnings about mismatch between versions of core libs --> |
| 83 | + <!-- ignore warnings about mismatch between versions of core libs |
| 84 | + and unreachable code because compiler is stupid --> |
84 | 85 | <PropertyGroup> |
85 | | - <NoWarn>$(NoWarn);MSB3277</NoWarn> |
| 86 | + <NoWarn>$(NoWarn);MSB3277;CS0162</NoWarn> |
86 | 87 | </PropertyGroup> |
87 | 88 |
|
88 | 89 | <!-- nuget refs --> |
|
130 | 131 | <Using Namespace="System.Reflection" /> |
131 | 132 | <Code Type="Fragment" Language="cs"> |
132 | 133 | <![CDATA[ |
| 134 | + #nullable enable annotations |
133 | 135 | // 1. Resolver for SCP:SL Dependencies |
134 | 136 | ResolveEventHandler resolver = (sender, args) => { |
135 | 137 | try { |
|
144 | 146 | return Assembly.LoadFrom(fullPath); |
145 | 147 | } |
146 | 148 | } |
147 | | - catch { /* Safe verify, ignore errors */ } |
| 149 | + catch (Exception e) |
| 150 | + { |
| 151 | + Log.LogError("Resolver Error: " + e.ToString()); |
| 152 | + } |
| 153 | +
|
148 | 154 | return null; |
149 | 155 | }; |
150 | 156 |
|
| 157 | + try |
| 158 | + { |
151 | 159 | AppDomain.CurrentDomain.AssemblyResolve += resolver; |
152 | 160 |
|
153 | | - try |
154 | | - { |
155 | 161 | if (!File.Exists(AssemblyPath)) { |
156 | 162 | Log.LogError("Target DLL not found: " + AssemblyPath); |
157 | 163 | return false; |
|
163 | 169 | |
164 | 170 | { |
165 | 171 | // 4. Find the class (Namespace.ClassName) |
166 | | - Type targetType = assembly.GetType("SER.Code.MethodSystem.MethodIndex"); |
| 172 | + Type? targetType = assembly.GetType("SER.Code.MethodSystem.MethodIndex"); |
167 | 173 | if (targetType == null) |
168 | 174 | { |
169 | 175 | Log.LogError("Validation Error: Type 'SER.Code.MethodSystem.MethodIndex' not found."); |
170 | 176 | return false; |
171 | 177 | } |
172 | 178 | |
173 | 179 | // 5. Find the method |
174 | | - MethodInfo method = targetType.GetMethod("AddAllDefinedMethodsInAssembly", BindingFlags.Public | BindingFlags.Static); |
| 180 | + MethodInfo? method = targetType.GetMethod( |
| 181 | + "AddAllDefinedMethodsInAssembly", |
| 182 | + BindingFlags.Public | BindingFlags.Static |
| 183 | + ); |
175 | 184 | if (method == null) |
176 | 185 | { |
177 | 186 | Log.LogError("Validation Error: Static method 'AddAllDefinedMethodsInAssembly()' not found."); |
178 | 187 | return false; |
179 | 188 | } |
180 | 189 | |
181 | | - method.Invoke(null, [assembly]); |
| 190 | + method.Invoke(null, new object[] { assembly }); |
182 | 191 | Log.LogMessage(MessageImportance.High, ">>> Loaded methods."); |
183 | 192 | } |
184 | 193 | |
185 | 194 | { |
186 | 195 | // 4. Find the class (Namespace.ClassName) |
187 | | - Type targetType = assembly.GetType("SER.Code.Examples.Example"); |
| 196 | + Type? targetType = assembly.GetType("SER.Code.Examples.Example"); |
188 | 197 | if (targetType == null) |
189 | 198 | { |
190 | 199 | Log.LogError("Validation Error: Type 'SER.Code.Examples.Example' not found."); |
191 | 200 | return false; |
192 | 201 | } |
193 | 202 | |
194 | 203 | // 5. Find the method |
195 | | - MethodInfo method = targetType.GetMethod("Verify", BindingFlags.Public | BindingFlags.Static); |
| 204 | + MethodInfo? method = targetType.GetMethod( |
| 205 | + "Verify", |
| 206 | + BindingFlags.Public | BindingFlags.Static |
| 207 | + ); |
196 | 208 | if (method == null) |
197 | 209 | { |
198 | 210 | Log.LogError("Validation Error: Static method 'Verify()' not found."); |
|
214 | 226 | return true; |
215 | 227 | } |
216 | 228 | } |
217 | | - catch (Exception ex) |
| 229 | + catch (OperationCanceledException) |
218 | 230 | { |
219 | | - if (ex is ReflectionTypeLoadException re) { |
220 | | - foreach (var loaderEx in re.LoaderExceptions) { |
221 | | - Log.LogError("Loader Error: " + loaderEx.Message); |
222 | | - } |
223 | | - } |
224 | | - else if (ex.InnerException != null) { |
225 | | - Log.LogError("Runtime Error: " + ex.InnerException.Message); |
226 | | - } |
227 | | - else { |
228 | | - Log.LogError("Task Error: " + ex.ToString()); |
| 231 | + throw; |
| 232 | + } |
| 233 | + catch (ReflectionTypeLoadException re) |
| 234 | + { |
| 235 | + foreach (var loaderEx in re.LoaderExceptions) |
| 236 | + { |
| 237 | + Log.LogError("Loader Error: " + loaderEx.ToString()); |
229 | 238 | } |
| 239 | + return false; |
| 240 | + } |
| 241 | + catch (TargetInvocationException tie) |
| 242 | + { |
| 243 | + Log.LogError("Invocation Error: " + |
| 244 | + (tie.InnerException != null ? tie.InnerException.ToString() : tie.ToString())); |
| 245 | + return false; |
| 246 | + } |
| 247 | + catch (Exception ex) |
| 248 | + { |
| 249 | + Log.LogError("Task Error: " + ex.ToString()); |
| 250 | + return false; |
230 | 251 | } |
231 | 252 | finally { |
232 | 253 | // 7. Detach Resolver to keep build process clean |
233 | 254 | AppDomain.CurrentDomain.AssemblyResolve -= resolver; |
234 | 255 | } |
| 256 | + #nullable disable annotations |
235 | 257 | ]]> |
236 | 258 | </Code> |
237 | 259 | </Task> |
|
0 commit comments