Search code examples
mysqlasp.netmono

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:

System.IO.FileNotFoundException
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!


Solution

  • 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.