linq2db: SqlText threw an exception of type 'System.TypeInitializationException'
Hello
I’m using this simple statement to select some records from my db.
public static List<Rate> Get(TradingDB db, string id, ENUM_TIMEFRAME timeframe, DateTime fromDate)
{
try
{
var query = from row in db.Rates
where row.MarketId == id && row.Timeframe == timeframe.ToString() && row.TimeframeDate >= fromDate
orderby row.TimeframeDate descending
select row;
return query.ToList();
}
catch (Exception e)
{
Logger.Print(ENUM_LOGGER.LOGGER_SQL, Helper.GetMethod(MethodBase.GetCurrentMethod()), e.Message);
return new List<Rate>();
}
}
This statement have been working for month, but since some weeks?? it’s not working anylonger.
IMO there is something wrong with the datetime
Exception message: '((LinqToDB.Linq.ExpressionQuery<DataModels.Rate>)query).SqlText' threw an exception of type 'System.TypeInitializationException' | string {System.TypeInitializationException}
Stack trace: bei LinqToDB.Linq.Query`1.GetQuery(IDataContext dataContext, Expression& expr) in C:\projects\linq2db\Source\LinqToDB\Linq\Query.cs:Zeile 219.
bei LinqToDB.Linq.ExpressionQuery`1.GetQuery(Expression& expression, Boolean cache) in C:\projects\linq2db\Source\LinqToDB\Linq\ExpressionQuery.cs:Zeile 84.
bei LinqToDB.Linq.ExpressionQuery`1.get_SqlText() in C:\projects\linq2db\Source\LinqToDB\Linq\ExpressionQuery.cs:Zeile 53.
Steps to reproduce
[Table(Schema="dbo", Name="rates")]
public partial class Rate
{
[Column("market_id"), PrimaryKey(1), NotNull] public string MarketId { get; set; } // nvarchar(80)
[Column("timeframe"), PrimaryKey(2), NotNull] public string Timeframe { get; set; } // nvarchar(13)
[Column("timeframe_date"), PrimaryKey(3), NotNull] public DateTime TimeframeDate { get; set; } // smalldatetime
[Column("open_time"), NotNull] public DateTime OpenTime { get; set; } // smalldatetime
[Column("open_price"), NotNull] public decimal OpenPrice { get; set; } // numeric(18, 8)
[Column("high_time"), NotNull] public DateTime HighTime { get; set; } // smalldatetime
[Column("high_price"), NotNull] public decimal HighPrice { get; set; } // numeric(18, 8)
[Column("low_time"), NotNull] public DateTime LowTime { get; set; } // smalldatetime
[Column("low_price"), NotNull] public decimal LowPrice { get; set; } // numeric(18, 8)
[Column("close_time"), NotNull] public DateTime CloseTime { get; set; } // smalldatetime
[Column("close_price"), NotNull] public decimal ClosePrice { get; set; } // numeric(18, 8)
}
public static List<Rate> Get(TradingDB db, string id, ENUM_TIMEFRAME timeframe, DateTime fromDate)
{
try
{
var query = from row in db.Rates
where row.MarketId == id && row.Timeframe == timeframe.ToString() && row.TimeframeDate >= fromDate
orderby row.TimeframeDate descending
select row;
return query.ToList();
}
catch (Exception e)
{
return new List<Rate>();
}
}
Thank you
Environment details
linq2db version: 2.7.4 Database Server: Windows Server 2016 Database Provider: MS Sql 2017 Operating system: Windows Server 2016 / Windows 10 .NET Framework: .NET Framework 4.7.2
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 20 (12 by maintainers)
Ok finally I found a workaround. I’ve installed VS2017 and VS2019 on my pc. When I’m using VS19, I get the error message. When I switch back to VS17 it works properly. So I seems to be a flag/bug, which is quite new, in VS 2019.
Thank you for your really great support. I really enjoy using your library! fantastic product