public override Assembly LoadAssembly(string assemblyPath) { var sri = System.Windows.Application.GetResourceStream(new Uri(assemblyPath, UriKind.Relative)); var myPart = new System.Windows.AssemblyPart(); var assembly = myPart.Load(sri.Stream); return assembly; }
protected static Type ReadPrecompiledUserCode(XElement root) { var codeNode = root.Element("precompiled-user-code"); if (codeNode == null) { return(null); } var typeAttr = codeNode.Attribute("type"); if (typeAttr == null) { return(null); } Assembly asm; byte[] asmBytes = Convert.FromBase64String(codeNode.Value); #if !SILVERLIGHT asm = Assembly.Load(asmBytes); #else var asmPart = new System.Windows.AssemblyPart(); asm = asmPart.Load(new MemoryStream(asmBytes)); #endif return(asm.GetType(typeAttr.Value)); }
private static Assembly LoadAssembly(string assemblyPath) { var sri = System.Windows.Application.GetResourceStream(new Uri(assemblyPath, UriKind.Relative)); var myPart = new System.Windows.AssemblyPart(); var assembly = myPart.Load(sri.Stream); return(assembly); }
static AnalyticsTracker() { resourceAssembliesHash.Add("EQATEC.Analytics.Monitor", Resources.EQATEC_Analytics_Monitor); resourceAssembliesHash.Add("EQATEC.Analytics.Monitor.SL", Resources.EQATEC_Analytics_MonitorSL); #if SILVERLIGHT System.Windows.AssemblyPart assemblyPart = new System.Windows.AssemblyPart(); assemblyPart.Load(new System.IO.MemoryStream(resourceAssembliesHash["EQATEC.Analytics.Monitor.SL"])); #else AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; #endif Instance = new AnalyticsTracker(); }
static SR.Assembly LoadTestModule(ModuleDefinition module) { using (var stream = new MemoryStream()) { module.Write(stream); //File.WriteAllBytes (Path.Combine (Path.Combine (Path.GetTempPath (), "cecil"), module.Name + ".dll"), stream.ToArray ()); #if SILVERLIGHT var p = new System.Windows.AssemblyPart(); var result = p.Load(stream); #else var result = SR.Assembly.Load(stream.ToArray()); #endif return(result); } }
// - - - /// <summary> /// Find modifiers of an assembly. /// </summary> /// <param name="assemblyShortName">The assembly (short) name [not the file name].</param> /// <param>On (pure, not portable) Android, the DLL file must be added as an Asset.</param> /// <returns></returns> /// <exception cref="FileNotFoundException">Please note on .NET Core the current directory can be wrong. Please set it correctly before calling this function.</exception> public static ModifiersAssembly GetModifiersAssembly(string assemblyShortName) { Assembly assembly; #if WINDOWS_UWP var an = new AssemblyName(assemblyShortName); assembly = Assembly.Load(an); #else #if SILVERLIGHT && !WINDOWS_PHONE7_1 var name = assemblyShortName + ".dll"; var uri = new Uri(name, UriKind.Relative); var sm = System.Windows.Application.GetResourceStream(uri); if (sm == null) { throw new FileNotFoundException(name); } var ap = new System.Windows.AssemblyPart(); assembly = ap.Load(sm.Stream); #else #if ANDROID // On Android, the DLL files must be added as embedded resources to the application project. var ea = Tools.GetEntryAssembly(); // finds the application assembly. var an = ea.GetName(); var an2 = an.Name; var name = an2 + "." + assemblyShortName + ".dll"; //var r =ea.GetManifestResourceNames(); using (var sm = ea.GetManifestResourceStream(name)) { if (sm == null) { throw new FileNotFoundException(name); } var bytes = new byte[sm.Length]; sm.Read(bytes, 0, bytes.Length); assembly = Assembly.Load(bytes); } #else // ordinary .NET try { assembly = Assembly.Load(assemblyShortName); } catch (FileNotFoundException ex) { // tries to read the dll file. var name = assemblyShortName + ".dll"; if (File.Exists(name)) { assembly = Assembly.LoadFrom(name); } else { // looks in the resources of all referenced assemblies for an embedded file. assembly = null; var ea = Tools.GetEntryAssembly(); // finds the application assembly. if (ea != null) { assembly = _LoadResourceAssembly(ea, assemblyShortName); } if (assembly == null) { // Searches the file in the resources of all loaded assemblies. var assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length && assembly == null; i++) { Assembly rc = assemblies[i]; assembly = _LoadResourceAssembly(rc, assemblyShortName); } } if (assembly == null) { throw ex; } } } #endif #endif #endif return(ModifiersAssembly.GetModifiersAssembly(assembly)); }