System.ArgumentException: The table type parameter must have a valid type name System.ArgumentException: The table type parameter must have a valid type name asp.net asp.net

System.ArgumentException: The table type parameter must have a valid type name


Set mapping to your type in SqlServer using TypeName property that: Gets or sets the type name for a table-valued parameter, that has to fix .

p.TypeName = "dbo.MyType";

Check as well Table-Valued Parameters post


Note that this may also happen when you're executing a stored procedure and you don't have the SqlCommand.CommandType set to CommandType.StoredProcedure, as such:

using (SqlCommand cmd = new SqlCommand("StoredProcName", conn)){    cmd.CommandType = CommandType.StoredProcedure;    cmd.ExecuteNonQuery();}


You can get this error also when you wanna pass table params into stored procedure. There is happen if you use entity famework Context.Database.SqlQuery(). You must necessary set TypeName property for your table params.

SqlParameter codesParam = new SqlParameter(CODES_PARAM, SqlDbType.Structured);            SqlParameter factoriesParam = new SqlParameter(FACTORIES_PARAM, SqlDbType.Structured);            codesParam.Value = tbCodes;            codesParam.TypeName = "[dbo].[MES_CodesType]";            factoriesParam.Value = tbfactories;            factoriesParam.TypeName = "[dbo].[MES_FactoriesType]";            var list = _context.Database.SqlQuery<MESGoodsRemain>($"{SP_NAME} {CODES_PARAM}, {FACTORIES_PARAM}"                , new SqlParameter[] {                   codesParam,                   factoriesParam                }                ).ToList();