I am receiving a null reference exception when trying to access the "Available" property of IValueRequest, but only if the Request ID is "QuickPrompt".
What is the best way to work around this?
IValueRequest - null reference exception
Moderator: Phil Barton
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: IValueRequest - null reference exception
Please include a code snippet. I'm not sure what an "IValueRequest" object is.
Bob Richards, Senior Software Developer, SoftPro
-
- Posts: 73
- Joined: Thu May 21, 2015 2:28 pm
Re: IValueRequest - null reference exception
IValueRequest is in SoftPro.Documents.Client.Rendering
Code: Select all
public class TestPrompts : IPrompt<PromptEventArgs>
{
public TestPrompts(){}
public void Request(PromptEventArgs value)
{
foreach (IRequest prompt in value.Requests)
{
var selectionReq = prompt as ISelectionRequest;
if (selectionReq != null)
{
// logic for handling a selection request
selectionReq.Handled = true;
}
var valueReq = prompt as IValueRequest;
if (valueReq != null)
{
// logic for handling a value request
var availableValues = valueReq.Available; // When valueReq.ID == "QuickPrompt", this line throws a null reference exception
valueReq.Handled = true;
}
}
}
}
-
- Posts: 1377
- Joined: Wed Jan 15, 2014 3:50 pm
- Location: Raleigh, NC
- Contact:
Re: IValueRequest - null reference exception
You need to know ahead of time the requirements of the document you are trying to render including the request IDs (IRequest.ID). You should not access the request unless the request corresponds to an ID you are expecting. The interface is designed to render documents when you know the appropriate responses.
Do you have a question regarding a specific one? If you are just looking to see what's there, a try/catch around the offending line sounds like a option - but not in production code!
Do you have a question regarding a specific one? If you are just looking to see what's there, a try/catch around the offending line sounds like a option - but not in production code!
Bob Richards, Senior Software Developer, SoftPro