Security Exception using MySQL and Entity Framework on godaddy

后端 未结 3 1186
遥遥无期
遥遥无期 2020-12-11 13:23

We are getting a SecurityException when using Entity framework on godaddy. The entity has been configured against a MySQL store. (v. 6.1.2) A bit of weirdnes

3条回答
  •  借酒劲吻你
    2020-12-11 14:17

    Weird one. GoDaddy shared-hosting ASP.NET apps execute under Medium Trust, and perf counter creation probably requires full trust, but perf counter creation is not what's failing here. (and if it failed, it wouldn't propagate out since perf coutner creation exceptions are swallowed by mySQL client code).

    Instead, it's failing trying to access a string resource, before perf counter creation. The failure is with this line of code in Resources.Designer.cs of the MySQL client:

    return ResourceManager.GetString("PerfMonCategoryName", resourceCulture)
    

    A few things to try, in increasing order of difficulty:

    1. ensure you have the MySQL client DLLs in your app's BIN directory and you're not trying to load the client DLL out of GoDaddy's GAC. Never depend on GoDaddy-supplied binaries if you can avoid it!

    2. switch to EN-US culture so the client doesn't have to go hunting for another resource DLL, and see if the problem goes away.

    3. Build the .NET client from source code, instead of copying DLLs from a binary distribution into your app's BIN directory. This will make problems like this easier to debug since the mySQL code won't be a black box. And, in a pinch, will let you change the problematic resource-fetching calls (or hard-code the locale)! :-)

    BTW, in case you're tempted to set "Use Performance Monitor=false" in your connection string to try to evade the problem, don't bother. The problematic code gets executed regardless of that setting:

        public PerformanceMonitor(MySqlConnection connection)
        {
            this.connection = connection;
    
            //// this line is where it bombs
            string categoryName = Resources.PerfMonCategoryName;
    
            //// this line is affected by connection string setting
            if (connection.Settings.UsePerformanceMonitor && procedureHardQueries == null)
            {
                try
                {
                    procedureHardQueries = new PerformanceCounter(categoryName,
                                                                  "HardProcedureQueries", false);
                    procedureSoftQueries = new PerformanceCounter(categoryName,
                                                                  "SoftProcedureQueries", false);
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
            }
        }
    

提交回复
热议问题