Visual Studio 未能加载文件或程序集“System.Private.CoreLib,版本=4.0.0.0,区域性=非特定,公钥标记=7cec85d7bea7798e”

r3i60tvu  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(722)

我正在尝试运行此代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Bluetooth;
using Windows.Devices.Enumeration;

namespace Bluetooth_sharp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            
            // Query for extra properties you want returned
            string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" };

            DeviceWatcher deviceWatcher =
                        DeviceInformation.CreateWatcher(
                                BluetoothLEDevice.GetDeviceSelectorFromPairingState(false),
                                requestedProperties,
                                DeviceInformationKind.AssociationEndpoint);

            // Register event handlers before starting the watcher.
            // Added, Updated and Removed are required to get all nearby devices
            deviceWatcher.Added += DeviceWatcher_Added;
            deviceWatcher.Updated += DeviceWatcher_Updated;
            deviceWatcher.Removed += DeviceWatcher_Removed;

            // EnumerationCompleted and Stopped are optional to implement.
            deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
            deviceWatcher.Stopped += DeviceWatcher_Stopped;

            // Start the watcher.
            deviceWatcher.Start();

            while (true)
            {
                Console.WriteLine("Press any key . . .");
                Console.ReadKey();
            }
        }

        private static void DeviceWatcher_Stopped(DeviceWatcher sender, object args)
        {
            //throw new NotImplementedException();
        }

        private static void DeviceWatcher_EnumerationCompleted(DeviceWatcher sender, object args)
        {
            //throw new NotImplementedException();
        }

        private static void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate args)
        {
            //throw new NotImplementedException();
        }

        private static void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate args)
        {
            //throw new NotImplementedException();
        }

        private static void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
        {
            Console.WriteLine(args.Name);
            //throw new NotImplementedException();
        }
    }

}

这是示例代码,我从:https://learn.microsoft.com/en-us/windows/uwp/devices-sensors/gatt-client
但是当我执行它时,我得到了以下错误:

'Bluetooth-sharp.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'Bluetooth-sharp.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\elect\source\repos\Bluetooth-sharp\Bluetooth-sharp\bin\Debug\Bluetooth-sharp.exe'. Symbols loaded.
'Bluetooth-sharp.exe' (CLR v4.0.30319: Bluetooth-sharp.exe): Loaded 'C:\windows\SysNative\WinMetadata\Windows.Devices.winmd'. Module was built without symbols.
'Bluetooth-sharp.exe' (CLR v4.0.30319: Bluetooth-sharp.exe): Loaded 'C:\Users\elect\source\repos\Bluetooth-sharp\Bluetooth-sharp\bin\Debug\System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.
Could not load file or assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.

The program '[10840] Bluetooth-sharp.exe' has exited with code 4294967295 (0xffffffff).

我跟踪this tutorial,但他没有遇到这个错误。我做了一件不同的事情,他的 * 系统.运行时.WindowsRuntime.dll* 在 *C:\程序文件(x86)\引用程序集\Microsoft\Framework.NETCore\v4.5 * 中,而我的是从 C:\程序文件(x86)\Microsoft SDKs\UWPNuGetPackages\runtime.win10-arm.microsoft.netcore.universalwindowsplatform\6.2.14\runtime\win10-arm\lib\uap10.0.15138 中获得的,因为我在另一个文件夹中只有XML文件。
我在谷歌上找不到任何东西能够解决这个问题。

zf9nrax1

zf9nrax11#

在您的问题中,发生的情况是在存储中跳过了.NET本机编译,导致绑定包无效,因为声明的依赖项与绑定包的内容不匹配。您需要重新检查正在使用的依赖项的版本。此外,我注意到“程序'[10840] Bluetooth-sharp.exe'已退出,代码为4294967295(0xffffffff).”这是因为没有找到相应的文件,您最好更改为与示例代码相同的路径。

相关问题