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

fix: android bitmap skip dynamic and handle exceptions #337

Merged
merged 4 commits into from Jun 14, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/Splat/Platforms/Android/Bitmaps/PlatformBitmapLoader.cs
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Android.App;
using Android.Graphics;
Expand Down Expand Up @@ -103,7 +104,8 @@ public IBitmap Create(float width, float height)

// VS2019 onward
var assemblies = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(t => !t.IsDynamic)
.SelectMany(GetTypesFromAssembly)
.Where(x => x.Name == "Resource" && x.GetNestedType("Drawable") != null)
.Select(x => x.GetNestedType("Drawable"))
.ToArray();
Expand All @@ -127,5 +129,29 @@ public IBitmap Create(float width, float height)

return result;
}

internal static Type[] GetTypesFromAssembly(Assembly assembly)
{
try
{
// could this be assembly.GetExportedTypes() ?
return assembly.GetTypes();
dpvreony marked this conversation as resolved.
Show resolved Hide resolved
}
catch (ReflectionTypeLoadException e)
{
// The array returned by the Types property of this exception contains a Type
// object for each type that was loaded and null for each type that could not
// be loaded, while the LoaderExceptions property contains an exception for
// each type that could not be loaded.
Splat.LogHost.Default.Warn(e, "Exception while detecting drawing types.");

foreach (var loaderException in e.LoaderExceptions)
{
Splat.LogHost.Default.Warn(loaderException, "Inner Exception for detecting drawing types.");
}

return e.Types.Where(x => x != null).ToArray();
}
}
}
}