In my store procedure I need to pass some ObjectParameter. (Basically they work as out put parameters). But when I try ti execute my code it show error.
System.InvalidOperationException: The parameter at index 3 in the parameters array is null.
Below is my controller code where I am executing the store procedure.
CPMVCEntities db = new CPMVCEntities(); int? result = db.AdminAuthenticate_USP(login.pvcUsername, login.pvcPassword,"",null,null,null,null,null,null,null).FirstOrDefault();
and below is the context.cs file code which EF creates automatically.
public virtual ObjectResult<Nullable<int>> AdminAuthenticate_USP(string pvcUsername, string pvcPassword, string pvcIpAddress, ObjectParameter pbintId, ObjectParameter pchAdminType, ObjectParameter pvcFirstName, ObjectParameter pvcLastName, ObjectParameter pvcEmail, ObjectParameter pbtStatus, ObjectParameter dtimeLastLogin)
{
var pvcUsernameParameter = pvcUsername != null ?
new ObjectParameter("pvcUsername", pvcUsername) :
new ObjectParameter("pvcUsername", typeof(string));
var pvcPasswordParameter = pvcPassword != null ?
new ObjectParameter("pvcPassword", pvcPassword) :
new ObjectParameter("pvcPassword", typeof(string));
var pvcIpAddressParameter = pvcIpAddress != null ?
new ObjectParameter("pvcIpAddress", pvcIpAddress) :
new ObjectParameter("pvcIpAddress", typeof(string));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<int>>("AdminAuthenticate_USP", pvcUsernameParameter, pvcPasswordParameter, pvcIpAddressParameter, pbintId, pchAdminType, pvcFirstName, pvcLastName, pvcEmail, pbtStatus, dtimeLastLogin);
}
The parameter at index 3 in the parameters array is null.
According to your description, the exception shows the parameter value is null and I think it represents that parameter value for pbintId is null. So there may be losing some settings in your store procedure.
So, I hope you could share your table construction and store procedure in your database.It will help us to reproduce your problem.
You can use optional parameters on a method signature. But on the other hand, you can't pass in a null value for a parameter object, becuase all that is going to do is blow up the program at the code that addresses any parameter object that is a null
valued object, which you have nulled-out most of the parameters you are passing into the method, and then you are trying to address the null valued parameters in the code.
Participant
1447 Points
2841 Posts
System.InvalidOperationException: The parameter at index 'n' in the parameters array is null
Apr 23, 2019 04:55 AM|demoninside9|LINK
Hi All,
I just started using EF 6.0.
In my store procedure I need to pass some ObjectParameter. (Basically they work as out put parameters). But when I try ti execute my code it show error.
System.InvalidOperationException: The parameter at index 3 in the parameters array is null.
Below is my controller code where I am executing the store procedure.
and below is the context.cs file code which EF creates automatically.
On this line (bold one) a get the error
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<int>>("AdminAuthenticate_USP", pvcUsernameParameter, pvcPasswordParameter, pvcIpAddressParameter, pbintId, pchAdminType, pvcFirstName, pvcLastName, pvcEmail, pbtStatus, dtimeLastLogin);
Please suggest.
Participant
1300 Points
522 Posts
Re: System.InvalidOperationException: The parameter at index 'n' in the parameters array is null
Apr 23, 2019 08:30 AM|Wei Zhang|LINK
Hi demoninside9,
According to your description, the exception shows the parameter value is null and I think it represents that parameter value for pbintId is null. So there may be losing some settings in your store procedure.
So, I hope you could share your table construction and store procedure in your database.It will help us to reproduce your problem.
Best Regards
Wei
Contributor
4973 Points
4262 Posts
Re: System.InvalidOperationException: The parameter at index 'n' in the parameters array is null
Apr 23, 2019 08:34 AM|DA924|LINK
You can use optional parameters on a method signature. But on the other hand, you can't pass in a null value for a parameter object, becuase all that is going to do is blow up the program at the code that addresses any parameter object that is a null valued object, which you have nulled-out most of the parameters you are passing into the method, and then you are trying to address the null valued parameters in the code.
https://www.c-sharpcorner.com/UploadFile/manas1/named-and-optional-parameter-in-C-Sharp/