Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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# WPF single.exe Microsoft.Threading.Tasks.dll_C#_Wpf_Wpf 4.0 - Fatal编程技术网

C# WPF single.exe Microsoft.Threading.Tasks.dll

C# WPF single.exe Microsoft.Threading.Tasks.dll,c#,wpf,wpf-4.0,C#,Wpf,Wpf 4.0,关于使用模板将WPF.NET4程序集打包到single.exe中,我遇到了一个奇怪的问题 除了Microsoft.Bcl库,尤其是(Microsoft.Threading.Tasks.dll),其他一切都可以正常工作。我尝试添加(Microsoft.Threading.Tasks.dll)并将其标记为资源和/或嵌入资源,但是如果指定的dll不在main.exe附近,则应用程序将不正常退出。有什么想法吗 负责打包的主要代码。DLL为(取自模板): 您不应该在.NET的系统库中执行此操作。请确保安装

关于使用模板将WPF.NET4程序集打包到single.exe中,我遇到了一个奇怪的问题 除了Microsoft.Bcl库,尤其是(Microsoft.Threading.Tasks.dll),其他一切都可以正常工作。我尝试添加(Microsoft.Threading.Tasks.dll)并将其标记为资源和/或嵌入资源,但是如果指定的dll不在main.exe附近,则应用程序将不正常退出。有什么想法吗

负责打包的主要代码。DLL为(取自模板):


您不应该在.NET的系统库中执行此操作。请确保安装了正确版本的.NET framework。我不知道你的意思是什么?Microsoft.Bcl库是通过nuget添加的,因此需要包含它。
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs e)
    {
        var thisAssembly = Assembly.GetExecutingAssembly();

        // Get the Name of the AssemblyFile
        var assemblyName = new AssemblyName(e.Name);
        var dllName = assemblyName.Name + ".dll";

        // Load from Embedded Resources - This function is not called if the Assembly is already
        // in the same folder as the app.
        var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(dllName));
        if (resources.Any())
        {

            // 99% of cases will only have one matching item, but if you don't,
            // you will have to change the logic to handle those cases.
            var resourceName = resources.First();
            using (var stream = thisAssembly.GetManifestResourceStream(resourceName))
            {
                if (stream == null) return null;
                var block = new byte[stream.Length];

                // Safely try to load the assembly.
                try
                {
                    stream.Read(block, 0, block.Length);
                    return Assembly.Load(block);
                }
                catch (IOException)
                {
                    return null;
                }
                catch (BadImageFormatException)
                {
                    return null;
                }
            }
        }

        // in the case the resource doesn't exist, return null.
        return null;
    }