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

[runtime] Improve error reporting when calling mono_assembly_open. #15139

Merged
merged 5 commits into from
Jun 3, 2022
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
5 changes: 3 additions & 2 deletions runtime/coreclr-bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,13 @@
MonoAssembly *
mono_assembly_open (const char * filename, MonoImageOpenStatus * status)
{
assert (status == NULL);

MonoAssembly *rv = xamarin_find_assembly (filename);

LOG_CORECLR (stderr, "mono_assembly_open (%s, %p) => MonoObject=%p GCHandle=%p\n", filename, status, rv, rv->gchandle);

if (status != NULL)
*status = rv == NULL ? MONO_IMAGE_ERROR_ERRNO : MONO_IMAGE_OK;

return rv;
}

Expand Down
27 changes: 14 additions & 13 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -917,22 +917,27 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
return stat (path, &buffer) == 0;
}

static MonoAssembly *
xamarin_open_assembly_or_assert (const char *name)
{
MonoImageOpenStatus status = MONO_IMAGE_OK;
MonoAssembly *assembly = mono_assembly_open (name, &status);
if (assembly == NULL)
xamarin_assertion_message ("Failed to open the assembly '%s' from the app: %i (errno: %i). This is usually fixed by cleaning and rebuilding your project; if that doesn't work, please file a bug report: https://github.com/xamarin/xamarin-macios/issues/new", name, (int) status, errno);
return assembly;
}

// Returns a retained MonoObject. Caller must release.
MonoAssembly *
xamarin_open_assembly (const char *name)
{
// COOP: this is a function executed only at startup, I believe the mode here doesn't matter.
char path [1024];
MonoAssembly *assembly;
bool exists = false;

#if MONOMAC
if (xamarin_get_is_mkbundle ()) {
assembly = mono_assembly_open (name, NULL);
if (assembly == NULL)
xamarin_assertion_message ("Could not find the required assembly '%s' in the app. This is usually fixed by cleaning and rebuilding your project; if that doesn't work, please file a bug report: https://github.com/xamarin/xamarin-macios/issues/new", name);
return assembly;
}
if (xamarin_get_is_mkbundle ())
return xamarin_open_assembly_or_assert (name);
#endif

exists = xamarin_locate_assembly_resource (name, NULL, name, path, sizeof (path));
Expand All @@ -942,7 +947,7 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
// Check if we already have the assembly in memory
xamarin_get_assembly_name_without_extension (name, path, sizeof (path));
MonoAssemblyName *aname = mono_assembly_name_new (path);
assembly = mono_assembly_loaded (aname);
MonoAssembly *assembly = mono_assembly_loaded (aname);
mono_assembly_name_free (aname);
if (assembly)
return assembly;
Expand All @@ -954,11 +959,7 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
if (!exists)
xamarin_assertion_message ("Could not find the assembly '%s' in the app. This is usually fixed by cleaning and rebuilding your project; if that doesn't work, please file a bug report: https://github.com/xamarin/xamarin-macios/issues/new", name);

assembly = mono_assembly_open (path, NULL);
if (assembly == NULL)
xamarin_assertion_message ("Could not find the required assembly '%s' in the app. This is usually fixed by cleaning and rebuilding your project; if that doesn't work, please file a bug report: https://github.com/xamarin/xamarin-macios/issues/new", name);

return assembly;
return xamarin_open_assembly_or_assert (path);
}

bool
Expand Down