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

AppDomains don't work (aspnet50) #985

Closed
bricelam opened this issue Dec 11, 2014 · 9 comments
Closed

AppDomains don't work (aspnet50) #985

bricelam opened this issue Dec 11, 2014 · 9 comments
Assignees
Milestone

Comments

@bricelam
Copy link
Contributor

The following code...

AppDomain.CreateDomain("MyDomain");

...throws the following exception.

System.TypeLoadException: The domain manager specified by the host could not be instantiated. ---> System.IO.FileNotFoundException: Could not load file or assembly 'klr.net45.managed' or one of its dependencies. The system cannot find the file specified.
   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.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateAppDomainManager()
   --- End of inner exception stack trace ---
   at System.AppDomain.CreateAppDomainManager()
   at System.AppDomain.Setup(Object arg)
   at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
   at System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName)
@troydai
Copy link
Contributor

troydai commented Dec 15, 2014

@bricelam can't repo this on 1.0.0-rc1-10781. On which KRE did you observe this issue? Is the AppDomain creating the only thing trigger the error?

@bricelam
Copy link
Contributor Author

Nothing special here. I'm using 1.0.0-rc1-10781 as well. Here is my entire source code.

using System;

namespace Test
{
    public static class Program
    {
        public static void Main()
        {
            AppDomain.Create("Test");
        }
    }
}

...and project.json

{
    "frameworks": {
        "aspnet50": { }
    }
}

...and k run output with tracing and fusion log.

Loaded Module: k
Found DLL Export: CallApplicationMain
klr Information: 0 : [LoaderContainer]: Load name=Microsoft.Framework.ApplicationHost
klr Information: 0 : [PathBasedAssemblyLoader]: Loaded name=Microsoft.Framework.ApplicationHost in 11ms
klr Information: 0 : [LoaderContainer]: Load name=Microsoft.Framework.Runtime
klr Information: 0 : [PathBasedAssemblyLoader]: Loaded name=Microsoft.Framework.Runtime in 12ms
klr Information: 0 : [LoaderContainer]: Load name=Newtonsoft.Json
klr Information: 0 : [PathBasedAssemblyLoader]: Loaded name=Newtonsoft.Json in 7ms
klr Information: 0 : [DefaultHost]: Project path: C:\Projects\Test\src\Test
klr Information: 0 : [DefaultHost]: Project root: C:\Projects\Test\src\Test
klr Information: 0 : [DefaultHost]: Packages path: C:\Users\bricelam\.kpm\packages
klr Information: 0 : [DependencyWalker]: Walking dependency graph for 'Test Asp.Net,Version=v5.0'.
klr Information: 0 : [ProjectReferenceDependencyProvider]: Test 1.0.0
klr Information: 0 : [ReferenceAssemblyDependencyResolver]: gac/mscorlib 4.0.0.0, gac/System 4.0.0.0, gac/System.Core 4.0.0.0, gac/Microsoft.CSharp 4.0.0.0
klr Information: 0 : [DependencyWalker]: Resolved dependencies for Test in 67ms
klr Information: 0 : [LoaderContainer]: Load name=Test
klr Information: 0 : [ProjectLibraryExportProvider]: GetLibraryExport(Test, Asp.Net,Version=v5.0, Debug, )
klr Information: 0 : [LoaderContainer]: Load name=Microsoft.Framework.Runtime.Roslyn
klr Information: 0 : [PathBasedAssemblyLoader]: Loaded name=Microsoft.Framework.Runtime.Roslyn in 4ms
klr Information: 0 : [LoaderContainer]: Load name=Microsoft.CodeAnalysis
klr Information: 0 : [PathBasedAssemblyLoader]: Loaded name=Microsoft.CodeAnalysis in 5ms
klr Information: 0 : [Microsoft.Framework.Runtime.Roslyn.RoslynProjectReferenceProvider]: GetProjectReference(Test, Asp.Net,Version=v5.0, Debug, )
klr Information: 0 : [LoaderContainer]: Load name=Microsoft.CodeAnalysis.CSharp
klr Information: 0 : [PathBasedAssemblyLoader]: Loaded name=Microsoft.CodeAnalysis.CSharp in 5ms
klr Information: 0 : [ProjectExportProviderHelper]: Resolving references for 'Test'
klr Information: 0 : [LoaderContainer]: Load name=System.Reflection.Metadata
klr Information: 0 : [PathBasedAssemblyLoader]: Loaded name=System.Reflection.Metadata in 7ms
klr Information: 0 : [ProjectExportProviderHelper]: Resolved 4 references for 'Test' in 252ms
klr Information: 0 : [RoslynCompiler]: Compiling 'Test'
klr Information: 0 : [LoaderContainer]: Load name=Microsoft.CodeAnalysis.Desktop
klr Information: 0 : [PathBasedAssemblyLoader]: Loaded name=Microsoft.CodeAnalysis.Desktop in 5ms
klr Information: 0 : [RoslynCompiler]: Scanning 'Test' for assembly neutral interfaces
klr Information: 0 : [RoslynCompiler]: Found 0 assembly neutral interfaces for 'Test' in 374ms
klr Information: 0 : [RoslynCompiler]: Compiled 'Test' in 930ms
klr Information: 0 : [CompilationContext]: Generating resources for Test
klr Information: 0 : [CompilationContext]: Generated resources for Test in 4ms
klr Information: 0 : [CompilationContext]: Resolving required assembly neutral references for Test
klr Information: 0 : [CompilationContext]: Resolved 0 required assembly neutral references for Test in 5ms
klr Information: 0 : [RoslynProjectReference]: Emitting assembly for Test
klr Information: 0 : [RoslynProjectReference]: Emitted Test in 1868ms
klr Information: 0 : [ProjectAssemblyLoader]: Loaded name=Test in 3233ms
System.TypeLoadException: The domain manager specified by the host could not be instantiated. ---> System.IO.FileNotFoundException: Could not load file or assembly 'klr.net45.managed' or one of its dependencies. The system cannot find the file specified.
   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.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateAppDomainManager()
   --- End of inner exception stack trace ---
   at System.AppDomain.CreateAppDomainManager()
   at System.AppDomain.Setup(Object arg)
   at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
   at System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName)
   at Test.Program.Main() in C:\Projects\Test\src\Test\Program.cs:line 9
