SqlText threw an exception of type 'System.TypeInitializationException'
See original GitHub issueHello
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
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (12 by maintainers)
Top Results From Across the Web
c# - System.TypeInitializationException when application ...
When a class initializer fails to initialize a type, a TypeInitializationException is created and passed a reference to the exception thrown ...
Read more >Execution of CLR fails with TypeInitializationException
TypeInitializationException : The type initializer for 'Scope' threw an exception. ---> System.IO.FileNotFoundException: Could not load file ...
Read more >[RESOLVED] TypeInitializationException thrown using an ...
I was adding a bunch of code and didnt commit frequently and now I have a runtime error bug. :( An unhandled exception...
Read more >How do I resolve "typeinitializationexception wa unhandled ...
Solution 1 ; TypeInitializationException Class (System) | Microsoft Docs · ] Few more threads on same error message. Check & fix it by...
Read more >MySQL connection throwing exception : r/csharp
System.TypeInitializationException: 'The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.'.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
yep, it’s quite straightforward fix. Just replace all uses of ConcurrentBag with better collection