title: Dynamic load assembly in WinRT
body: <p>I have created a program to load dynamic assemblies using the following code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Reflection;
  using System.Threading.Tasks;
  
  namespace BarcodeReader
  {
     public class Parsing
     {
        private static string _FolderName = "BarcodeReaders";
        private static bool _Initialized = false;
        private static IEnumerable&lt;IBarcodeReader&gt; _Objs;
  
        /// Parse the picture
        /// &lt;returns&gt;The value from the picture&lt;/returns&gt;
        public static async Task&lt;string&gt; ParsePicture()
        {
           // Check if this class has not been initialized, and if it hasn't initialize it
           if (!_Initialized)
           {
              await InitializeAsync();
           }
  
           foreach (var Obj in _Objs)
           {
              if (Obj.IsType())
              {
                 return Obj.GetValue();
              }
           }
  
           return null;
        }
  
        private static async Task InitializeAsync()
        {
           // Get the folder
           var Folder = await GetFolder();
  
           // Get the Files in the Folder
           var Files = await Folder.GetFilesAsync();
  
           // Initialize the objects and set them
           _Objs = InitializeObjects(Files);
  
           // Set it as initialized
           _Initialized = true;
        }
  
        private static IEnumerable&lt;IBarcodeReader&gt; InitializeObjects(IEnumerable&lt;Windows.Storage.StorageFile&gt; Files)
        {
           foreach (var File in Files)
           {
              string Name = File.Path;
              var Assembly = System.Reflection.Assembly.Load(new AssemblyName(Name));
              foreach (var Typ in Assembly.ExportedTypes)
              {
                 var TypInfo = Typ.GetTypeInfo();
                 foreach (var Interf in TypInfo.ImplementedInterfaces)
                 {
                    if (Interf.Name.Equals("IBarcodeReader"))
                    {
                       yield return (IBarcodeReader)Activator.CreateInstance(Typ);
                    }
                 }
              }
           }
        }
  
        private static async Task&lt;bool&gt; BarcodeFolderExist(Windows.Storage.StorageFolder Folder)
        {
           // Get all folders
           var Folders = await Folder.GetFoldersAsync();
  
           // For each folder, check if it is the Folder we are searching and if it is return true
           foreach (var Foldr in Folders)
           {
              if (Foldr.Name.Equals(_FolderName))
              {
                 return true;
              }
           }
  
           // Return false as the folder was not found
           return false;
        }
  
        private static async Task&lt;Windows.Storage.StorageFolder&gt; GetFolder()
        {
           // Get the local-folder
           var Folder = Windows.Storage.ApplicationData.Current.LocalFolder;
  
           // Check if the folder does not exist, and if it does not create it
           if (!await BarcodeFolderExist(Folder))
           {
              await Folder.CreateFolderAsync(_FolderName);
           }
  
           return await Folder.GetFolderAsync(_FolderName);
        }
     }
  }
  </code></pre>
  
  <p>And the project I am trying to load is these files</p>
  
  <pre><code>namespace QRReader
  {
     public sealed class QRReader : IBarcodeReader
     {
        public bool IsType()
        {
           return true;
        }
  
        public string GetValue()
        {
           return "HEJ";
        }
     }
  
     public interface IBarcodeReader
     {
        bool IsType();
        string GetValue();
     }
  }
  </code></pre>
  
  <p>But I get this error</p>
  
  <pre><code>FileLoadException was unhandled by user code
  The assembly name or code base was illegal. (Exception HRESULT: 0x80131047)
  </code></pre>
  
  <p>The <code>name</code>-variable is set to 
  <code>C:\Users\Lasse\AppData\Local\Packages\93e3b2c9-7ef8-4537-be39-d0f3e93ca100_e85ydygyad1dy\LocalState\BarcodeReaders\QRReader.winmd</code></p>