BrokeredComponents TypeLoad and InvalidCastException

本文关键字:InvalidCastException and TypeLoad BrokeredComponents | 更新日期: 2023-09-27 18:08:44

我们正在尝试在UWP上使用BrokeredComponents。我们正在接收TypeLoadExceptionInvalidCastException

我们定义了一个名为BrokeredComponentsHost的类,它被用作通用类,因此我们可以访问BrokeredComponents内部的其他类。

我们为每个组件使用guid。

这是BrokeredComponentsHost:

namespace BrokeredComponents
{    
    [Guid(BrokeredComponentsHost.ClassId), ComVisible(true)]
    public sealed class BrokeredComponentsHost : IBrokeredComponentFactory
    {
        internal const string ClassId = "881724C4-E330-40D5-BDA1-7D9F7C44FB7C";
        internal const string FactoryInterfaceId = "1FA85472-5B0D-487C-B58E-F8BE9A89D470";
        internal const string BarcodeScannerInterfaceId = "840F54D5-7AF7-4C31-91B0-BA274FCDD737";
        public string LastError { get; set; }
        public IPosScanner GetPosScanner()
        {
            return new PosScanner() { Host = this };
        }
    }
}

这是IBrokeredComponentsFactory:

namespace BrokeredComponents
{
    [Guid(BrokeredComponentsHost.FactoryInterfaceId), ComVisible(true)]
    public interface IBrokeredComponentFactory
    {
        IPosScanner GetPosScanner();
        string LastError { get; set; }
    }
}

这是PosScanner和它的接口:

namespace BrokeredComponents
{
    [Guid(BrokeredComponentsHost.BarcodeScannerInterfaceId), ComVisible(true)]
    public interface IPosScanner : IPosDevice
    {
        bool DecodeData { get; set; }
        bool DeviceEnabled { get; set; }
        bool DataEventEnabled { get; set; }
        bool AutoDisable { get; set; }
        byte[] ScanData { get; }
    }
}

当我们尝试创建BrokeredComponentsHost (bcHost = new BrokeredComponents.BrokeredComponentsHost();)的新实例时,它会抛出typeloadeexception。

如果我们定义了一个新类(例如processexexecutor class),重建了所有的东西,然后再次尝试创建BrokeredComponentsHost的新实例,它会抛出InvalidCastException。

我们做icacls。/T/grant " ALL APPLICATION PACKAGES ":RX and regsvr32 theproxy.dll.

有人遇到同样的问题并知道解决方法吗?

谢谢!

编辑:我收到的确切错误信息是"Unable to cast COM object of type 'BrokeredComponents.BrokeredComponentsHost' to interface type 'BrokeredComponents.IBrokeredComponentFactory'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{1FA85472-5B0D-487C-B58E-F8BE9A89D470}' failed due to the following error: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."

我在Windows 10 64位上运行,但我的BrokeredComponents项目是Windows 8.1和BrokeredComponentsProxy是VS 2013。

编辑2:我已经修复了TypeLoad异常,这是一个错误的扩展为未在Appxmanifest文件中定义的暴露类。我仍然遇到InvalidCastException虽然

BrokeredComponents TypeLoad and InvalidCastException

谢谢Franklin和Lawrence。

我已经找出了错误,这是因为主要的UWP项目是针对x64的,而我们的BrokeredComponents和解决方案中的其他项目是针对x86的。

我将UWP项目更改为x86并注册了。dll,现在工作正常。

相关文章:
  • 没有找到相关文章