[英]JIT Compiler encountered an internal limitation. C#, VS 2019
I'm starting learning C# and came up with this exception:我开始学习 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>
This exception happens when I try to get data from database using the stored procedure with a DateTime parameter passed in.当我尝试使用传入了 DateTime 参数的存储过程从数据库中获取数据时,会发生此异常。
Here is a full info which I get:这是我得到的完整信息:
<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>
Would appreciate any suggestions!将不胜感激任何建议!
The code is below代码如下
This part is calling the Stored Procedure and passing parameter:这部分是调用存储过程并传递参数:
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;
}
}
This is the part for sql connection and data load (using Dapper):这是 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;
}
}
}
This is the model of items I'm trying to get:这是我想要得到的项目的 model:
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; }
}
And here is a stored procedure:这是一个存储过程:
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
UPDATE 1 :更新 1 :
if I use a SP without parameters and LINQ-ed output - it all works fine:如果我使用没有参数的 SP 和 LINQ-ed output - 一切正常:
var output = sql.LoadData<FiveDaysEventsModel, dynamic>("dbo.spEvents_GetAll", new { }, "MFData");
//instead of
var output = sql.LoadData<FiveDaysEventsModel, DateTime>("dbo.spGetDatePlusFiveDaysEvents", date, "MFData");
and和
return output.Where(o => (o.Event_Date >= DateTime.Today && o.Event_Date <= DateTime.Today.AddDays(5))).ToList();
//instead of
return output;
using the SP:使用 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
But I don't want to load entire table each time...但我不想每次都加载整个表......
I suppose that there is a problem with DateTime conversion, any thoughts reg.我想 DateTime 转换存在问题,任何想法都可以。 where to look?
在哪里看?
Instead of passing the DateTime in as the parameter, pass it in as part of a dynamic object like so:与其将 DateTime 作为参数传递,不如将其作为动态 object 的一部分传递,如下所示:
var output = sql.LoadData<FiveDaysEventsModel, dynamic>("dbo.spGetDatePlusFiveDaysEvents", new { EventDate = date }, "MFData");
The problem you are encountering is because Dapper expects some type of set of parameters.您遇到的问题是因为 Dapper 需要某种类型的参数集。 It is fairly loose with the types of sets it can take, including lists and objects.
它可以采用的集合类型相当松散,包括列表和对象。 However, a struct like DateTime causes it issues.
但是,像 DateTime 这样的结构会导致它出现问题。 Instead of passing just one object through on its own, pass it through as part of an anonymous class object like I did where the property name corresponds to the parameter in your stored procedure and you will be fine.
不要像我一样只传递一个 object 通过它自己,而是将它作为匿名 class object 的一部分传递,其中属性名称对应于存储过程中的参数,你会没事的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.