请求的Windows运行时类型“PrintService.PDFPrinting”未注册

时间:2016-08-30 05:40:47

标签: c# windows-runtime uwp windows-10-universal

我正在尝试使用this为UWP应用程序开发代理的WinRT静音PDF打印服务。

我已经按照有关如何创建代理WinRT组件的所有步骤进行操作。但是当我在UWP应用程序上调用该服务时,我收到以下错误:

  

请求的Windows运行时类型'PrintService.PDFPrinting'不是   注册

我的代理组件类:

public sealed class PDFPrinting
{
    public Boolean PrintPDFs(string pdfFileName)
    {
        try
        {
            Process proc = new Process();
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.Verb = "print";

            //Define location of adobe reader/command line
            //switches to launch adobe in "print" mode
            proc.StartInfo.FileName =
              @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
            proc.StartInfo.Arguments = String.Format(@"/p /h {0}", pdfFileName);
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = true;

            proc.Start();
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            if (proc.HasExited == false)
            {
                proc.WaitForExit(10000);
            }

            proc.EnableRaisingEvents = true;

            proc.Close();
            return true;
        }
        catch
        {
            return false;
        }
    }
}

我如何称呼它:

var path = @"C:\Users\...\mydocument.pdf";
var service = new PrintService.PDFPrinting();
service.PrintPDFs(path);

我的延伸:

<Extension Category="windows.activatableClass.inProcessServer">
<InProcessServer>
  <Path>clrhost.dll</Path>
  <ActivatableClass ActivatableClassId="PrintService.PDFPrinting" ThreadingModel="MTA">
    <ActivatableClassAttribute Name="DesktopApplicationPath" Type="string" Value="C:\Development\MyApp" />
  </ActivatableClass>
</InProcessServer>
</Extension>

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,我在UWP Package.appxmanifest扩展中的值路径是错误的。

我引用了:

<ActivatableClassAttribute Name="DesktopApplicationPath" Type="string" Value="C:\Development\MyApp" />

而不是:

<ActivatableClassAttribute Name="DesktopApplicationPath" Type="string" Value="C:\Development\MyApp\MyApp\Debug" />

所有相关支持文件和代理/存根dll所在的位置。 找到的详细信息here