locked
.net 3.5/4 PrintServer creation works in Visual Studio (Express) but not stand alone RRS feed

  • Question

  • The following code works without issue from inside Visual Studio (professional or express editions) but when this console app is run from the command line it returns: Win32 Error: The RPC Server is unavailable.

    The variations on PrintServer and LocalPrintServer produce the same results.  It's also disappointing that sample code provided at http://msdn.microsoft.com/en-us/library/aa970845(v=VS.100).aspx doesn't work (which is the base of this code)

    Prior to installing .net 3.5 framework sdk, I had the same errors as found in this article: http://connect.microsoft.com/VisualStudio/feedback/details/552520/methodaccessexception-when-printqueuecollection-disposed# with PrintServer (as opposed to LocalPrintServer) but the work around of using .net 3.5 didn't solve the problem, just made all the errors of the RPC flavour.  All the obvious things, like ensuring the RPC server is up and running automatically, firewalls turned off (instead of just adding the application - that fails too), and so on don't help any.

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Printing;

    namespace PrinterStatusCSharp
    {
        class Program
        {
           static void Main(string[] args)
            {
                Console.WriteLine("Printer issues listed below:");
                String statusReport = "\n";

                //LocalPrintServer ps = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
                LocalPrintServer ps = new LocalPrintServer();
                PrintQueue pq = ps.DefaultPrintQueue;

                //PrintServer ps = new PrintServer();
                //PrintServer ps = new PrintServer(PrintSystemDesiredAccess.AdministrateServer);
                //PrintQueue pq = ps.GetPrintQueue("6490CW");

                pq.Refresh();

                if (pq.IsPaused)
                    statusReport = statusReport + "Is paused. ";

                //fileOfPrintServers.Close();
                Console.WriteLine(statusReport);
                Console.WriteLine("\nPress Return to continue.");
                Console.ReadLine();
            }
        }
    }

     

     

      

     

    • Moved by CoolDadTx Monday, April 4, 2011 1:39 PM Winforms related (From:Visual C# IDE)
    • Moved by Helen Zhou Wednesday, April 27, 2011 8:56 AM (From:Windows Forms General)
    Monday, April 4, 2011 11:45 AM

Answers

All replies

  • Hi Shawn,

    That works all right on both situations (Windows 7, 32 bit) : run in VS and in command. What's your operation system?

    I guess there some security issue that prevent you from running it in command. I'll do some research and keep you updated.

    Sincerely,


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Helen Zhou Monday, April 11, 2011 6:01 AM
    Wednesday, April 6, 2011 9:13 AM
  • Digging around on the old internet suggests this is a 32 v 64bit platform issue for RPC and RPC on 64bit is the failure point. 

    this code runs within a (32bit) bash environment (minigw) and in 'troubleshoot compatibility' (right click on the executable) once set to XP, but frustratingly despite being set to XP compatibility still fails with an RPC problem run from the (64bit) windows cmd prompt or from the explorer.

    RPC vs 64bit seems to be an old problem from the beginning of VISTA days, and years later, doesn't appear to have been completely resolved. 

    Any hints on how to force a 32bit execution enviroment on a 64bit host, apart from having to install *nix tools, would be greatly appreciated.

    Friday, April 8, 2011 9:39 AM
  • Never mind - make sure to build for x64 and recofigure the defaults from x86.

     

    Friday, April 8, 2011 9:45 AM
  • Hi Shawn,

    If you have anyother question about "how to force a 32bit execution enviroment on a 64bit host, apart from having to install *nix tools", you'd better create a thread for the benefit of the forum members that help us to trace the issue more effectively.

    Thank you!


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 11, 2011 6:09 AM
  • Hi Shawn,

    The following is my test environment, and I have not found any error message in my locale side, so can you show us a screen shot when you're shown the error message? And please show us your environment, it is important to let peoples help you research the root cause, if you have not found the root cause, otherwise please mark the replies as answer so that the others will clear about this question.

     

    windows 7 64bit, x64 cpu,

    target platform:

    x86-> no error occurs

    x64-> no error occurs

    any cpu -> no error occurs

     

    you can upload your screenshot to the sky driver, and then show us the download link, or just past it to your new post.

    The way for posting an image:
    You can upload the image into your windows live space, then open this image in your space, select this image and copy it into the reply textbox, and then you can submit an image in your post.(Or past the image link in the reply)

    And I don't know why you said the application can run fine in vs, but would failed when you double click on the application. The application bit are the same.

     

     

     


    HI_0_HI

    Tuesday, April 12, 2011 5:33 AM
  • Hi Shawn,

    This is not a UI issue, so to help you to get better response, I'm moving it to the Where is the forum for to see if someone is expert and intersted in this question.


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 27, 2011 8:56 AM
  • Ask in one of these forums: http://social.msdn.microsoft.com/Forums/en-US/category/netdevelopment

    Thanks!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    Friday, October 12, 2012 10:25 PM