13 Replies - 2079 Views - Last Post: 28 November 2011 - 02:21 PM Rate Topic: -----

#1 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 07:42 AM

I am using PRNADMINLib to install a print driver, create a port and install the printer

PRNADMINLib.PrintMaster printMaster = new PRNADMINLib.PrintMaster();

PRNADMINLib.Driver driver = new PRNADMINLib.Driver();
driver.ModelName = driverName;
driver.InfFile = infName;

   printMaster.DriverAdd(driver);

PRNADMINLib.Port port = new PRNADMINLib.Port();
port.PortName = ipAddress;
port.HostAddress = ipAddress;
port.PortNumber = 515;
port.PortType = 2;
port.QueueName = "print";
port.CommunityName = "public";
port.SNMP = 1;
port.SnmpDeviceIndex = 1;
printMaster.PortAdd(port);

PRNADMINLib.Printer printer = new PRNADMINLib.Printer();
printer.PortName = ipAddress;
printer.DriverName = driverName;
printer.PrinterName = printerName;
printMaster.PrinterAdd(printer);



When it gets to "printMaster.DriverAdd(driver);" it gives me the error:

System.ArgumentException was unhandled
Message=Value does not fall within the expected range.
Source=InstallPrinter
StackTrace:
at PRNADMINLib.IPrintMaster.DriverAdd(Driver pDriver)
at InstallPrinter.Form1.AddPrinter(String ipAddress, String printerName, String driverName, String infPath, String infName) in Form1.cs:line 79
at InstallPrinter.Form1.AddPrinterStart() in Form1.cs:line 64
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Is This A Good Question/Topic? 0
  • +

Replies To: Add Printer Driver "Value does not fall within the expected range.

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5633
  • View blog
  • Posts: 12,086
  • Joined: 02-June 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 07:54 AM

That's a statement of what's happening.
Did you have a question we can help you with?

See FAQ #5 for debugging tutorials


