After running my project few times I'm getting error: Could not resolve COM reference "f8937e53-d444-4e71-9275-35b64210cc3b" what's that?

After running my project few times I'm getting error: Could not resolve COM reference "f8937e53-d444-4e71-9275-35b64210cc3b" what's that?

这是完整的错误:

Error   1   Could not resolve COM reference "f8937e53-d444-4e71-9275-35b64210cc3b" version 1.0. The specified image file did not contain a resource section. (Exception from HRESULT: 0x80070714)   UsingAutoIt

之前从未有过 google 没有找到任何包含此参考长号和字母的内容。

这是我的form1完整代码,不长。也许是 DllImport 造成了问题?但是以前没有。奇怪的错误。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using AutoItX3Lib;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace UsingAutoIt
{
    public partial class Form1 : Form
    {
        [DllImport("USER32.DLL")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);


        static AutoItX3Lib.AutoItX3Class au3;
        static Thread thread;
        static bool threadshouldexecute = true;
        static int i = 0;
        string processName = "GameCapture";
        string existingProcessName = "Game Capture HD";
        string processFileName = @"C:\Program Files (x86)\Elgato\GameCapture\GameCapture.exe";
        IntPtr windowHandle;

        public Form1()
        {
            InitializeComponent();


            au3 = new AutoItX3Lib.AutoItX3Class();
            au3.AutoItSetOption("WinTitleMatchMode", 4);

            if (au3.WinExists(existingProcessName, "") == 0) // Window not found
            {
                int processId = au3.Run(processFileName, "", au3.SW_SHOW);
                BringToFront(processId);
                Thread.Sleep(10000);
                au3.MouseClick("LEFT", 358, 913, 1, -1);

            }
            else
            {
                Process[] processes = Process.GetProcessesByName(processName);
                BringToFront(processes[0].Id);
                au3.MouseClick("LEFT", 358, 913, 1, -1);
            }
        }

        public static void BringToFront(int processId)
        {
            Process process = Process.GetProcessById(processId);
            IntPtr handle = process.MainWindowHandle;

            if (handle == IntPtr.Zero)
                return;

            SetForegroundWindow(handle);
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            System.Windows.Forms.Timer t1 = new System.Windows.Forms.Timer();
            t1.Interval = 50;
            t1.Tick += new EventHandler(timer1_Tick);
            //t1.Enabled = true;
            t1.Enabled = false;
        }

        public static Point GetMousePosition()
        {
            var position = System.Windows.Forms.Cursor.Position;
            return new Point(position.X, position.Y);
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = string.Format("X={0}, Y={1}", GetMousePosition().X, GetMousePosition().Y);
        }
    }
}

But to do that I had first to register using regsrv32 only after register it I could add as reference the dll file.

这是正常的,Visual Studio在项目文件中存储了类型库的guid。类型库是对 COM 组件导出的类型的描述。与 .NET 程序集中的元数据非常相似。从项目文件中的 "f8937e53-d444-4e71-9275-35b64210cc3b" guid 找回库需要 Visual Studio 在注册表中查找,HKCR\TypeLib 项。在 COM 组件注册 之后,它才会存在。是的,Regsvr32.exe,一般情况下最好使用组件的安装程序。

I had to change the property Embed Interop Types to false

那是因为您在源代码中使用了 AutoItX3Lib.AutoItX3Class。这是从类型库生成的合成 class,它使实现多个接口的 COM 组件更易于使用。然而,这样一个合成的 class 无法嵌入,这就是为什么你必须将 属性 设置为 false。一个简单的解决方法是从类型名称中省略 "Class",以便您只使用接口。修复:

    static AutoItX3Lib.AutoItX3 au3;
    ....
    au3 = new AutoItX3Lib.AutoItX3();