Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Cannot test ASP.NET Web Application decorated with AssemblyCultureAttribute. #2890

Closed
hubuk opened this issue Oct 2, 2015 · 11 comments
Closed

Comments

@hubuk
Copy link

hubuk commented Oct 2, 2015

UPDATE:
Reproduction project available on https://github.com/hubuk/Issue-aspnet-dnx-2890-AssemblyCulture

Environment for which the problem occurs is following:

  1. A newly created ASP.NET 5 Web API project named (Application).
  2. An ASP.NET class library which acts as a test project.
  3. All the necessary references to test framework and Application project are added:
"dependencies": {
  "Application":  "1.0.0",
  "Microsoft.AspNet.TestHost": "1.0.0-beta7",
  "xunit.runner.dnx": "2.1.0-*",
  "xunit": "2.1.0-*"
},

*4. [assembly: AssemblyCulture("en-US")] attribute is added to Application project.
5. Test with the following content is created:

public class TestClass  {
    private readonly Action<IApplicationBuilder> _app;
    private readonly Action<IServiceCollection> _services;

    public TestClass()  {
        var environment = CallContextServiceLocator.Locator.ServiceProvider.GetRequiredService<IApplicationEnvironment>();

        var startup = new Startup(new HostingEnvironment());
        _app = startup.Configure;
        _services = startup.ConfigureServices;
    }

    [Fact]
    public async Task Get()  {
        var server = TestServer.Create(_app, _services);
        var client = server.CreateClient();

        var deleteResponse = await client.GetAsync(string.Empty);
    }
}

When running dnx test from test project directory I got the following error (not reproducible after deleting attribute from point 4):

