Я начинаю изучать C # и придумала это исключение:
System.InvalidProgramException
HResult=0x8013153A
Message=JIT Compiler encountered an internal limitation.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
Это исключение происходит, когда я пытаюсь получить данные из базы данных, используя хранимую процедуру с переданным параметром DateTime.
Вот полная информация, которую я получаю:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>JIT Compiler encountered an internal limitation.</ExceptionMessage>
<ExceptionType>System.InvalidProgramException</ExceptionType>
<StackTrace>
at ParamInfoe2776a66-00bd-4ad7-a77a-368cc977a638(IDbCommand , Object ) at Dapper.CommandDefinition.SetupCommand(IDbConnection cnn, Action`2 paramReader) in C:\projects\dapper\Dapper\CommandDefinition.cs:line 128 at Dapper.SqlMapper.<QueryImpl>d__140`1.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.cs:line 1073 at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 721 at MFDataManager.Library.Internal.SqlDataAccess.LoadData[T,U](String storedProcedure, U parameters, String connectionStringName) in D:\MICE_forecast\MICE_forecast\MICE_Forecast\MFDataManagerLibrary\Internal\SqlDataAccess.cs:line 27 at MFDataManagerLibrary.DataAccess.FiveDaysEventsData.getFiveDaysEvents() in D:\MICE_forecast\MICE_forecast\MICE_Forecast\MFDataManagerLibrary\DataAccess\FiveDaysEventsData.cs:line 21 at MFDataManager.Controllers.FiveDaysEventsController.Get() in D:\MICE_forecast\MICE_forecast\MICE_Forecast\MFDataManager\Controllers\FiveDaysEventsController.cs:line 19 at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()
</StackTrace>
</Error>
Буду признателен за любые предложения!
Код ниже
Эта часть вызывает хранимую процедуру ипередаваемый параметр:
public class FiveDaysEventsData
{
public List <FiveDaysEventsModel> getFiveDaysEvents()
{
SqlDataAccess sql = new SqlDataAccess();
//stuff for testing:
DateTime date = new DateTime(2019, 11, 10);
var output = sql.LoadData<FiveDaysEventsModel, DateTime>("dbo.spGetDatePlusFiveDaysEvents", date, "MFData");
return output;
}
}
Это часть для подключения SQL и загрузки данных (с помощью Dapper):
internal class SqlDataAccess
{
public string GetConnectionString(string name)
{
return ConfigurationManager.ConnectionStrings[name].ConnectionString;
}
public List<T> LoadData<T, U>(string storedProcedure, U parameters, string connectionStringName)
{
string connectionString = GetConnectionString(connectionStringName);
using (IDbConnection connection = new SqlConnection (connectionString))
{
List<T> rows = connection.Query<T>(storedProcedure, parameters,
commandType: CommandType.StoredProcedure).ToList();
return rows;
}
}
}
Это модель элементов, которые я пытаюсь получить:
public class FiveDaysEventsModel
{
public DateTime Event_Date { get; set; }
public string CompanyName { get; set; }
public string Booked_for { get; set; }
public TimeSpan Time_From { get; set; }
public TimeSpan Time_To { get; set; }
public string LocationName { get; set; }
public string ContactName { get; set; }
public string PhoneNumber { get; set; }
public string EventStatus { get; set; }
public int EventID { get; set; }
}
И вот хранимая процедура:
CREATE PROCEDURE [dbo].[spGetDatePlusFiveDaysEvents]
@EventDate Datetime2
AS
BEGIN
set nocount on;
SELECT
ed.Event_Date, c.[Name] as CompanyName, ed.Booked_for,
ed.Time_From, ed.Time_To, loc.[Name] as LocationName, cnt.[Name] as ContactName,
cnt.PhoneNumber, ed.[Status] as EventStatus, ed.ID as EventID
FROM
dbo.[EventData] ed,
dbo.Company c,
dbo.Contact cnt,
dbo.[Location] loc
WHERE
(ed.Event_Date>= @EventDate and ed.Event_Date<= DATEADD(day, 5, @EventDate)) and
c.ID = ed.Company_ID and ed.ContactID = cnt.ID;
End
ОБНОВЛЕНИЕ 1 :
, если я использую SP без параметров и LINQ-edвывод - все работает нормально:
var output = sql.LoadData<FiveDaysEventsModel, dynamic>("dbo.spEvents_GetAll", new { }, "MFData");
//instead of
var output = sql.LoadData<FiveDaysEventsModel, DateTime>("dbo.spGetDatePlusFiveDaysEvents", date, "MFData");
и
return output.Where(o => (o.Event_Date >= DateTime.Today && o.Event_Date <= DateTime.Today.AddDays(5))).ToList();
//instead of
return output;
с использованием SP:
CREATE PROCEDURE [dbo].[spEvents_GetAll]
AS
BEGIN
set nocount on;
SELECT
ed.Event_Date, c.[Name] as CompanyName, ed.Booked_for, ed.Time_From, ed.Time_To, loc.[Name] as LocationName, cnt.[Name] as ContactName,
cnt.PhoneNumber, ed.[Status] as [Status], ed.ID
FROM
dbo.[EventData] ed,
dbo.Company c,
dbo.Contact cnt,
dbo.[Location] loc
WHERE
ed.Company_ID = c.ID and
ed.ContactID = cnt.ID and
ed.LocationID = loc.ID
END
Но я не хочу загружать всю таблицу каждыйвремя ...
Я полагаю, что есть проблема с преобразованием DateTime, любые мысли рег. где искать?