Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试在.net4 don';似乎不起作用_C#_.net_Visual Studio 2010_Dll_Rebasing - Fatal编程技术网

C# 尝试在.net4 don';似乎不起作用

C# 尝试在.net4 don';似乎不起作用,c#,.net,visual-studio-2010,dll,rebasing,C#,.net,Visual Studio 2010,Dll,Rebasing,我正在.net4上运行的一个小型测试解决方案上进行Dll重定基址的实验,该解决方案由一个小型.exe和三个小型.Dll组成。程序集引用设置正确,程序编译和运行正常 这个练习的目的是检查重定基调是如何工作的,这样我就可以将它与ngen结合起来,并在我正在进行的一个大型项目中提高性能 我尝试了许多不同的方法重新设置DLL的基址,并使用vmmap、visual studio模块调试器窗口和process explorer监视结果;到目前为止,还没有成功的案例: 我已经将Dll1.DLL、Dll2.DL

我正在.net4上运行的一个小型测试解决方案上进行Dll重定基址的实验,该解决方案由一个小型.exe和三个小型.Dll组成。程序集引用设置正确,程序编译和运行正常

这个练习的目的是检查重定基调是如何工作的,这样我就可以将它与ngen结合起来,并在我正在进行的一个大型项目中提高性能

我尝试了许多不同的方法重新设置DLL的基址,并使用vmmap、visual studio模块调试器窗口和process explorer监视结果;到目前为止,还没有成功的案例:

  • 我已经将Dll1.DLL、Dll2.DLL和Dll3.DLL的Build->Advanced->DLL基址设置分别设置为0x41000000、0x42000000和0x43000000。在每个DLL中,这些地址肯定被保存为首选的基址,但是对于每次运行,DLL都会不规则地将它们的映像重新定基到内存中的许多不同位置

  • 我试过使用这个应用程序。它生成的日志显示DLL确实内置了首选的基址(由我选择),但是在运行时结果仍然不稳定

  • 我试过使用ngen。这导致.ni版本的DLL与原始DLL一起加载,并且所有6个DLL的内存位置都不稳定,与我要求的内存位置相差甚远

  • 我试着把我的照片贴在GAC上。令人振奋的是,只加载了GAC版本的DLL,但它们的内存位置仍然不稳定

  • 我试过上面的每一个组合。没有成功

  • 在运行时使用VMMap查看显示,地址空间中的可用内存在0x10000000和0x50000000之间存在巨大的缺口,因此应该不会发生冲突,也不需要重新设置Dll的基址。DLL也非常小,我在它们之间留下的0x01000000间隙非常大,所以它们不应该相互碰撞

    我错过了什么

    在本练习中,我的主要参考文献是一篇文章,内容丰富,但是2006年为.Net2编写的:从那时到现在,有什么根本性的变化吗

    我很怀疑这会有多大的区别,但以下是我为以防万一而使用的代码:

    Program.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using Dll1;
    using Dll2;
    using Dll3;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Thread.CurrentThread.Name = "Poodle";
                Console.ReadLine();
                //Thread.Sleep(10000);
                Blah();
            }
    
            static void Blah()
            {
                Console.WriteLine(Class2.shrooms(5, 'h'));
                Class3.teenAngst();
                Class1.Wait();
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll1
    {
        public static class Class1
        {
            public static void Wait()
            {
                Console.ReadLine();
                Console.Write("   ");
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll2
    {
        public static class Class2
        {
            public static string shrooms(int argc, char argv) 
            {
                return "Ranchdaddyx   ";
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll3
    {
        public static class Class3
        {
            public static void teenAngst()
            {
                Console.Write("Belonging   ");
            }
        }
    }
    
    Class1.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using Dll1;
    using Dll2;
    using Dll3;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Thread.CurrentThread.Name = "Poodle";
                Console.ReadLine();
                //Thread.Sleep(10000);
                Blah();
            }
    
            static void Blah()
            {
                Console.WriteLine(Class2.shrooms(5, 'h'));
                Class3.teenAngst();
                Class1.Wait();
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll1
    {
        public static class Class1
        {
            public static void Wait()
            {
                Console.ReadLine();
                Console.Write("   ");
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll2
    {
        public static class Class2
        {
            public static string shrooms(int argc, char argv) 
            {
                return "Ranchdaddyx   ";
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll3
    {
        public static class Class3
        {
            public static void teenAngst()
            {
                Console.Write("Belonging   ");
            }
        }
    }
    
    Class2.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using Dll1;
    using Dll2;
    using Dll3;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Thread.CurrentThread.Name = "Poodle";
                Console.ReadLine();
                //Thread.Sleep(10000);
                Blah();
            }
    
            static void Blah()
            {
                Console.WriteLine(Class2.shrooms(5, 'h'));
                Class3.teenAngst();
                Class1.Wait();
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll1
    {
        public static class Class1
        {
            public static void Wait()
            {
                Console.ReadLine();
                Console.Write("   ");
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll2
    {
        public static class Class2
        {
            public static string shrooms(int argc, char argv) 
            {
                return "Ranchdaddyx   ";
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll3
    {
        public static class Class3
        {
            public static void teenAngst()
            {
                Console.Write("Belonging   ");
            }
        }
    }
    
    Class3.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using Dll1;
    using Dll2;
    using Dll3;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Thread.CurrentThread.Name = "Poodle";
                Console.ReadLine();
                //Thread.Sleep(10000);
                Blah();
            }
    
            static void Blah()
            {
                Console.WriteLine(Class2.shrooms(5, 'h'));
                Class3.teenAngst();
                Class1.Wait();
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll1
    {
        public static class Class1
        {
            public static void Wait()
            {
                Console.ReadLine();
                Console.Write("   ");
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll2
    {
        public static class Class2
        {
            public static string shrooms(int argc, char argv) 
            {
                return "Ranchdaddyx   ";
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Dll3
    {
        public static class Class3
        {
            public static void teenAngst()
            {
                Console.Write("Belonging   ");
            }
        }
    }
    

    .Net.dll与它们的非托管等价物截然不同。老实说,我不认为重新定基是相关的

    查看这篇MSDN文章。除其他外,这会鼓励您不要重新设定基准。并给出了至少一个令人信服的理由(这可能会使强签名程序集的签名无效)。本文还讨论了NGEN的潜在好处(以及您的链接):


    无需重新设置JIT编译代码的基础:

    JIT编译的代码没有重定基址问题,因为地址 在运行时根据代码在内存中的位置生成。 此外,MSIL很少受到基址未命中的影响,因为MSIL 引用是基于令牌的,而不是基于地址的。因此,当 使用JIT编译器,系统对基址具有弹性 碰撞


    原来(地址空间布局随机化)是我困惑的罪魁祸首。显然你可以关掉它,但是你牺牲了安全/为自己做了很多工作。我认为整个冒险是一次失败的实验。

    这篇文章说我应该避免在自动意义上重新设置,并且在使用NGEN时,我应该选择自己的基地址。事先选择基址可以避免在运行时重定基址,这是一个非常昂贵的过程。让我沮丧的是,无论我做了什么,这都不会发生。我正在尝试重新设置ngen代码的基础。重定MSIL代码的基调只是试图让重定基调发挥作用的一个练习。即使没有必要,也有可能吗?