0

SecurityException我们在 godaddy 上使用实体框架时得到了一个。该实体已针对 MySQL 存储进行配置。(v. 6.1.2)虽然异常有点奇怪......查看异常堆栈似乎意味着如果我们在站点的任何位置打开与 MySQL 的连接,那么我们应该得到相同的异常;但是,直接打开 MySQL 连接似乎在站点的另一部分工作......

这是验证:

using (MySqlConnection connection = new MySqlConnection(ConnectionString))
{
  connection.Open();
  ...
}

有人遇到类似的问题吗?

完整的错误堆栈跟踪如下:

[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Reflection.MethodBase.PerformSecurityCheck(Object obj, RuntimeMethodHandle method, IntPtr parent, UInt32 invocationFlags) +0
   System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +470
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
   System.Resources.ResourceManager.CreateResourceSet(Stream store, Assembly assembly) +357
   System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) +471
   System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) +583
   System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) +583
   System.Resources.ResourceManager.GetString(String name, CultureInfo culture) +74
   MySql.Data.MySqlClient.Resources.get_PerfMonCategoryName() +40
   MySql.Data.MySqlClient.PerformanceMonitor..ctor(MySqlConnection connection) +43
   MySql.Data.MySqlClient.MySqlConnection.Open() +434
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +173
   System.Data.EntityClient.EntityConnection.Open() +96
   System.Data.Objects.ObjectContext.EnsureConnection() +81
   System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +46
   System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +44
   jet.Controllers.WorkOrder.WorkOrderView..ctor() +219
   jet.Controllers.WorkOrder.WorkOrderView.get_Instance() +29
   jet.Controllers.WorkItemController.Index() +11
   lambda_method(ExecutionScope , ControllerBase , Object[] ) +39
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
   System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +53
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
   System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +20
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +382
   System.Web.Mvc.Controller.ExecuteCore() +123
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
4

3 回答 3

3

奇怪的一个。GoDaddy 共享托管 ASP.NET 应用程序在中等信任下执行,并且创建性能计数器可能需要完全信任,但创建性能计数器并不是这里失败的原因。(如果它失败了,它不会传播出去,因为 perf coutner 创建异常被 mySQL 客户端代码吞没了)。

相反,它在创建 perf 计数器之前尝试访问字符串资源失败。失败在于 MySQL 客户端的 Resources.Designer.cs 中的这行代码:

return ResourceManager.GetString("PerfMonCategoryName", resourceCulture)

一些事情要尝试,按照难度递增的顺序:

  1. 确保您的应用程序的 BIN 目录中有 MySQL 客户端 DLL,并且您没有尝试从 GoDaddy 的 GAC 中加载客户端 DLL。如果可以避免的话,永远不要依赖 GoDaddy 提供的二进制文件!

  2. 切换到 EN-US 文化,这样客户就不必去寻找另一个资源 DLL,看看问题是否消失了。

  3. 从源代码构建 .NET 客户端,而不是将 DLL 从二进制分发版复制到应用程序的 BIN 目录中。这将使此类问题更易于调试,因为 mySQL 代码不会是黑盒。而且,在紧要关头,将让您更改有问题的资源获取调用(或硬编码语言环境)!:-)

顺便说一句,如果您想在连接字符串中设置“Use Performance Monitor=false”以试图规避问题,请不要打扰。无论该设置如何,都会执行有问题的代码:

    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);
            }
        }
    }
于 2009-09-29T21:44:55.317 回答
2

贾斯汀是当场的。问题是godaddy 在他们的gac 中有一个旧版本的MySql dll 并且实体框架正在拾取它!

这是修复。(将此应用于 web.config)

<configuration>
  ...
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d"/>
        <bindingRedirect oldVersion="5.0.7.0" newVersion="6.1.2.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  ...
</configuration>
于 2009-10-03T16:20:18.023 回答
1

我只是在我的 Web 配置文件中添加了 trust level="Full",它就可以工作了

于 2013-11-13T11:33:18.543 回答