/// <summary> /// Loads a native library with a reflected assembly holding the native libraries /// </summary> /// <param name="assemblyName">The name of the assembly to reflect into and load from</param> /// <param name="localLoadOnRio">True to force a local load on the RoboRIO</param> public void LoadNativeLibraryFromReflectedAssembly(string assemblyName, bool localLoadOnRio = true) { if (localLoadOnRio && CheckIsRoboRio()) { ILibraryLoader loader = new EmbeddedLibraryLoader(); LibraryLoader = loader; var location = m_nativeLibraryName[OsType.roboRIO]; loader.LoadLibrary(location); LibraryLocation = location; return; } AssemblyName name = new AssemblyName(assemblyName); Assembly asm; try { asm = Assembly.Load(name); } catch (Exception e) { throw new InvalidOperationException($"Failed to load desktop libraries. Please ensure that the {assemblyName} is installed and referenced by your project", e); } LoadNativeLibraryFromAssembly(asm, localLoadOnRio); }
/// <summary> /// Loads a native library with a reflected assembly holding the native libraries /// </summary> /// <param name="assembly">The assembly to load from</param> /// <param name="localLoadOnRio">True to force a local load on the RoboRIO</param> public void LoadNativeLibraryFromAssembly(Assembly assembly, bool localLoadOnRio = true) { if (localLoadOnRio && CheckIsRoboRio()) { ILibraryLoader loader = new EmbeddedLibraryLoader(); LibraryLoader = loader; var location = m_nativeLibraryName[OsType.roboRIO]; loader.LoadLibrary(location); LibraryLocation = location; return; } if (OsType == OsType.None) { throw new InvalidOperationException( "OS type is unknown. Must use the overload to manually load the file"); } if (!m_nativeLibraryName.ContainsKey(OsType)) { throw new InvalidOperationException("OS Type not contained in dictionary"); } switch (OsType) { case OsType.Windows32: case OsType.Windows64: LibraryLoader = new WindowsLibraryLoader(); break; case OsType.Linux32: case OsType.Linux64: LibraryLoader = new LinuxLibraryLoader(); break; case OsType.MacOs32: case OsType.MacOs64: LibraryLoader = new MacOsLibraryLoader(); break; case OsType.LinuxAarch64: case OsType.LinuxRaspbian: case OsType.roboRIO: LibraryLoader = new EmbeddedLibraryLoader(); break; } if (LibraryLoader == null) { throw new ArgumentNullException(nameof(LibraryLoader), "Library loader cannot be null"); } string extractLocation = Path.GetTempFileName(); UsingTempFile = true; ExtractNativeLibrary(m_nativeLibraryName[OsType], extractLocation, assembly); LibraryLoader.LoadLibrary(extractLocation); LibraryLocation = extractLocation; }