Trust level problem?

Discussion in 'General troubleshooting' started by Infidelux, Feb 2, 2013.

  1. I'm testing a new app that is using Ninject for dependency injection. I am getting this security error when it tries to initialize:
    Code:
    [SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
       System.AppDomain.get_Evidence() +24
       Ninject.Modules.AssemblyNameRetriever.CreateTemporaryAppDomain() +18
       Ninject.Modules.AssemblyNameRetriever.GetAssemblyNames(IEnumerable`1 filenames, Predicate`1 filter) +44
       Ninject.Modules.CompiledModuleLoaderPlugin.LoadModules(IEnumerable`1 filenames) +87
       Ninject.Modules.ModuleLoader.LoadModules(IEnumerable`1 patterns) +370
       Ninject.KernelBase.Load(IEnumerable`1 filePatterns) +40
       Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules) +359
       Ninject.KernelBase..ctor(INinjectModule[] modules) +92
       GW2FALFG.Web.App_Start.NinjectWebCommon.CreateKernel() +38
       Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) +16
       GW2FALFG.Web.App_Start.NinjectWebCommon.Start() +103
    
    My guess is that the site is defaulted in a lower trust level unless I request it be elevated so that it has appropriate permissions to handle my dependencies. Can one of you folks confirm this and I'll submit the request needed.
     
  2. ComputerMan

    ComputerMan Winhost Staff

    Last edited by a moderator: Oct 14, 2015
  3. That fixed one problem and opened another. So now Ninject loads properly but I get this in its place..
    Code:
    [FileLoadException: Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
    
    [FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
       System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
       System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
       System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
       System.Reflection.Assembly.Load(String assemblyString) +28
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
    
    [ConfigurationErrorsException: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
       System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
       System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
       System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
       System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
       System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +258
       System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
    
    [HttpException (0x80004005): Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
    
    I was getting this same error for the Entity Framework dll so I did a rebuild and deleted the app from the server and republished and now I get the same message but for the JSON.Net dll. I verified the dlls are the right versions and of course everything works perfectly local.
     
  4. Elshadriel

    Elshadriel Winhost Staff

    Last edited by a moderator: Oct 14, 2015
  5. No they are definitely there. I even verified that they haven't been modified or any of the other things it is complaining about. I'm not doing anything particularly strange in the app. It's just a backend with WebAPI to a small database of values. I'm pretty much grasping at straws at this point. I can't find any reason that these assemblies won't load on the site.
     
  6. Elshadriel

    Elshadriel Winhost Staff

    The only other thing I can think of is that you're not using the correct Framework. What's the domain name of your site?
     
  7. lfg.infidelux.net

    There should be a web redirect that sends you to the app folder. The index.html (which doesn't do anything yet) isn't even getting hit because the rest of the app can't get loaded.
     
  8. Elshadriel

    Elshadriel Winhost Staff

    I checked your web.config file in the root. You have not set the trust level to 'Full' yet.
     
  9. I just added it. (It was set in the subdirectory's web.config) That didn't seem to make any difference though. When the trust level in the app folder wasn't set to full, the dependency injection assemblies couldn't load and that was the first error I got. Setting it to full in that web.config seemed to solve that but now I'm getting errors getting these assemblies that web api depend on to load.
     
  10. Elshadriel

    Elshadriel Winhost Staff

    Here are a couple of links on the topic:

    http://forums.asp.net/t/1168781.aspx/1
    http://www.devexpress.com/Support/Center/p/Q309995.aspx
    http://stackoverflow.com/questions/...h-assembly-reference-throws-signing-strong-na
    http://forums.asp.net/t/1835695.aspx/1
    http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/bdd42a56-e869-4a82-89a2-4a3016918bab

    Unfortunately, I'm not sure how to narrow it down. Solutions varied from incorrect reference in your code, not loading a dependent assembly, re-signing the assembly, etc.
     
  11. Yep, I found all of those before I posted about the problem. I'm wondering if it may have something to do with this:

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18033

    Shouldn't those be 4.5 if I'm on an IIS8 host?
     
  12. And it's possible the MS didn't update the API I suppose but I thought this was also strange from the stack trace:
    Code:
    [HttpException (0x80004005): Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate([B][COLOR="Red"]IIS7WorkerRequest[/COLOR][/B] wr, HttpContext context) +254
    
     
  13. (Yes, I'm grasping at straws here..) I even transferred the dll back to my local system and pulled it into JustDecompile and it shows the correct version and assembly information. Adding a bindingRedirect in the web.config didn't help either. I don't think anything is trying to load an older version. This version along with the ASPNet Web API assembly were Nuget packages that were already installed just by choosing Web API as the project type in Visual Studio.
     
  14. Elshadriel

    Elshadriel Winhost Staff

    It's 4.5. The version reference is misleading. Have you tried removing the URL redirects to help isolate the problem? I'm kinda grasping at straws here as well.
     
  15. I'm going to try that next. I just republished it and now the JSON.Net dll doesn't complain but instead I am getting this:
    Code:
    System.IO.FileLoadException: Could not load file or assembly 'EntityFramework' or one of its dependencies. Strong name signature could not be verified.  The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
    
    It almost seems like a random dll every so often. Although I got EF not loading before then published and started getting the JSON.Net one. Let me pull the redirects and see what that does.
     
  16. Ok. Some progress. I deleted all of the files and republished everything, with redirects off. I can get the site to initialize now. But it can't connect to the DB. I see something on it in the KB so I'll see where that takes me..
    Code:
    A network-related or instance-specific error occurred while establishing a connection to SQL Server. 
    The server was not found or was not accessible. 
    Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 
    (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
    
     
  17. Elshadriel

    Elshadriel Winhost Staff

    That error usually occurs because of an incorrect connection string.
     
  18. Yea, that's what I read but I was using EF Code first which generated a SQLExpress DB. I took a backup of that, restored it on my hosted SQL Server here and I'm using the SQL Connection string listed in the SQL Manager. But I'm thinking it may be something from the Code First conventions that are still looking for a SQLExpress DB. I'm working on switching the local copy of the app to use the same Hosted DB so I can troubleshoot it from here. Thanks for your help.
     
  19. Just an update. I have it all working now. Good call on removing the redirects. The way I had them set up is what was causing the DLL loading errors. And I had to make a code change so that my DBContext would use the hosted SQL Server.

    Thanks again!
     
  20. Elshadriel

    Elshadriel Winhost Staff

    Great! I'm glad to hear you got it working. :)
     
  21. Nothing to it! ;)
     

Share This Page