FAQ (Frequently Asked Questions - Updated Oct 2011

Spoiler


Since the line is given to you, it should be a simple matter to check the values of those variables. All you have to do is hover your mouse over the variables and the values will be shown to you.

Attached Image

This post has been edited by tlhIn`toq: 23 November 2011 - 07:56 AM

Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5633
  • View blog
  • Posts: 12,086
  • Joined: 02-June 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 08:00 AM

Since it was expecting a value based on the error, and you provided an object that's probably a clue.

Looking at the error:

Quote

StackTrace:
at PRNADMINLib.IPrintMaster.DriverAdd(Driver pDriver)


Look at what it was expecting: pDriver. That's common notation for a pointer. Which would be a value. To me it looks like it was expecting a memory address of where the driver object is located.

But to be clear, I've never used the library you're talking about. I'm basing that assumption on the error and code you provided.

This post has been edited by tlhIn`toq: 23 November 2011 - 08:03 AM

Was This Post Helpful? 0
  • +
  • -

#4 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 08:29 AM

View PosttlhIn`toq, on 23 November 2011 - 09:00 AM, said:

Since it was expecting a value based on the error, and you provided an object that's probably a clue.

Looking at the error:

Quote

StackTrace:
at PRNADMINLib.IPrintMaster.DriverAdd(Driver pDriver)


Look at what it was expecting: pDriver. That's common notation for a pointer. Which would be a value. To me it looks like it was expecting a memory address of where the driver object is located.


I'm pretty sure pDriver stands for "printer driver." If they wanted me to send a pointer, first of all the program wouldn't have compiled, and secondly they would've documented it like this:
PRNADMINLib.IPrintMaster.DriverAdd(ref Driver pDriver)


Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5633
  • View blog
  • Posts: 12,086
  • Joined: 02-June 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 08:53 AM

If the documentation is telling you to send it a ref, then why aren't you?

07 printMaster.DriverAdd(driver);


And a reference (ref) by its very nature is a pointer. Just FYI

This post has been edited by tlhIn`toq: 23 November 2011 - 08:56 AM

Was This Post Helpful? 0
  • +
  • -

#6 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 09:26 AM

View PosttlhIn`toq, on 23 November 2011 - 09:53 AM, said:

If the documentation is telling you to send it a ref, then why aren't you?


The reason I'm not sending the driver by reference is because the documentation is not telling me to.

The driver object is not the issue. Most likely it is one of the properties of the object. The problem is that I cannot find any documentation on PRNADMINLib. So I don't know which "Value" is out of what "Range."

This is why error handling and documentation, albeit tedious and time consuming, is so important.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5633
  • View blog
  • Posts: 12,086
  • Joined: 02-June 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 10:49 AM

My mistake. I misread your statement #4 about the documentation.

You feel confident that pDriver stands for printer driver and not pointer. But then you say you can't find any documentation. So you're just guessing at that then?

Have you actually tried sending it a pointer to your driver object? It won't cost you anything to try.

I'm pretty comfortable with such notation from libraries.

pDriver would be a pointer
szDriver would be a string
nDriver would be an integer
fDriver would be a float

and so on.

Its called Hungarian notation and has been used by programmers for years. Some consider it out of date, but I like it because it lets you know what the data type expected is in situations exactly like this one.

http://web.mst.edu/~.../hungarian.html
Was This Post Helpful? 0
  • +
  • -

#8 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 01:48 PM

I tried sending a pointer and visual studios won't compile it cause its not the right type.
Was This Post Helpful? 1
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,614
  • Joined: 23-August 08

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 03:43 PM

What are the values of these variables?

driver.ModelName = driverName;
driver.InfFile = infName;

Was This Post Helpful? 1
  • +
  • -

#10 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 04:11 PM

View PostJackOfAllTrades, on 23 November 2011 - 04:43 PM, said:

What are the values of these variables?

driver.ModelName = driverName;
driver.InfFile = infName;


driverName = "test printer";
infName = "c:\\path to driver folder\\infname.inf";

I have tried changing these to everything I could think of and it still gives the same error
Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,614
  • Joined: 23-August 08

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 04:12 PM

I wonder if there's actually a value in the printer driver's .INF file that it doesn't like?

EDIT: Is it also possible there's some sort of 32-bit/64-bit issue going on?
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5633
  • View blog
  • Posts: 12,086
  • Joined: 02-June 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 04:18 PM

driverName = "test printer"
driver.ModelName = driverName

Therefore the driver.ModelName = "test printer"

Maybe you need to actually match the proper model name of the printer in question. Perhaps the driver only has options for a given family of printers: ModelABC, Model123, ModelABCpro

When it tries to find a set of instructions for which files to install for a model "test printer" it can't; therefore the value is invalid.

Just a thought.
Was This Post Helpful? 1
  • +
  • -

#13 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,614
  • Joined: 23-August 08

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 23 November 2011 - 04:21 PM

Yeah, I'm just throwing stuff out there. Never did anything with printers or printer drivers previously. Unfortunately this is a pretty generic error, and therefore tough to debug.

Might try over at the MSDN forums if none of our suggestions end up being helpful.
Was This Post Helpful? 0
  • +
  • -

#14 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Re: Add Printer Driver "Value does not fall within the expected range.

Posted 28 November 2011 - 02:21 PM

View PosttlhIn`toq, on 23 November 2011 - 05:18 PM, said:

driverName = "test printer"
driver.ModelName = driverName

Therefore the driver.ModelName = "test printer"

Maybe you need to actually match the proper model name of the printer in question. Perhaps the driver only has options for a given family of printers: ModelABC, Model123, ModelABCpro

When it tries to find a set of instructions for which files to install for a model "test printer" it can't; therefore the value is invalid.

Just a thought.



That was the problem. In the inf file it specifies the model name and the ModelName attribute must be the same what is in the inf file.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1