public static BindOperation SatelliteAssembly_CultureSubdirectory() { AssemblyName assemblyName = new AssemblyName($"{SubdirectoryAssemblyName}.resources"); assemblyName.CultureInfo = SatelliteCulture; CustomALC alc = new CustomALC(nameof(SatelliteAssembly_CultureSubdirectory)); alc.LoadFromAssemblyPath(Helpers.GetAssemblyInSubdirectoryPath(SubdirectoryAssemblyName)); Assembly asm = alc.LoadFromAssemblyName(assemblyName); return(new BindOperation() { AssemblyName = assemblyName, AssemblyLoadContext = alc.ToString(), Success = true, ResultAssemblyName = asm.GetName(), ResultAssemblyPath = asm.Location, Cached = false, ProbedPaths = new List <ProbedPath>() { new ProbedPath() { FilePath = Helpers.GetProbingFilePath(ProbedPath.PathSource.SatelliteSubdirectory, assemblyName.Name, SatelliteCulture.Name, Helpers.GetSubdirectoryPath()), Source = ProbedPath.PathSource.SatelliteSubdirectory, Result = S_OK } } }); }
public static BindOperation ResolveSatelliteAssembly() { AssemblyName assemblyName = new AssemblyName($"{DependentAssemblyName}.resources"); assemblyName.CultureInfo = SatelliteCulture; CustomALC alc = new CustomALC(nameof(ResolveSatelliteAssembly)); alc.LoadFromAssemblyPath(Helpers.GetAssemblyInAppPath(DependentAssemblyName)); Assembly asm = alc.LoadFromAssemblyName(assemblyName); return(new BindOperation() { AssemblyName = assemblyName, AssemblyLoadContext = alc.ToString(), Success = true, ResultAssemblyName = asm.GetName(), ResultAssemblyPath = asm.Location, Cached = false, ResolutionAttempts = new List <ResolutionAttempt>() { GetResolutionAttempt(assemblyName, ResolutionStage.FindInLoadContext, alc, ResolutionResult.AssemblyNotFound), GetResolutionAttempt(assemblyName, ResolutionStage.AssemblyLoadContextLoad, alc, ResolutionResult.AssemblyNotFound), GetResolutionAttempt(assemblyName, ResolutionStage.ResolveSatelliteAssembly, alc, ResolutionResult.Success, asm) } }); }
public static BindOperation SatelliteAssembly_CultureSubdirectory_Lowercase() { AssemblyName assemblyName = new AssemblyName($"{SubdirectoryAssemblyName}.resources"); assemblyName.CultureInfo = SatelliteCulture; CustomALC alc = new CustomALC(nameof(SatelliteAssembly_CultureSubdirectory)); alc.LoadFromAssemblyPath(Helpers.GetAssemblyInSubdirectoryPath(SubdirectoryAssemblyName)); Assembly asm; string subdirectoryPath = Helpers.GetSubdirectoryPath(); string cultureSubdirectory = Path.Combine(subdirectoryPath, SatelliteCulture.Name); string cultureSubdirectoryLower = Path.Combine(subdirectoryPath, SatelliteCulture.Name.ToLowerInvariant()); try { Directory.Move(cultureSubdirectory, cultureSubdirectoryLower); asm = alc.LoadFromAssemblyName(assemblyName); } finally { Directory.Move(cultureSubdirectoryLower, cultureSubdirectory); } var probedPaths = new List <ProbedPath>() { new ProbedPath() { FilePath = Helpers.GetProbingFilePath(ProbedPath.PathSource.SatelliteSubdirectory, assemblyName.Name, SatelliteCulture.Name, subdirectoryPath), Source = ProbedPath.PathSource.SatelliteSubdirectory, Result = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? COR_E_FILENOTFOUND : S_OK } }; // On Linux, the path with a lower-case culture name should also be probed if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { probedPaths.Add(new ProbedPath() { FilePath = Helpers.GetProbingFilePath(ProbedPath.PathSource.SatelliteSubdirectory, assemblyName.Name, SatelliteCulture.Name.ToLowerInvariant(), subdirectoryPath), Source = ProbedPath.PathSource.SatelliteSubdirectory, Result = S_OK }); } return(new BindOperation() { AssemblyName = assemblyName, AssemblyLoadContext = alc.ToString(), Success = true, ResultAssemblyName = asm.GetName(), ResultAssemblyPath = asm.Location, Cached = false, ProbedPaths = probedPaths }); }
public static BindOperation LoadFromAssemblyPath() { CustomALC alc = new CustomALC(nameof(LoadFromAssemblyPath)); var executingAssembly = Assembly.GetExecutingAssembly(); Assembly asm = alc.LoadFromAssemblyPath(executingAssembly.Location); return(new BindOperation() { AssemblyName = executingAssembly.GetName(), AssemblyPath = executingAssembly.Location, AssemblyLoadContext = alc.ToString(), RequestingAssemblyLoadContext = DefaultALC, Success = true, ResultAssemblyName = asm.GetName(), ResultAssemblyPath = asm.Location, Cached = false }); }
public static BindOperation SatelliteAssembly_NotFound() { string cultureName = "en-GB"; AssemblyName assemblyName = new AssemblyName($"{SubdirectoryAssemblyName}.resources"); assemblyName.CultureInfo = new CultureInfo(cultureName); CustomALC alc = new CustomALC(nameof(SatelliteAssembly_CultureSubdirectory)); alc.LoadFromAssemblyPath(Helpers.GetAssemblyInSubdirectoryPath(SubdirectoryAssemblyName)); Assert.Throws <FileNotFoundException>(() => alc.LoadFromAssemblyName(assemblyName)); var probedPaths = new List <ProbedPath>() { new ProbedPath() { FilePath = Helpers.GetProbingFilePath(ProbedPath.PathSource.SatelliteSubdirectory, assemblyName.Name, cultureName, Helpers.GetSubdirectoryPath()), Source = ProbedPath.PathSource.SatelliteSubdirectory, Result = COR_E_FILENOTFOUND } }; // On Linux (case-sensitive), the path with a lower-case culture name should also be probed if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { probedPaths.Add(new ProbedPath() { FilePath = Helpers.GetProbingFilePath(ProbedPath.PathSource.SatelliteSubdirectory, assemblyName.Name, cultureName.ToLowerInvariant(), Helpers.GetSubdirectoryPath()), Source = ProbedPath.PathSource.SatelliteSubdirectory, Result = COR_E_FILENOTFOUND }); } return(new BindOperation() { AssemblyName = assemblyName, AssemblyLoadContext = alc.ToString(), Success = false, Cached = false, ProbedPaths = probedPaths }); }
private static void LoadSubdirectoryAssembly_InstanceALC() { string assemblyPath = Helpers.GetAssemblyInSubdirectoryPath(SubdirectoryAssemblyName); loadedAssembly = alcInstance.LoadFromAssemblyPath(assemblyPath); }