PS ...\Repro\test\Application.Tests> dnx test
xUnit.net DNX Runner (32-bit DNXCore 5.0)
  Discovering: Application.Tests
  Discovered:  Application.Tests
  Starting:    Application.Tests
    Application.Tests.Class1.PostDelete [FAIL]
      System.IO.FileLoadException : Could not load file or assembly 'Application, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)
      ---- System.IO.FileLoadException : Assembly with same name is already loaded
      Stack Trace:
           at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity , RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
           at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
           at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
           at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
           at Microsoft.AspNet.Mvc.DefaultAssemblyProvider.Load(AssemblyName assemblyName)
           at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
           at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
           at System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer)
           at Microsoft.AspNet.Mvc.DefaultControllerTypeProvider.get_ControllerTypes()
           at Microsoft.AspNet.Mvc.Core.ControllerActionDescriptorProvider.BuildModel()
           at Microsoft.AspNet.Mvc.Core.ControllerActionDescriptorProvider.GetDescriptors()
           at Microsoft.AspNet.Mvc.Core.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
           at Microsoft.AspNet.Mvc.Core.DefaultActionDescriptorsCollectionProvider.GetCollection()
           at Microsoft.AspNet.Mvc.Core.DefaultActionDescriptorsCollectionProvider.get_ActionDescriptors()
           at Microsoft.AspNet.Mvc.Routing.AttributeRoute.GetInnerRoute()
           at Microsoft.AspNet.Mvc.Routing.AttributeRoute.RouteAsync(RouteContext context)
           at Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.AspNet.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.AspNet.Hosting.Internal.HostingEngine.<>c__DisplayClass29_0.<<Start>b__0>d.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.AspNet.TestHost.ClientHandler.<>c__DisplayClass3_0.<<SendAsync>b__0>d.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.AspNet.TestHost.ClientHandler.<SendAsync>d__3.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
           at Application.Tests.Class1.<PostDelete>d__3.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        ----- Inner Stack Trace -----
           at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(IntPtr ptrNativeAssemblyLoadContext, IntPtr ptrAssemblyArray, Int32 iAssemblyArrayLen, IntPtr ptrSymbols, Int32 iSymbolArrayLen, ObjectHandleOnStack retAssembly)
           at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(Stream assembly, Stream assemblySymbols)
           at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadStream(Stream assembly, Stream assemblySymbols)
           at Microsoft.Dnx.Compilation.CSharp.RoslynProjectReference.Load(IAssemblyLoadContext loadContext)
           at Microsoft.Dnx.Compilation.CompilationEngine.LoadProject(Project project, String aspect, IAssemblyLoadContext loadContext)
           at Microsoft.Dnx.Runtime.Loader.ProjectAssemblyLoader.Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
           at Microsoft.Dnx.Runtime.Loader.ProjectAssemblyLoader.Load(AssemblyName assemblyName)
           at Microsoft.Dnx.Host.LoaderContainer.Load(AssemblyName assemblyName)
           at Microsoft.Dnx.Host.DefaultLoadContext.LoadAssembly(AssemblyName assemblyName)
           at Microsoft.Dnx.Runtime.Loader.AssemblyLoaderCache.GetOrAdd(AssemblyName name, Func`2 factory)
           at Microsoft.Dnx.Runtime.Loader.LoadContext.Load(AssemblyName assemblyName)
           at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
           at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
  Finished:    Application.Tests
=== TEST EXECUTION SUMMARY ===
   Application.Tests  Total: 1, Errors: 0, Failed: 1, Skipped: 0, Time: 0,485s
@NeelBhatt
Copy link

may be related to #2802

@hubuk
Copy link
Author

hubuk commented Oct 2, 2015

Yes, it may be related but in this case there is only one assembly named Application. There are no satellites.

@muratg
Copy link
Contributor

muratg commented Oct 2, 2015

@kirthik Any thoughts on this one?

@kirthik
Copy link
Contributor

kirthik commented Oct 2, 2015

Could you please tell me what build of dnx you are using?

@muratg
Copy link
Contributor

muratg commented Oct 2, 2015

From his global.json, it looks like he's using Beta 7.

@hubuk This may have been fixed with #2802. Can you upgrade to the latest bits and retry?

@muratg
Copy link
Contributor

muratg commented Oct 5, 2015

@kirthik
Copy link
Contributor

kirthik commented Oct 5, 2015

Thank you for reporting this issue. Your issue is fixed with #2802 but I found another related issue - #2902. I will send a fix for this soon.

@hubuk
Copy link
Author

hubuk commented Oct 5, 2015

Sorry for late response and thank you all for the comments.
I have checked all the coreclr runtimes for x86 and x64 from 1.0.0-beta7 to 1.0.0-rc1-15798
Starting from beta8-15616 a new exception is thrown instead of the old one:

PS ...\Repro\test\Application.Tests> dnx test
xUnit.net DNX Runner (64-bit DNXCore 5.0)
  Discovering: Application.Tests
  Discovered:  Application.Tests
  Starting:    Application.Tests
    Application.Tests.TestClass.Get [FAIL]
      System.IO.FileNotFoundException : Could not load file or assembly 'Application, Version=1.0.0.0, Culture=en-US, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
      ---- System.IO.FileNotFoundException : Could not load the specified file.
      Stack Trace:
           at Application.Tests.TestClass..ctor()
        ----- Inner Stack Trace -----
           at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
           at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
  Finished:    Application.Tests
=== TEST EXECUTION SUMMARY ===
   Application.Tests  Total: 1, Errors: 0, Failed: 1, Skipped: 0, Time: 0,199s

But I think this is exactly what @kirthik has already reported in #2902.

@hubuk
Copy link
Author

hubuk commented Oct 6, 2015

I am closing this issue as #2902 is probably a root cause for this problem. Will reopen if it turns out otherwise.

@hubuk hubuk closed this as completed Oct 6, 2015
@muratg
Copy link
Contributor

muratg commented Oct 6, 2015

Thanks @hubuk. I triaged #2902 for RC1.

@dalpert-korewireless
Copy link

I have not played much with the new dnx bits yet, but found this post after running into a very similar behavior with an ASP.NET WebForms app running on .NET 4

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants