Mono + ASP.NET + MySQL: works, but always throws initial System.IO.FileNotFoundException for ‘MySql.Data’

I have built an ASP.NET web application on a Linux server running Apache and mod_mono with a MySQL database using the MySQL Connector/NET. Everything works splendidly… but only after an initial exception is thrown: if no requests have been made by anyone for this site for “awhile” (I’m unclear on the exact duration and cause of this, but some kind of hour-ish timeout seems to be at play), then a new request always results in:

Could not load file or assembly 'MySql.Data' or one of its dependencies
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): mscorlib.
Exception stack trace:
   at System.AppDomain.Load (assemblyString, assemblySecurity, refonly)
   at System.AppDomain.Load (assemblyString)
   at (wrapper remoting-invoke-with-check) System.AppDomain:Load (string)
   at System.Reflection.Assembly.Load (assemblyString)
   at System.Web.Compilation.BuildManager.LoadAssembly (info, al)
   at System.Web.Compilation.BuildManager.GetReferencedAssemblies ()
   at System.Web.Compilation.BuildManager.CallPreStartMethods ()

A simple browser reload/refresh or repeat request always succeeds, and thereafter everything works fine, even if the browser is closed and then a new session is started before “awhile” has elapsed, and even if a different user from a different location makes a request — everything always works after that initial single exception that is somehow “fixed” simply by making the request again.

Thoughts on causes/fixes for this annoyance? It doesn’t make for a nice first impression!


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The fact that the error only occurs on first try means that, eventually, the file (a DLL) is being found. The only instance of MySql.Data.dll is (was) in the GAC.

But ASP.NET web apps will also use DLLs in a /bin folder in the app’s root directory, so I created /bin and dropped a copy of MySql.Data.dll into it: problem solved! No more errors on startup.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x