locked
value does not fall within expected range

    Question

  • I am using a sample Metro style device app for printer from the windows 8.1 Samples collection(from  http://code.msdn.microsoft.com/windowsapps/Print-job-management-and-8245e020 ). I have successfully enumerated the device. But when I try to get the PrinterExtensionContaxt of the device, I am getting exception "Value does not fall within expected range". What could be wring?

    Object comComtext = Windows.Devices.Printers.Extensions.PrintExtensionContext.FromDeviceId(queue.DeviceId);

     Below is the full code:

    private void Printer_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                try
                {
                    // Remove the current printer queue view (if any) before displaying the new view.
                    if (currentPrinterQueueView != null)
                    {
                        currentPrinterQueueView.OnChanged -= OnPrinterQueueViewChanged;
                        currentPrinterQueueView = null;
                    }
    
                    // Retrieve a COM IPrinterExtensionContext object, using the static WinRT factory.
                    // Then instantiate one "PrinterExtensionContext" object that allows operations on the COM object.
                    PrinterInfo queue = (PrinterInfo)PrinterComboBox.SelectedItem;
                    Object comComtext = Windows.Devices.Printers.Extensions.PrintExtensionContext.FromDeviceId(queue.DeviceId);
                    PrinterExtensionContext context = new PrinterExtensionContext(comComtext);
    
                    // Display the printer queue view.
                    const int FirstPrintJobEnumerated = 0;
                    const int LastPrintJobEnumerated = 10;
    
                    currentPrinterQueueView = context.Queue.GetPrinterQueueView(FirstPrintJobEnumerated, LastPrintJobEnumerated);
                    currentPrinterQueueView.OnChanged += OnPrinterQueueViewChanged;
                }
                catch (Exception exception)
                {
                    rootPage.NotifyUser("Caught an exception: " + exception.Message, NotifyType.ErrorMessage);
                }
            }
    I am a bit stuck on this. Can someone please tell a way out?
    Monday, July 29, 2013 5:51 PM

All replies

  • I have a metro style device app to which I have associated a USB printer via meta data on Windows 8.1. This is based on the sample app http://code.msdn.microsoft.com/windowsapps/Print-job-management-and-8245e020 in Windows 8.1 Store app samples collection. I have enumerated the device. Now I need to access the print job queue from the app. When I try to get the printer extension context using PrintExtensionContext.FromDeviceId() by supplying the DeviceID it throws an exception "Value does not fall within the expected range" . What could be wrong here?
    Tuesday, July 23, 2013 1:10 PM
  • Hi,

         I'm not familiar with this area of development, so perhaps you can help me understand how to reproduce your problem.  I downloaded and installed the sample, and tried to enumerate the printers which were installed.  I didn't get any printers enumerated, although they are installed on my machine.  It said something about doing device metadata.  Was this necessary to make this sample work?  If you can give me more information to understand this code, I can work with the right dev team to try to resolve this.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, July 31, 2013 6:16 PM
    Moderator
  • Hi Matt,

      Thanks a lot for replying. Yes, the app will enumerate only printers  associated with the app via device meta data. ie. only printers  whose package family name is

    same as that of the package family name of the Device app. And that is what a Windows Store Device app for printer basically is. The below is how it will work:

    1. Create a sample Windows Store Device app( only device enumeration part is needed for now)

    2. Create device meta data for a v4 printers  using Device Metadata authoring wizard( %ProgramFiles(x86)%\Windows Kits\8.1\bin\x86\DeviceMetadataWizard.exe). During

    meta data data creation, specify the package name as the package name of the app created in Step1. Please follow the steps at http://msdn.microsoft.com/en-

    us/library/windows/hardware/dn265143(v=vs.85).aspx for meta data creation.


    When we create a Windows Store Device app and try to enumerate printers that are supposed to be associated with that app, then we will face two problems on Windows

    8.1.

    1. Device meta data for HP Printer Control Windows Store App automatically downloads and associates with our printer. So the package family name retrieved is that of

    HP Printer Control instead of our app. The printers  should associate with our app instead of HP Printer Control. Windows 8 did not have this issue.

    2. But even if explicitly set the package family name of the device as the package family name of our app, then we come across the problem that I mentioned in the

    original post("value out of range" issue when we try to get the printer extension context of the pronter

     Frankly, it is not sufficient to post code blocks. To check this one will have to create device meta data and also need to have a v4 printer. I think you can

    do the following steps in order to reproduce the issue:

    1. Download the sample Windows Store device app from the link I provided in my original post.
    2. Connect a v4 printer via USB. (To check if a printer supports v4 driver, connect the printer via usb, open Devices and Printers, select the printer, select Print

    Server properties from the ribbon above,Select drivers tab. v3/v4 support wll be displayed there)
    3. Create device meta data for the printer. During meta data creation , specify package name as the package name of the sample app downloaded
    3. Copy the created meta data to %programdata%Microsoft\Windows\DeviceMetadataStore\(locale) .
    4. Reboot the machine in test signing mode( from an elevated command prompt issue Bcdedit -set testsigining ON and reboot machine )
    5. Run the sample app. Click the Enumerate Devices button. If the meta data association is correct, the associated devices will be displayed.

    Thanks n Regards

    its_me_here


    • Edited by its_me_here Thursday, August 1, 2013 6:02 AM
    Thursday, August 1, 2013 6:01 AM
  • Sorry for the delay in response.  I am going to move this to the Developing Store apps for Hardware forum as this area of development will be more familiar to those guys on that forum.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, August 29, 2013 12:46 PM
    Moderator