更新Windows10后,如果程序与Interop.photoshop.dll一起出现System.InvalidCastExecption错误消息

时间:2018-04-03 16:52:35

标签: c# windows-10 photoshop

更新到Windows 10后,Visual Studio 2017上的C#程序处理图像并使用Interop.Photoshop.dll和Interop.PhotoshopTypeLibrary.dll,得到以下问题:

"System.InvalidCastException: Unable to cast COM object of type 'Photoshop.ApplicationClass' to interface type 'Photoshop._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{5DE90358-4D0B-4FA1-BA3E-C91BBA863F32}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Photoshop.ApplicationClass.Quit()"

相同的程序在更新之前正在运行,它适用于Windows 7和8。

有人可以帮助我吗?

3 个答案:

答案 0 :(得分:0)

解决了它以管理员身份运行Photoshop并重新启动计算机的问题。 除此之外,我还使用以下功能找到了我的PS实例。

并且没有再次崩溃,它得到了正确执行:

        /// <summary>
    /// Find the Photoshop instance and return it
    /// </summary>
    /// <returns>Photoshop Application COM object</returns>
    [STAThread]
    public static Photoshop.Application SetPhotoshop()
    {
        Type photoshopType = Type.GetTypeFromProgID("Photoshop.Application");
        Photoshop.Application psApp = null;
        object obj = Activator.CreateInstance(photoshopType);
        if (photoshopType != null)
        {
            try
            {
                psApp = (Photoshop.Application)obj;
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.ToString());
                return null;
            }
        }
        return psApp;
    }

答案 1 :(得分:-1)

您必须关闭Visual Studio并通过右键单击并选择“以管理员身份运行”来启动它。

答案 2 :(得分:-2)

无论如何,我发现它不是Photoshop问题,而是.Net问题:

Using CreateInstance in Windows 10 Universal Apps

这个答案提出了一个解决方案,但我尚未尝试过:

InvalidCastException of a Activator.CreateInstance object during an installation procedure