45 ArgumentNullException.ThrowIfNull(
68 if (
string.IsNullOrWhiteSpace(
75 "The adapter assembly path is empty.");
94 $
"The adapter assembly was not found at " +
95 $
"'{assemblyPath}'.");
105 AssemblyLoadContext.Default
106 .LoadFromAssemblyPath(
109 catch (Exception exception)
113 FileNotFoundException or
114 BadImageFormatException)
122 result.AddDiagnostic(
123 "The adapter assembly could not be loaded.");
133 if (adapterType is
null)
138 result.AddDiagnostic(
139 string.IsNullOrWhiteSpace(
141 ?
"No public concrete solver-adapter " +
142 "type was found in the assembly."
144 $
"'{descriptor.TypeName}' was not " +
145 "found in the assembly.");
151 adapterType.AssemblyQualifiedName ??
152 adapterType.FullName ??
161 result.AddDiagnostic(
162 $
"Type '{adapterType.FullName}' does not " +
163 $
"implement {nameof(ISolverAdapter)}.");
168 if (adapterType.IsAbstract ||
169 adapterType.IsInterface)
174 result.AddDiagnostic(
175 $
"Type '{adapterType.FullName}' is not a " +
176 "concrete adapter type.");
181 if (adapterType.GetConstructor(
182 Type.EmptyTypes) is
null)
187 result.AddDiagnostic(
188 $
"Type '{adapterType.FullName}' does not " +
189 "provide a public parameterless " +
201 catch (Exception exception)
204 TargetInvocationException or
205 MemberAccessException or
206 MissingMethodException or
207 TypeInitializationException)
210 IsNativeDependencyFailure(
213 .NativeDependencyFailure
215 .InstantiationFailure;
218 GetInnermostException(
221 result.AddDiagnostic(
222 "The solver adapter could not be " +
228 if (result.Adapter is
null)
232 .InstantiationFailure;
234 result.AddDiagnostic(
235 "The adapter constructor returned no " +
241 if (result.Adapter.SolverKind !=
247 result.AddDiagnostic(
248 $
"The adapter reports solver kind " +
249 $
"'{result.Adapter.SolverKind}', whereas " +
250 $
"the descriptor declares " +
251 $
"'{descriptor.SolverKind}'.");
262 result.AddDiagnostic(
263 $
"Adapter '{result.Adapter.AdapterName}' was " +
264 "loaded successfully.");
268 catch (Exception exception)
271 IsNativeDependencyFailure(
274 .NativeDependencyFailure
276 .AssemblyLoadFailure;
279 GetInnermostException(
282 result.AddDiagnostic(
283 "An unexpected error occurred while loading " +
284 "the solver adapter.");
290 private static Type? ResolveAdapterType(
294 if (!
string.IsNullOrWhiteSpace(
297 return assembly.GetType(
308 assembly.GetExportedTypes(),
311 .IsAssignableFrom(type) &&
315 catch (ReflectionTypeLoadException exception)
322 .IsAssignableFrom(type) &&
328 private static bool IsNativeDependencyFailure(
331 Exception innermostException =
332 GetInnermostException(
335 return innermostException is
336 DllNotFoundException or
337 BadImageFormatException or
338 FileNotFoundException;
341 private static Exception GetInnermostException(
344 Exception currentException =
347 while (currentException.InnerException is not
null)
350 currentException.InnerException;
353 return currentException;