System.IO.FileNotFoundException: Could not load file or assembly 'klr.net45.managed' or one of its dependencies. The system cannot find the file specified.
File name: 'klr.net45.managed'
   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.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateAppDomainManager()

=== Pre-bind state information ===
LOG: DisplayName = klr.net45.managed
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: klr.net45.managed | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Projects/Test/src/Test
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Configuration file C:\Users\bricelam\.kre\packages\KRE-CLR-x86.1.0.0-rc1-10781\bin\klr.exe.config does not exist.
LOG: No application configuration file found.
LOG: Using host configuration file: C:\Users\bricelam\.kre\packages\KRE-CLR-x86.1.0.0-rc1-10781\bin\klr.net45.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Projects/Test/src/Test/klr.net45.managed.DLL.
LOG: Attempting download of new URL file:///C:/Projects/Test/src/Test/klr.net45.managed/klr.net45.managed.DLL.
LOG: Attempting download of new URL file:///C:/Projects/Test/src/Test/klr.net45.managed.EXE.
LOG: Attempting download of new URL file:///C:/Projects/Test/src/Test/klr.net45.managed/klr.net45.managed.EXE.

@davidfowl
Copy link
Member

Yea it doesn't work. Set the http://msdn.microsoft.com/en-us/library/system.appdomainsetup.appdomainmanagerassembly(v=vs.110).aspx to null or empty string and see if that works.

@troydai
Copy link
Contributor

troydai commented Dec 15, 2014

This works

    // Issue 985
    //

    var setup = new AppDomainSetup();
    setup.AppDomainManagerAssembly = string.Empty;

    AppDomain.CreateDomain("MyDomain", null, setup);

@bricelam
Copy link
Contributor Author

@davidfowl So any existing libraries for net45 that don't do this will break?

@davidfowl
Copy link
Member

For now. I'm sure there's a way to make this work without having to null out the appdomain manager. We just need to set the right flags or something like that.

@davidfowl
Copy link
Member

I believe this works now without having to specify the domain manager as empty string

@davidfowl
Copy link
Member

Just tried it and I'm getting a new error:

System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
   at DomainManager.BindApplicationMain(ApplicationMainInfo& info)
   at DomainManager.InitializeNewDomain(AppDomainSetup appDomainInfo)
   at System.AppDomain.CreateAppDomainManager()
   at System.AppDomain.Setup(Object arg)
   at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr p
arentSecurityDescriptor)
   at System.AppDomainManager.CreateDomainHelper(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomainManager.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
   at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName)
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\davifowl\Documents\Visual Studio 14\Projects\WebApplication7\src\ConsoleApp1\Program.cs:line
 10

We'll have to clean up our AppDomainManager so make it handle this.

@davidfowl davidfowl self-assigned this Mar 1, 2015
@davidfowl davidfowl added this to the 1.0.0-rc1 milestone Mar 1, 2015
@davidfowl
Copy link
Member

Fixed in 16fd19a

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

No branches or pull requests

3 participants