adrianstevens / Xamarin-Plugins

Cross-platform Plugins for Xamarin, Xamarin.Forms and Windows
https://www.nuget.org/packages/Xam.Plugin.SimpleAudioPlayer/
MIT License
133 stars 53 forks source link

WPF version throws FileNotFound Exception #58

Open tkouba opened 5 years ago

tkouba commented 5 years ago

WPF version of SimpleAudioPlayer has wrong name of assembly. So on use throws FileNotFoundException with

FileName    "Plugin.SimpleAudioPlayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"   string

But dll name is "Plugin.SimpleAudioPlayer.WPF.dll"

Workaround:

    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolver); 
            Xamarin.Forms.Forms.Init();
            base.OnStartup(e);
        }

        private Assembly AssemblyResolver(object sender, ResolveEventArgs args)
        {
            if (args.Name.StartsWith("Plugin.SimpleAudioPlayer", StringComparison.CurrentCultureIgnoreCase))
            {
                return Assembly.LoadFrom("Plugin.SimpleAudioPlayer.WPF.dll");
            }
            return null;
        }
    }