public void DifferingMvids() { var directory = Temp.CreateDirectory(); // Load Beta.dll from the future Alpha.dll path to prime the assembly loader var alphaDll = directory .CreateFile("Alpha.dll") .WriteAllBytes(TestResources.AssemblyLoadTests.Beta); var assemblyLoader = new InMemoryAssemblyLoader(); var betaAssembly = assemblyLoader.LoadFromPath(alphaDll.Path); alphaDll.WriteAllBytes(TestResources.AssemblyLoadTests.Alpha); var gammaDll = directory .CreateFile("Gamma.dll") .WriteAllBytes(TestResources.AssemblyLoadTests.Gamma); var deltaDll = directory .CreateFile("Delta.dll") .WriteAllBytes(TestResources.AssemblyLoadTests.Delta); var analyzerReferences = ImmutableArray.Create( new CommandLineAnalyzerReference("Alpha.dll"), new CommandLineAnalyzerReference("Gamma.dll"), new CommandLineAnalyzerReference("Delta.dll") ); var result = AnalyzerConsistencyChecker.Check( directory.Path, analyzerReferences, assemblyLoader, Logger ); Assert.False(result); }
public Assembly GetAssembly() { if (_lazyAssembly == null) { var assembly = _getAssembly != null? _getAssembly(_fullPath) : InMemoryAssemblyLoader.Load(_fullPath); Interlocked.CompareExchange(ref _lazyAssembly, assembly, null); } return(_lazyAssembly); }
public Assembly GetAssembly() { if (lazyAssembly == null) { var assembly = getAssembly != null? getAssembly(fullPath) : InMemoryAssemblyLoader.Load(fullPath); Interlocked.CompareExchange(ref this.lazyAssembly, assembly, null); } return(lazyAssembly); }
public void DifferingMvids() { var directory = Temp.CreateDirectory(); // Load Beta.dll from the future Alpha.dll path to prime the assembly loader var alphaDll = directory.CreateFile("Alpha.dll").WriteAllBytes(TestResources.AssemblyLoadTests.AssemblyLoadTests.Beta); var assemblyLoader = new InMemoryAssemblyLoader(); var betaAssembly = assemblyLoader.LoadFromPath(alphaDll.Path); alphaDll.WriteAllBytes(TestResources.AssemblyLoadTests.AssemblyLoadTests.Alpha); var gammaDll = directory.CreateFile("Gamma.dll").WriteAllBytes(TestResources.AssemblyLoadTests.AssemblyLoadTests.Gamma); var deltaDll = directory.CreateFile("Delta.dll").WriteAllBytes(TestResources.AssemblyLoadTests.AssemblyLoadTests.Delta); var analyzerReferences = ImmutableArray.Create( new CommandLineAnalyzerReference("Alpha.dll"), new CommandLineAnalyzerReference("Gamma.dll"), new CommandLineAnalyzerReference("Delta.dll")); var result = AnalyzerConsistencyChecker.Check(directory.Path, analyzerReferences, assemblyLoader); Assert.False(result); }
public void DifferingMvids() { var directory = Temp.CreateDirectory(); // Load Beta.dll from the future Alpha.dll path to prime the assembly loader var alphaDll = directory.CopyFile(TestFixture.Beta.Path, name: "Alpha.dll"); var assemblyLoader = new InMemoryAssemblyLoader(); var betaAssembly = assemblyLoader.LoadFromPath(alphaDll.Path); // now overwrite the {directory}/Alpha.dll file with the content from our Alpha.dll test resource alphaDll.CopyContentFrom(TestFixture.Alpha.Path); directory.CopyFile(TestFixture.Gamma.Path); directory.CopyFile(TestFixture.Delta1.Path); var analyzerReferences = ImmutableArray.Create( new CommandLineAnalyzerReference("Alpha.dll"), new CommandLineAnalyzerReference("Gamma.dll"), new CommandLineAnalyzerReference("Delta.dll")); var result = AnalyzerConsistencyChecker.Check(directory.Path, analyzerReferences, assemblyLoader, Logger); Assert.False(result); }
unsafe static int Main(string[] args) { // Disable running on Windows 7 until IJW activation work is complete. if (Environment.OSVersion.Platform != PlatformID.Win32NT || (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1)) { return(100); } try { HostPolicyMock.Initialize(Environment.CurrentDirectory, null); Console.WriteLine("Verify that we can load an IJW assembly from native code."); string ijwModulePath = Path.Combine(Environment.CurrentDirectory, "IjwNativeCallingManagedDll.dll"); IntPtr ijwNativeHandle = NativeLibrary.Load(ijwModulePath); using (HostPolicyMock.Mock_corehost_resolve_component_dependencies( 0, ijwModulePath, string.Empty, string.Empty)) fixed(char *path = ijwModulePath) { InMemoryAssemblyLoader.LoadInMemoryAssembly(ijwNativeHandle, (IntPtr)path); } NativeEntryPointDelegate nativeEntryPoint = Marshal.GetDelegateForFunctionPointer <NativeEntryPointDelegate>(NativeLibrary.GetExport(ijwNativeHandle, "NativeEntryPoint")); Assert.AreEqual(100, nativeEntryPoint()); Console.WriteLine("Test calls from managed to native to managed when an IJW assembly was first loaded via native."); Assembly ijwAssemblyManaged = Assembly.Load("IjwNativeCallingManagedDll"); Type testType = ijwAssemblyManaged.GetType("TestClass"); object testInstance = Activator.CreateInstance(testType); MethodInfo testMethod = testType.GetMethod("ManagedEntryPoint"); Assert.AreEqual(100, (int)testMethod.Invoke(testInstance, null)); MethodInfo changeReturnedValueMethod = testType.GetMethod("ChangeReturnedValue"); MethodInfo getReturnValueMethod = testType.GetMethod("GetReturnValue"); int newValue = 42; changeReturnedValueMethod.Invoke(null, new object[] { newValue }); Assert.AreEqual(newValue, (int)getReturnValueMethod.Invoke(null, null)); // Native images are only loaded into memory once. As a result, the stubs in the vtfixup table // will always point to JIT stubs that exist in the first ALC that the module was loaded into. // As a result, if an IJW module is loaded into two different ALCs, or if the module is // first loaded via a native call and then loaded via the managed loader, the call stack can change ALCs when // jumping from managed->native->managed code within the IJW module. Assert.AreEqual(100, (int)testMethod.Invoke(testInstance, null)); return(100); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(101); } }
/// <summary> /// Maps from one assembly back to the assembly that requested it, if known. /// </summary> public static string TryGetRequestingAssemblyPath(string assemblyPath) { return(InMemoryAssemblyLoader.TryGetRequestingAssembly(assemblyPath)); }