Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make loading of the detective assembly more resilient. #14512

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/DynamoCoreWpf/Utilities/CrashReportTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,23 @@ private static string FindCERToolInInstallLocations()

try
{
string rootFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var assemblyPath = Path.Combine(Path.Combine(rootFolder, "DynamoInstallDetective.dll"));
if (!File.Exists(assemblyPath))
throw new FileNotFoundException(assemblyPath);

var assembly = Assembly.LoadFrom(assemblyPath);

var type = assembly.GetType("DynamoInstallDetective.Utilities");
// Try to directly get the type for the detective class
// (this will in many cases also load the assembly)
var type = Type.GetType("DynamoInstallDetective.Utilities, DynamoInstallDetective", false);
if (type == null)
{
// fallback, load the assembly and get the type using LoadFrom
string rootFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var assemblyPath = Path.Combine(rootFolder, "DynamoInstallDetective.dll");
if (!File.Exists(assemblyPath))
throw new FileNotFoundException(assemblyPath);

var assembly = Assembly.LoadFrom(assemblyPath);
type = assembly.GetType("DynamoInstallDetective.Utilities");
}

var installationsMethod = type.GetMethod(
var installationsMethod = type.GetMethod(
"FindMultipleProductInstallations",
BindingFlags.Public | BindingFlags.Static);

Expand Down
18 changes: 12 additions & 6 deletions src/Tools/DynamoShapeManager/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,19 @@ public static string GetGeometryFactoryPath2(string rootFolder, Version version)
#endif
private static IEnumerable GetAsmInstallations(string rootFolder)
{
var assemblyPath = Path.Combine(Path.Combine(rootFolder, "DynamoInstallDetective.dll"));
if (!File.Exists(assemblyPath))
throw new FileNotFoundException(assemblyPath);

var assembly = Assembly.LoadFrom(assemblyPath);
// Try to directly get the type for the detective class
// (this will in many cases also load the assembly)
var type = Type.GetType("DynamoInstallDetective.Utilities, DynamoInstallDetective", false);
if (type == null)
{
// fallback, load the assembly and get the type using LoadFrom
var assemblyPath = Path.Combine(rootFolder, "DynamoInstallDetective.dll");
if (!File.Exists(assemblyPath))
throw new FileNotFoundException(assemblyPath);

var type = assembly.GetType("DynamoInstallDetective.Utilities");
var assembly = Assembly.LoadFrom(assemblyPath);
type = assembly.GetType("DynamoInstallDetective.Utilities");
}

var installationsMethod = type.GetMethod(
"FindMultipleProductInstallations",
Expand Down
Loading