Home

Odd issue after latest windows updates (Windows 7)

I have a LINQPad Program I use to do some queries against databases in different environments (Dev, Qa, Staging, Prod) and don't use the built in database connection mechanism in LINQPad. Instead I edit the file and choose an environment and then the script pulls the necessary configuration info out based on that selection, opens a SqlConnection to the selected environment database and then uses Dapper to query the database and do other things.

I went through and recreated the problem in a much simpler script that you can find here:
http://share.linqpad.net/2eqjjw.linq

It gives me an Exception:
The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.

Inner Exception is:
Type 'UserQuery+NoEncryptionCrypto' in assembly 'LINQPadQuery, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

The strange part is that you can fix it by simply choosing any saved db connection in LINQPad and choosing any database from the dropdown.

You can also resolve the problem by comenting out line 4 where I save an object in the CallContext.

Several co-workers use this script on Windows 10 and don't have the issue I have started seeing.

Comments

  • Maybe SqlConnection's static constructor is enumerating call context variables and requires them to be serializable. You can work around this by doing something to SqlConnection at the start of your query, e.g.:

    new SqlConnection();

    If it has already faulted, you will need to clear the existing process first (Shift+Ctrl+F5).
  • That does work but I don't fully understand why. It always worked fine before. You think something changed recently in the Framework to do this?
Sign In or Register to comment.