Remove always defined FEATURE_CORECLR
[platform/upstream/coreclr.git] / src / vm / assembly.cpp
index eb4c2e5..59f9947 100644 (file)
 #include "ngenoptout.h"
 #endif
 
-#if !defined(FEATURE_CORECLR) && !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
-#include "assemblyusagelogmanager.h"
-#include "policy.h"
-#endif
 
 #include "eeprofinterfaces.h"
 #include "reflectclasswriter.h"
 
 #include "peimagelayout.inl"
 
-#if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE)
-#include <shlobj.h>
-#include "eventmsg.h"
-#endif
 
 #ifdef FEATURE_TRACELOGGING
 #include "clrtracelogging.h"
@@ -171,9 +163,6 @@ Assembly::Assembly(BaseDomain *pDomain, PEAssembly* pFile, DebuggerAssemblyContr
 #ifdef FEATURE_COMINTEROP
     , m_InteropAttributeStatus(INTEROP_ATTRIBUTE_UNSET)
 #endif
-#ifndef FEATURE_CORECLR
-    , m_fSupportsAutoNGen(FALSE)
-#endif
 {
     STANDARD_VM_CONTRACT;
 }
@@ -285,13 +274,6 @@ void Assembly::Init(AllocMemTracker *pamTracker, LoaderAllocator *pLoaderAllocat
     if (!m_pManifest->IsReadyToRun())
         CacheManifestExportedTypes(pamTracker);
 
-#if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE)
-    GenerateBreadcrumbForServicing();
-
-    m_fSupportsAutoNGen = SupportsAutoNGenWorker();
-
-    ReportAssemblyUse();
-#endif
 
 #ifdef FEATURE_TRACELOGGING
 
@@ -808,69 +790,12 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, CreateDynamicAssemblyArgs
     }            
     
     AssemblyLoadSecurity loadSecurity;
-#ifndef FEATURE_CORECLR
-    DWORD dwSpecialFlags = 0xFFFFFFFF;
-    
-    // Don't bother with setting up permissions if this isn't allowed to run
-    // This doesn't apply in CoreCLR because you cannot specify evidence when creating a dynamic assembly
-    if ((args->identity != NULL) &&
-        (args->access & ASSEMBLY_ACCESS_RUN))
-    {
-        loadSecurity.m_pAdditionalEvidence = &args->identity;
-    }
-    else
-    {
-        if (pCallerAssembly != NULL) // can be null if caller is interop
-        {
-            if (args->securityContextSource == kCurrentAssembly)
-            {
-                IAssemblySecurityDescriptor *pCallerSecDesc = pCallerAssembly->GetSecurityDescriptor(pCallersDomain);
-                gc.granted = pCallerSecDesc->GetGrantedPermissionSet(&(gc.denied));
-                dwSpecialFlags = pCallerSecDesc->GetSpecialFlags();
-            }
-            else
-            {
-                IApplicationSecurityDescriptor *pCallersDomainSecDesc = pCallersDomain->GetSecurityDescriptor();
-
-#ifdef FEATURE_CAS_POLICY
-                // We only want to propigate the identity of homogenous domains, since heterogenous domains tend
-                // to be fully trusted even if they are housing partially trusted code - which could lead to an
-                // elevation of privilege if we allow the grant set to be pushed to assemblies partially trusted
-                // code is loading.
-                if (!pCallersDomainSecDesc->IsHomogeneous())
-                {
-                    COMPlusThrow(kNotSupportedException, W("NotSupported_SecurityContextSourceAppDomainInHeterogenous"));
-                }
-#endif // FEATURE_CAS_POLICY
-
-                gc.granted = pCallersDomainSecDesc->GetGrantedPermissionSet();
-                dwSpecialFlags = pCallersDomainSecDesc->GetSpecialFlags();
-            }
-
-            // Caller may be in another appdomain context, in which case we'll
-            // need to marshal/unmarshal the grant and deny sets across.
-#ifdef FEATURE_REMOTING  // should not happen without remoting              
-            if (pCallersDomain != ::GetAppDomain())
-            {
-                gc.granted = AppDomainHelper::CrossContextCopyFrom(pCallersDomain->GetId(), &(gc.granted));
-                if (gc.denied != NULL)
-                {
-                    gc.denied = AppDomainHelper::CrossContextCopyFrom(pCallersDomain->GetId(), &(gc.denied));
-                }
-            }
-#else // !FEATURE_REMOTING
-            _ASSERTE(pCallersDomain == ::GetAppDomain());
-#endif // FEATURE_REMOTING
-        }
-    }
-#else // FEATURE_CORECLR
     // In SilverLight all dynamic assemblies should be transparent and partially trusted, even if they are
     // created by platform assemblies. Thus they should inherit the grant sets from the appdomain not the 
     // parent assembly.
     IApplicationSecurityDescriptor *pCurrentDomainSecDesc = ::GetAppDomain()->GetSecurityDescriptor();
     gc.granted = pCurrentDomainSecDesc->GetGrantedPermissionSet();
     DWORD dwSpecialFlags = pCurrentDomainSecDesc->GetSpecialFlags();
-#endif // !FEATURE_CORECLR
 
     // If the dynamic assembly creator did not specify evidence for the newly created assembly, then it
     // should inherit the grant set of the creation assembly.
@@ -992,33 +917,6 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, CreateDynamicAssemblyArgs
             tokenFlags |= TokenSecurityDescriptorFlags_TreatAsSafe;
 
 
-#ifndef FEATURE_CORECLR
-        // Use the security rules given to us if the emitting code has selected a specific one. Otherwise,
-        // inherit the security rules of the emitting assembly.
-        if (args->securityRulesBlob != NULL)
-        {
-            tokenFlags |= ParseSecurityRulesAttribute(args->securityRulesBlob->GetDirectPointerToNonObjectElements(),
-                                                      args->securityRulesBlob->GetNumComponents());
-        }
-        else
-        {
-            // Ensure that dynamic assemblies created by mscorlib always specify a rule set, since we want to
-            // make sure that creating a level 2 assembly was an explicit decision by the emitting code,
-            // rather than an implicit decision because mscorlib is level 2 itself.
-            //
-            // If you're seeing this assert, it means that you've created a dynamic assembly from mscorlib,
-            // but did not pass a CustomAttributeBuilder for the SecurityRulesAttribute to the 
-            // DefineDynamicAssembly call.
-           _ASSERTE(!pCallerAssembly->IsSystem());
-
-            // Use the creating assembly's security rule set for the emitted assembly
-            SecurityRuleSet callerRuleSet = 
-                ModuleSecurityDescriptor::GetModuleSecurityDescriptor(pCallerAssembly)->GetSecurityRuleSet();
-            tokenFlags |= EncodeSecurityRuleSet(callerRuleSet);
-
-            tokenFlags |= TokenSecurityDescriptorFlags_SecurityRules;
-        }
-#endif // !FEATURE_CORECLR
 
         _ASSERTE(pAssem->GetManifestModule()->m_pModuleSecurityDescriptor != NULL);
         pAssem->GetManifestModule()->m_pModuleSecurityDescriptor->OverrideTokenFlags(tokenFlags); 
@@ -1030,47 +928,6 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, CreateDynamicAssemblyArgs
         if (publicKey.GetSize() > 0)
         {
             pAssem->SetStrongNameLevel(Assembly::SN_PUBLIC_KEY);
-#ifndef FEATURE_CORECLR
-            gc.strongNameKeyPair = args->assemblyName->GetStrongNameKeyPair();
-            // If there's a public key, there might be a strong name key pair.
-            if (gc.strongNameKeyPair != NULL) 
-            {
-                MethodDescCallSite getKeyPair(METHOD__STRONG_NAME_KEY_PAIR__GET_KEY_PAIR, &gc.strongNameKeyPair);
-
-                ARG_SLOT arglist[] = 
-                {
-                    ObjToArgSlot(gc.strongNameKeyPair),
-                    PtrToArgSlot(&gc.orArrayOrContainer)
-                };
-
-                BOOL bKeyInArray;
-                bKeyInArray = (BOOL)getKeyPair.Call_RetBool(arglist);
-
-                if (bKeyInArray)
-                {
-                    U1ARRAYREF orArray = (U1ARRAYREF)gc.orArrayOrContainer;
-                    pAssem->m_cbStrongNameKeyPair = orArray->GetNumComponents();
-                    pAssem->m_pbStrongNameKeyPair = new BYTE[pAssem->m_cbStrongNameKeyPair];
-
-                    pAssem->m_FreeFlag |= pAssem->FREE_KEY_PAIR;
-                    memcpy(pAssem->m_pbStrongNameKeyPair, orArray->GetDataPtr(), pAssem->m_cbStrongNameKeyPair);
-                    pAssem->SetStrongNameLevel(Assembly::SN_FULL_KEYPAIR_IN_ARRAY);
-                }
-                else
-                {
-                    STRINGREF orContainer = (STRINGREF)gc.orArrayOrContainer;
-                    DWORD cchContainer = orContainer->GetStringLength();
-                    pAssem->m_pwStrongNameKeyContainer = new WCHAR[cchContainer + 1];
-
-                    pAssem->m_FreeFlag |= pAssem->FREE_KEY_CONTAINER;
-                    memcpy(pAssem->m_pwStrongNameKeyContainer, orContainer->GetBuffer(), cchContainer * sizeof(WCHAR));
-                    pAssem->m_pwStrongNameKeyContainer[cchContainer] = W('\0');
-
-                    pAssem->SetStrongNameLevel(Assembly::SN_FULL_KEYPAIR_IN_CONTAINER);
-                }
-            }
-            else
-#endif // FEATURE_CORECLR
             {
                 // Since we have no way to validate the public key of a dynamic assembly we don't allow 
                 // partial trust code to emit a dynamic assembly with an arbitrary public key.
@@ -1764,11 +1621,6 @@ Module * Assembly::FindModuleByTypeRef(
                 RETURN NULL;
             }
 
-#ifndef FEATURE_CORECLR
-            // Event Tracing for Windows is used to log data for performance and functional testing purposes.
-            // The events below are used to help measure the performance of assembly loading of a static reference.
-            FireEtwLoaderPhaseStart((::GetAppDomain() ? ::GetAppDomain()->GetId().m_dwId : ETWAppDomainIdNotAvailable), ETWLoadContextNotAvailable, ETWFieldUnused, ETWLoaderStaticLoad, NULL, NULL, GetClrInstanceId());
-#endif //!FEATURE_CORECLR
             
             DomainAssembly * pDomainAssembly = pModule->LoadAssembly(
                     ::GetAppDomain(), 
@@ -1776,27 +1628,6 @@ Module * Assembly::FindModuleByTypeRef(
                     szNamespace, 
                     szClassName);
 
-#ifndef FEATURE_CORECLR
-            if (ETW_TRACING_CATEGORY_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PRIVATE_PROVIDER_Context, TRACE_LEVEL_INFORMATION, CLR_PRIVATEBINDING_KEYWORD))
-            {
-                StackSString assemblySimpleName;
-                EX_TRY
-                {
-                    if ((pDomainAssembly != NULL) && (pDomainAssembly->GetCurrentAssembly() != NULL))
-                    {
-                        assemblySimpleName.AppendUTF8(pDomainAssembly->GetCurrentAssembly()->GetSimpleName());
-                        assemblySimpleName.Normalize(); // Ensures that the later cast to LPCWSTR does not throw.
-                    }
-                }
-                EX_CATCH
-                {
-                    assemblySimpleName.Clear();
-                }
-                EX_END_CATCH(RethrowTransientExceptions)
-                
-                FireEtwLoaderPhaseEnd(::GetAppDomain() ? ::GetAppDomain()->GetId().m_dwId : ETWAppDomainIdNotAvailable, ETWLoadContextNotAvailable, ETWFieldUnused, ETWLoaderStaticLoad, NULL, assemblySimpleName.IsEmpty() ? NULL : (LPCWSTR)assemblySimpleName, GetClrInstanceId());
-            }
-#endif //!FEATURE_CORECLR
 
             if (pDomainAssembly == NULL)
                 RETURN NULL;
@@ -2539,20 +2370,7 @@ HRESULT RunMain(MethodDesc *pFD ,
 
     if ((EntryType == EntryManagedMain) &&
         (stringArgs == NULL)) {
- #ifndef FEATURE_CORECLR
-       // If you look at the DIFF on this code then you will see a major change which is that we
-        // no longer accept all the different types of data arguments to main.  We now only accept
-        // an array of strings.
-
-        wzArgs = CorCommandLine::GetArgvW(&cCommandArgs);
-        // In the WindowsCE case where the app has additional args the count will come back zero.
-        if (cCommandArgs > 0) {
-            if (!wzArgs)
-                return E_INVALIDARG;
-        }
-#else // !FEATURE_CORECLR
         return E_INVALIDARG;
-#endif // !FEATURE_CORECLR
     }
 
     ETWFireEvent(Main_V1);
@@ -2727,13 +2545,11 @@ INT32 Assembly::ExecuteMainMethod(PTRARRAYREF *stringArgs, BOOL waitForOtherThre
             }
 #endif // FEATURE_APPX_BINDER && FEATURE_MULTICOREJIT
             
-#ifdef FEATURE_CORECLR
             // Set the root assembly as the assembly that is containing the main method
             // The root assembly is used in the GetEntryAssembly method that on CoreCLR is used
             // to get the TargetFrameworkMoniker for the app
             AppDomain * pDomain = pThread->GetDomain();
             pDomain->SetRootAssembly(pMeth->GetAssembly());
-#endif
             hr = RunMain(pMeth, 1, &iRetVal, stringArgs);
         }
     }
@@ -3165,24 +2981,13 @@ mdAssemblyRef Assembly::AddAssemblyRef(Assembly *refedAssembly, IMetaDataAssembl
         GC_TRIGGERS;
         INJECT_FAULT(COMPlusThrowOM(););
         PRECONDITION(CheckPointer(refedAssembly));
-#ifdef FEATURE_CORECLR
         PRECONDITION(CheckPointer(pAssemEmitter, NULL_NOT_OK));
-#else
-        PRECONDITION(CheckPointer(pAssemEmitter, NULL_OK));
-#endif //FEATURE_CORECLR
         POSTCONDITION(!IsNilToken(RETVAL));
         POSTCONDITION(TypeFromToken(RETVAL) == mdtAssemblyRef);
     }
     CONTRACT_END;
 
     SafeComHolder<IMetaDataAssemblyEmit> emitHolder;
-#if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE)
-    if (pAssemEmitter == NULL)
-    {
-        pAssemEmitter = GetOnDiskMDAssemblyEmitter();
-        emitHolder.Assign(pAssemEmitter);
-    }
-#endif // FEATURE_CORECLR && !CROSSGEN_COMPILE
 
     AssemblySpec spec;
     spec.InitializeSpec(refedAssembly->GetManifestFile());
@@ -3250,650 +3055,109 @@ void Assembly::AddExportedType(mdExportedType cl)
 }
 
 
-#if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE)
 
-//***********************************************************
-//
-// get the IMetaDataAssemblyEmit for the on disk manifest.
-// Note that the pointer returned is AddRefed. It is the caller's
-// responsibility to release the reference.
-//
-//***********************************************************
-IMetaDataAssemblyEmit *Assembly::GetOnDiskMDAssemblyEmitter()
+
+HRESULT STDMETHODCALLTYPE
+GetAssembliesByName(LPCWSTR  szAppBase,
+                    LPCWSTR  szPrivateBin,
+                    LPCWSTR  szAssemblyName,
+                    IUnknown *ppIUnk[],
+                    ULONG    cMax,
+                    ULONG    *pcAssemblies)
 {
     CONTRACTL
     {
-        THROWS;
+        NOTHROW;
+        MODE_PREEMPTIVE;
         GC_TRIGGERS;
-        INJECT_FAULT(COMPlusThrowOM(););
+        INJECT_FAULT(return E_OUTOFMEMORY;);
     }
     CONTRACTL_END
 
-    IMetaDataAssemblyEmit *pAssemEmitter = NULL;
-    IMetaDataEmit   *pEmitter;
-    RefClassWriter  *pRCW;
-
-    _ASSERTE(m_pOnDiskManifest);
-
-    pRCW = m_pOnDiskManifest->GetClassWriter();
-    _ASSERTE(pRCW);
-
-    // If the RefClassWriter has a on disk emitter, then use it rather than the in-memory emitter.
-    pEmitter = pRCW->GetOnDiskEmitter();
-
-    if (pEmitter == NULL)
-        pEmitter = m_pOnDiskManifest->GetEmitter();
-    
-    _ASSERTE(pEmitter != NULL);
-    
-    IfFailThrow(pEmitter->QueryInterface(IID_IMetaDataAssemblyEmit, (void**) &pAssemEmitter));
-    
-    if (pAssemEmitter == NULL)
-    {
-        // the manifest is not writable
-        _ASSERTE(!"Bad usage!");
-    }
-    return pAssemEmitter;
-}
-
-//***********************************************************
-//
-// prepare saving manifest to disk.
-//
-//***********************************************************
-void Assembly::PrepareSavingManifest(ReflectionModule *pAssemblyModule)
-{
-    STANDARD_VM_CONTRACT;
-
-    if (pAssemblyModule)
-    {
-        // embedded assembly
-        m_pOnDiskManifest = pAssemblyModule;
-        m_fEmbeddedManifest = true;
-    }
-    else
-    {
-        m_fEmbeddedManifest = false;
-
-        StackSString name(SString::Utf8, GetSimpleName());
-
-        // Create the module
-        m_pOnDiskManifest = CreateDynamicModule(name, name, FALSE /*fIsTransient*/);
-        // store the fact this on disk manifest is temporary and can be hidden from the user
-        m_needsToHideManifestForEmit = TRUE;
-    }
-
-    NonVMComHolder<IMetaDataAssemblyEmit> pAssemblyEmit(GetOnDiskMDAssemblyEmitter());
-
-    // Copy assembly metadata to emit scope
-    //<TODO>@todo: add Title, Description, Alias as CA</TODO>
-    // <TODO>@todo: propagate all of the information</TODO>
-    // <TODO>@todo: introduce a helper in metadata to take the ansi version of string.</TODO>
-
-    IMetaDataAssemblyImport *pAssemblyImport = GetManifestFile()->GetAssemblyImporter();
-
-    const void          *pbPublicKey;
-    ULONG               cbPublicKey;
-    ULONG               ulHashAlgId;
-    LPWSTR              szName;
-    ULONG               chName;
-    ASSEMBLYMETADATA    MetaData;
-    DWORD               dwAssemblyFlags;
-
-    MetaData.cbLocale = 0;
-    MetaData.ulProcessor = 0;
-    MetaData.ulOS = 0;
-    IfFailThrow(pAssemblyImport->GetAssemblyProps(TokenFromRid(1, mdtAssembly),
-                                                  NULL, NULL, NULL,
-                                                  NULL, 0, &chName,
-                                                  &MetaData, NULL));
-    StackSString name;
-    szName = name.OpenUnicodeBuffer(chName);
-
-    SString locale;
-    MetaData.szLocale = locale.OpenUnicodeBuffer(MetaData.cbLocale);
-
-    SBuffer proc;
-    MetaData.rProcessor = (DWORD *) proc.OpenRawBuffer(MetaData.ulProcessor*sizeof(*MetaData.rProcessor));
-
-    SBuffer os;
-    MetaData.rOS = (OSINFO *) os.OpenRawBuffer(MetaData.ulOS*sizeof(*MetaData.rOS));
-
-    IfFailThrow(pAssemblyImport->GetAssemblyProps(TokenFromRid(1, mdtAssembly),
-                                                  &pbPublicKey, &cbPublicKey, &ulHashAlgId,
-                                                  szName, chName, &chName,
-                                                  &MetaData, &dwAssemblyFlags));
-
-    mdAssembly ad;
-    IfFailThrow(pAssemblyEmit->DefineAssembly(pbPublicKey, cbPublicKey, ulHashAlgId,
-                                              szName, &MetaData, dwAssemblyFlags, &ad));
+    HRESULT hr = S_OK;
 
-    SafeComHolder<IMetaDataImport> pImport;
-    IfFailThrow(pAssemblyEmit->QueryInterface(IID_IMetaDataImport, (void**)&pImport));
-    ULONG cExistingName = 0;
-    if (FAILED(pImport->GetScopeProps(NULL, 0, &cExistingName, NULL)) || cExistingName == 0)
-    {
-        SafeComHolder<IMetaDataEmit> pEmit;
-        IfFailThrow(pAssemblyEmit->QueryInterface(IID_IMetaDataEmit, (void**)&pEmit));
-        IfFailThrow(pEmit->SetModuleProps(szName));
+    if (g_fEEInit) {
+        // Cannot call this during EE startup
+        return MSEE_E_ASSEMBLYLOADINPROGRESS;
     }
 
-    name.CloseBuffer();
-    locale.CloseBuffer();
-    proc.CloseRawBuffer();
-    os.CloseRawBuffer();
-}   // Assembly::PrepareSavingManifest
-
-
-//***********************************************************
-//
-// add a file name to the file list of this assembly. On disk only.
-//
-//***********************************************************
-mdFile Assembly::AddFile(LPCWSTR wszFileName)
-{
-    STANDARD_VM_CONTRACT;
-
-    SafeComHolder<IMetaDataAssemblyEmit> pAssemEmitter(GetOnDiskMDAssemblyEmitter());
-    mdFile          fl;
-
-    // Define File.
-    IfFailThrow( pAssemEmitter->DefineFile(
-        wszFileName,                // [IN] Name of the file.
-        0,                          // [IN] Hash Blob.
-        0,                          // [IN] Count of bytes in the Hash Blob.
-        0,                          // [IN] Flags.
-        &fl) );                     // [OUT] Returned File token.
-
-    return fl;
-}   // Assembly::AddFile
-
-
-//***********************************************************
-//
-// Set the hash value on a file table entry.
-//
-//***********************************************************
-void Assembly::SetFileHashValue(mdFile tkFile, LPCWSTR wszFullFileName)
-{
-    STANDARD_VM_CONTRACT;
-
-    SafeComHolder<IMetaDataAssemblyEmit> pAssemEmitter(GetOnDiskMDAssemblyEmitter());
+    if (!(szAssemblyName && ppIUnk && pcAssemblies))
+        return E_POINTER;
 
-    // Get the hash value.
-    SBuffer buffer;
-    PEImageHolder map(PEImage::OpenImage(StackSString(wszFullFileName)));
-    map->ComputeHash(GetHashAlgId(), buffer);
+    hr = COR_E_NOTSUPPORTED;
 
-    // Set the hash blob.
-    IfFailThrow( pAssemEmitter->SetFileProps(
-        tkFile,                 // [IN] File Token.
-        buffer,                 // [IN] Hash Blob.
-        buffer.GetSize(),       // [IN] Count of bytes in the Hash Blob.
-        (DWORD) -1));           // [IN] Flags.
+    return hr;
+}// Used by the IMetadata API's to access an assemblies metadata.
 
-}   // Assembly::SetHashValue
+#ifdef FEATURE_LOADER_OPTIMIZATION
 
-//*****************************************************************************
-// Add a Type name to the ExportedType table in the on-disk assembly manifest.
-//*****************************************************************************
-mdExportedType Assembly::AddExportedTypeOnDisk(LPCWSTR wszExportedType, mdToken tkImpl, mdToken tkTypeDef, CorTypeAttr flags)
+void Assembly::SetMissingDependenciesCheckDone()
 {
-    STANDARD_VM_CONTRACT;
-
-    _ASSERTE(TypeFromToken(tkTypeDef) == mdtTypeDef);
-
-    // The on-disk assembly manifest
-    SafeComHolder<IMetaDataAssemblyEmit> pAssemEmitter(GetOnDiskMDAssemblyEmitter());
-
-    mdExportedType ct;
-
-    IfFailThrow( pAssemEmitter->DefineExportedType(
-        wszExportedType,            // [IN] Name of the COMType.
-        tkImpl,                     // [IN] mdFile or mdAssemblyRef that provides the ExportedType.
-        tkTypeDef,                  // [IN] TypeDef token within the file.
-        flags,                      // [IN] Flags.
-        &ct) );                     // [OUT] Returned ExportedType token.
-
-    return ct;
-} // Assembly::AddExportedTypeOnDisk
+    LIMITED_METHOD_CONTRACT;
+    m_bMissingDependenciesCheckDone=TRUE;
+};
 
-//*******************************************************************************
-// Add a Type name to the ExportedType table in the in-memory assembly manifest.
-//*******************************************************************************
-mdExportedType Assembly::AddExportedTypeInMemory(LPCWSTR wszExportedType, mdToken tkImpl, mdToken tkTypeDef, CorTypeAttr flags)
+BOOL Assembly::MissingDependenciesCheckDone()
 {
-    STANDARD_VM_CONTRACT;
-
-    _ASSERTE(TypeFromToken(tkTypeDef) == mdtTypeDef);
-
-    // The in-memory assembly manifest
-    IMetaDataAssemblyEmit* pAssemEmitter = GetManifestFile()->GetAssemblyEmitter();
-
-    mdExportedType ct;
-
-    IfFailThrow( pAssemEmitter->DefineExportedType(
-        wszExportedType,            // [IN] Name of the COMType.
-        tkImpl,                     // [IN] mdFile or mdAssemblyRef that provides the ExportedType.
-        tkTypeDef,                  // [IN] TypeDef token within the file.
-        flags,                      // [IN] Flags.
-        &ct) );                     // [OUT] Returned ExportedType token.
-
-    return ct;
-} // Assembly::AddExportedTypeInMemory
+    LIMITED_METHOD_CONTRACT;
+    return m_bMissingDependenciesCheckDone;
+};
 
 
-//***********************************************************
-// add an entry to ManifestResource table for a stand alone managed resource. On disk only.
-//***********************************************************
-void Assembly::AddStandAloneResource(LPCWSTR wszName, LPCWSTR wszDescription, LPCWSTR wszMimeType, LPCWSTR wszFileName, LPCWSTR wszFullFileName, int iAttribute)
+#ifdef FEATURE_FUSION
+void Assembly::SetBindingClosure(IAssemblyBindingClosure* pClosure) // Addrefs. It is assumed the caller did not addref pClosure for us.
 {
-    STANDARD_VM_CONTRACT;
-
-    SafeComHolder<IMetaDataAssemblyEmit> pAssemEmitter(GetOnDiskMDAssemblyEmitter());
-    mdFile          tkFile;
-    mdManifestResource mr;
-    SBuffer         hash;
-
-    // Get the hash value;
-    if (GetHashAlgId())
+    CONTRACTL
     {
-        PEImageHolder pImage(PEImage::OpenImage(StackSString(wszFullFileName)));
-        pImage->ComputeHash(GetHashAlgId(), hash);
+        THROWS;
+        GC_NOTRIGGER;
+        INJECT_FAULT(COMPlusThrowOM(););
     }
+    CONTRACTL_END;
 
-    IfFailThrow( pAssemEmitter->DefineFile(
-        wszFileName,            // [IN] Name of the file.
-        hash,                   // [IN] Hash Blob.
-        hash.GetSize(),         // [IN] Count of bytes in the Hash Blob.
-        ffContainsNoMetaData,   // [IN] Flags.
-        &tkFile) );             // [OUT] Returned File token.
-
-
-    IfFailThrow( pAssemEmitter->DefineManifestResource(
-        wszName,                // [IN] Name of the resource.
-        tkFile,                 // [IN] mdFile or mdAssemblyRef that provides the resource.
-        0,                      // [IN] Offset to the beginning of the resource within the file.
-        iAttribute,             // [IN] Flags.
-        &mr) );                 // [OUT] Returned ManifestResource token.
-
-}   // Assembly::AddStandAloneResource
-
-
-//***********************************************************
-// Save security permission requests.
-//***********************************************************
-void Assembly::AddDeclarativeSecurity(DWORD dwAction, void const *pValue, DWORD cbValue)
-{
-    STANDARD_VM_CONTRACT;
-
-    mdAssembly tkAssembly = 0x20000001;
-
-    SafeComHolder<IMetaDataAssemblyEmit> pAssemEmitter(GetOnDiskMDAssemblyEmitter());
-    _ASSERTE( pAssemEmitter );
-
-    SafeComHolder<IMetaDataEmitHelper> pEmitHelper;
-    IfFailThrow( pAssemEmitter->QueryInterface(IID_IMetaDataEmitHelper, (void**)&pEmitHelper) );
+    _ASSERTE(m_pBindingClosure == NULL);
+    _ASSERTE(pClosure != NULL);
 
-    IfFailThrow(pEmitHelper->AddDeclarativeSecurityHelper(tkAssembly,
-                                                          dwAction,
-                                                          pValue,
-                                                          cbValue,
-                                                          NULL));
+    m_pBindingClosure = pClosure;
+    pClosure->AddRef(); // It is assumed the caller did not addref pBindingClosure for us.
 }
 
-
-//***********************************************************
-// Allocate space for a strong name signature in the manifest
-//***********************************************************
-HRESULT Assembly::AllocateStrongNameSignature(ICeeFileGen  *pCeeFileGen,
-                                              HCEEFILE      ceeFile)
+IAssemblyBindingClosure * Assembly::GetBindingClosure()
 {
-    CONTRACTL
-    {
-        NOTHROW;
-        GC_TRIGGERS;
-        MODE_PREEMPTIVE;
-        INJECT_FAULT(return E_OUTOFMEMORY;);
-    }
-    CONTRACTL_END
-    
-    HRESULT     hr;
-    HCEESECTION TData;
-    DWORD       dwDataOffset;
-    DWORD       dwDataLength;
-    DWORD       dwDataRVA;
-    VOID       *pvBuffer;
-    const void *pbPublicKey;
-    ULONG       cbPublicKey;
-    
-    // Determine size of signature blob.
-    
-    IfFailRet(GetManifestImport()->GetAssemblyProps(TokenFromRid(1, mdtAssembly),
-                                          &pbPublicKey, &cbPublicKey, NULL,
-                                          NULL, NULL, NULL));
-    
-    if (!StrongNameSignatureSize((BYTE *) pbPublicKey, cbPublicKey, &dwDataLength)) {
-        hr = StrongNameErrorInfo();
-        return hr;
-    }
-    
-    // Allocate space for the signature in the text section and update the COM+
-    // header to point to the space.
-    IfFailRet(pCeeFileGen->GetIlSection(ceeFile, &TData));
-    IfFailRet(pCeeFileGen->GetSectionDataLen(TData, &dwDataOffset));
-    IfFailRet(pCeeFileGen->GetSectionBlock(TData, dwDataLength, 4, &pvBuffer));
-    IfFailRet(pCeeFileGen->GetMethodRVA(ceeFile, dwDataOffset, &dwDataRVA));
-    IfFailRet(pCeeFileGen->SetStrongNameEntry(ceeFile, dwDataLength, dwDataRVA));
-    
-    return S_OK;
+    LIMITED_METHOD_CONTRACT;
+    return m_pBindingClosure;
 }
 
 
-//***********************************************************
-// Strong name sign a manifest already persisted to disk
-//***********************************************************
-HRESULT Assembly::SignWithStrongName(LPCWSTR wszFileName)
+// The shared module list is effectively an extension of the shared domain assembly hash table.
+// It is the canonical list and aribiter of modules loaded from this assembly by any app domain.
+// Modules are stored here immediately on creating (to prevent duplicate creation), as opposed to
+// in the rid map, where they are only placed upon load completion.
+
+BOOL Assembly::CanBeShared(DomainAssembly *pDomainAssembly)
 {
     CONTRACTL
     {
-        NOTHROW;
+        PRECONDITION(CheckPointer(pDomainAssembly));
+        THROWS;
         GC_TRIGGERS;
-        INJECT_FAULT(return E_OUTOFMEMORY;);
+        INJECT_FAULT(COMPlusThrowOM(););
     }
-    CONTRACTL_END
-
-    HRESULT hr = S_OK;
-
-    // If we're going to do a full signing we have a key pair either
-    // in a key container or provided directly in a byte array.
+    CONTRACTL_END;
 
-    switch (m_eStrongNameLevel) {
-    case SN_FULL_KEYPAIR_IN_ARRAY:
-        if (!StrongNameSignatureGeneration(wszFileName, NULL, m_pbStrongNameKeyPair, m_cbStrongNameKeyPair, NULL, NULL))
-            hr = StrongNameErrorInfo();
-        break;
+    LOG((LF_CODESHARING,
+         LL_INFO100,
+         "Checking if we can share: \"%S\" in domain 0x%x.\n",
+         GetDebugName(), pDomainAssembly->GetAppDomain()));
 
-    case SN_FULL_KEYPAIR_IN_CONTAINER:
-        if (!StrongNameSignatureGeneration(wszFileName, m_pwStrongNameKeyContainer, NULL, 0, NULL, NULL))
-            hr = StrongNameErrorInfo();
-        break;
+    STRESS_LOG2(LF_CODESHARING, LL_INFO1000,"Checking whether DomainAssembly %p is compatible with Assembly %p",
+        pDomainAssembly,this);
 
-    default:
-        break;
-    }
-
-    return hr;
-}
-
-
-//***********************************************************
-// save the manifest to disk!
-//***********************************************************
-void Assembly::SaveManifestToDisk(LPCWSTR wszFileName, int entrypoint, int fileKind, DWORD corhFlags, DWORD peFlags)
-{
-    STANDARD_VM_CONTRACT;
-
-    HRESULT         hr = NOERROR;
-    HCEEFILE        ceeFile = NULL;
-    ICeeFileGen     *pCeeFileGen = NULL;
-    RefClassWriter  *pRCW;
-    IMetaDataEmit   *pEmitter;
-
-    _ASSERTE( m_fEmbeddedManifest == false );
-
-    pRCW = m_pOnDiskManifest->GetClassWriter();
-    _ASSERTE(pRCW);
-
-    IfFailGo( pRCW->EnsureCeeFileGenCreated(corhFlags, peFlags) );
-
-    pCeeFileGen = pRCW->GetCeeFileGen();
-    ceeFile = pRCW->GetHCEEFILE();
-    _ASSERTE(ceeFile && pCeeFileGen);
-
-    //Emit the MetaData
-    pEmitter = m_pOnDiskManifest->GetClassWriter()->GetEmitter();
-    IfFailGo( pCeeFileGen->EmitMetaDataEx(ceeFile, pEmitter) );
-
-    // Allocate space for a strong name signature if a public key was supplied
-    // (this doesn't strong name the assembly, but it makes it possible to do so
-    // as a post processing step).
-    if (IsStrongNamed())
-        IfFailGo(AllocateStrongNameSignature(pCeeFileGen, ceeFile));
-
-    IfFailGo( pCeeFileGen->SetOutputFileName(ceeFile, (LPWSTR)wszFileName) );
-
-    // the entryPoint for an assembly is a tkFile token if exist.
-    if (RidFromToken(entrypoint) != mdTokenNil)
-        IfFailGo( pCeeFileGen->SetEntryPoint(ceeFile, entrypoint) );
-    if (fileKind == Dll)
-    {
-        pCeeFileGen->SetDllSwitch(ceeFile, true);
-    }
-    else
-    {
-        // should have a valid entry point for applications
-        if (fileKind == WindowApplication)
-        {
-            IfFailGo( pCeeFileGen->SetSubsystem(ceeFile, IMAGE_SUBSYSTEM_WINDOWS_GUI, CEE_IMAGE_SUBSYSTEM_MAJOR_VERSION, CEE_IMAGE_SUBSYSTEM_MINOR_VERSION) );
-        }
-        else
-        {
-            _ASSERTE(fileKind == ConsoleApplication);
-            IfFailGo( pCeeFileGen->SetSubsystem(ceeFile, IMAGE_SUBSYSTEM_WINDOWS_CUI, CEE_IMAGE_SUBSYSTEM_MAJOR_VERSION, CEE_IMAGE_SUBSYSTEM_MINOR_VERSION) );
-        }
-
-    }
-
-    //Generate the CeeFile
-    IfFailGo(pCeeFileGen->GenerateCeeFile(ceeFile) );
-
-    // Strong name sign the resulting assembly if required.
-    if (IsStrongNamed())
-        IfFailGo(SignWithStrongName(wszFileName));
-
-    // now release the m_pOnDiskManifest
-ErrExit:
-    pRCW->DestroyCeeFileGen();
-
-    // we keep the on disk manifest so that the GetModules code can skip over this ad-hoc module when modules are enumerated.
-    // Need to see if we can remove the creation of this module alltogether
-    //m_pOnDiskManifest = NULL;
-
-    if (FAILED(hr))
-    {
-        if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
-        {
-            if (IsWin32IOError(HRESULT_CODE(hr)))
-            {
-                COMPlusThrowHR(COR_E_IO);
-            }
-            else
-            {
-                COMPlusThrowHR(hr);
-            }
-        }
-        if (hr == CEE_E_CVTRES_NOT_FOUND)
-            COMPlusThrow(kIOException, W("Argument_cvtres_NotFound"));
-        COMPlusThrowHR(hr);
-    }
-}   // Assembly::SaveManifestToDisk
-
-#endif // FEATURE_CORECLR && !CROSSGEN_COMPILE
-
-
-HRESULT STDMETHODCALLTYPE
-GetAssembliesByName(LPCWSTR  szAppBase,
-                    LPCWSTR  szPrivateBin,
-                    LPCWSTR  szAssemblyName,
-                    IUnknown *ppIUnk[],
-                    ULONG    cMax,
-                    ULONG    *pcAssemblies)
-{
-    CONTRACTL
-    {
-        NOTHROW;
-        MODE_PREEMPTIVE;
-        GC_TRIGGERS;
-        INJECT_FAULT(return E_OUTOFMEMORY;);
-    }
-    CONTRACTL_END
-
-    HRESULT hr = S_OK;
-
-    if (g_fEEInit) {
-        // Cannot call this during EE startup
-        return MSEE_E_ASSEMBLYLOADINPROGRESS;
-    }
-
-    if (!(szAssemblyName && ppIUnk && pcAssemblies))
-        return E_POINTER;
-
-#if defined(FEATURE_CORECLR) || defined(CROSSGEN_COMPILE)
-    hr = COR_E_NOTSUPPORTED;
-#else
-    AppDomain *pDomain = NULL;
-
-    BEGIN_EXTERNAL_ENTRYPOINT(&hr)
-    if(szAppBase || szPrivateBin)
-    {
-        GCX_COOP_THREAD_EXISTS(GET_THREAD());
-        MethodDescCallSite createDomainEx(METHOD__APP_DOMAIN__CREATE_DOMAINEX);
-        struct _gc {
-            STRINGREF pFriendlyName;
-            STRINGREF pAppBase;
-            STRINGREF pPrivateBin;
-        } gc;
-        ZeroMemory(&gc, sizeof(gc));
-
-        GCPROTECT_BEGIN(gc);
-        gc.pFriendlyName = StringObject::NewString(W("GetAssembliesByName"));
-
-        if(szAppBase)
-        {
-            gc.pAppBase = StringObject::NewString(szAppBase);
-        }
-            
-        if(szPrivateBin)
-        {
-            gc.pPrivateBin = StringObject::NewString(szPrivateBin);
-        }
-
-        ARG_SLOT args[5] = 
-        {
-            ObjToArgSlot(gc.pFriendlyName),
-            NULL,
-            ObjToArgSlot(gc.pAppBase),
-            ObjToArgSlot(gc.pPrivateBin),
-            BoolToArgSlot(false)
-        };
-        APPDOMAINREF pDom = (APPDOMAINREF) createDomainEx.Call_RetOBJECTREF(args);
-        if (pDom == NULL)
-        {
-            hr = E_FAIL;
-        }
-        else 
-        {
-            Context *pContext = CRemotingServices::GetServerContextForProxy((OBJECTREF) pDom);
-            _ASSERTE(pContext);
-            pDomain = pContext->GetDomain();
-        }
-
-        GCPROTECT_END();
-    }
-    else
-        pDomain = SystemDomain::System()->DefaultDomain();
-
-    Assembly *pFoundAssembly;
-    if (SUCCEEDED(hr)) {
-        pFoundAssembly = pDomain->LoadAssemblyHelper(szAssemblyName,
-                                                     NULL);
-        if (SUCCEEDED(hr)) {
-            if (cMax < 1)
-                hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
-            else {
-                ppIUnk[0] = (IUnknown *)pFoundAssembly->GetManifestAssemblyImporter();
-                ppIUnk[0]->AddRef();
-            }
-            *pcAssemblies = 1;
-        }
-    }
-
-    END_EXTERNAL_ENTRYPOINT;
-#endif // FEATURE_CORECLR
-
-    return hr;
-}// Used by the IMetadata API's to access an assemblies metadata.
-
-#ifdef FEATURE_LOADER_OPTIMIZATION
-
-void Assembly::SetMissingDependenciesCheckDone()
-{
-    LIMITED_METHOD_CONTRACT;
-    m_bMissingDependenciesCheckDone=TRUE;
-};
-
-BOOL Assembly::MissingDependenciesCheckDone()
-{
-    LIMITED_METHOD_CONTRACT;
-    return m_bMissingDependenciesCheckDone;
-};
-
-
-#ifdef FEATURE_FUSION
-void Assembly::SetBindingClosure(IAssemblyBindingClosure* pClosure) // Addrefs. It is assumed the caller did not addref pClosure for us.
-{
-    CONTRACTL
-    {
-        THROWS;
-        GC_NOTRIGGER;
-        INJECT_FAULT(COMPlusThrowOM(););
-    }
-    CONTRACTL_END;
-
-    _ASSERTE(m_pBindingClosure == NULL);
-    _ASSERTE(pClosure != NULL);
-
-    m_pBindingClosure = pClosure;
-    pClosure->AddRef(); // It is assumed the caller did not addref pBindingClosure for us.
-}
-
-IAssemblyBindingClosure * Assembly::GetBindingClosure()
-{
-    LIMITED_METHOD_CONTRACT;
-    return m_pBindingClosure;
-}
-
-
-// The shared module list is effectively an extension of the shared domain assembly hash table.
-// It is the canonical list and aribiter of modules loaded from this assembly by any app domain.
-// Modules are stored here immediately on creating (to prevent duplicate creation), as opposed to
-// in the rid map, where they are only placed upon load completion.
-
-BOOL Assembly::CanBeShared(DomainAssembly *pDomainAssembly)
-{
-    CONTRACTL
-    {
-        PRECONDITION(CheckPointer(pDomainAssembly));
-        THROWS;
-        GC_TRIGGERS;
-        INJECT_FAULT(COMPlusThrowOM(););
-    }
-    CONTRACTL_END;
-
-    LOG((LF_CODESHARING,
-         LL_INFO100,
-         "Checking if we can share: \"%S\" in domain 0x%x.\n",
-         GetDebugName(), pDomainAssembly->GetAppDomain()));
-
-    STRESS_LOG2(LF_CODESHARING, LL_INFO1000,"Checking whether DomainAssembly %p is compatible with Assembly %p",
-        pDomainAssembly,this);
-
-    // We must always share the same system assemblies
-    if (IsSystem())
-    {
-        STRESS_LOG0(LF_CODESHARING, LL_INFO1000,"System assembly - sharing");
-        return TRUE;
+    // We must always share the same system assemblies
+    if (IsSystem())
+    {
+        STRESS_LOG0(LF_CODESHARING, LL_INFO1000,"System assembly - sharing");
+        return TRUE;
     }
 
     if ((pDomainAssembly->GetDebuggerInfoBits()&~(DACF_PDBS_COPIED|DACF_IGNORE_PDBS|DACF_OBSOLETE_TRACK_JIT_INFO))
@@ -4296,365 +3560,6 @@ IWinMDImport *Assembly::GetManifestWinMDImport()
 
 #endif // FEATURE_COMINTEROP
 
-#if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE)
-void Assembly::GenerateBreadcrumbForServicing()
-{
-    STANDARD_VM_CONTRACT;
-
-    if (AppX::IsAppXProcess() || IsIntrospectionOnly() || GetManifestFile()->IsDynamic())
-    {
-        return;
-    }
-
-    if (HasServiceableAttribute() || IsExistingOobAssembly())
-    {
-        StackSString ssDisplayName;
-        GetDisplayName(ssDisplayName);
-
-        WriteBreadcrumb(ssDisplayName);
-        CheckDenyList(ssDisplayName);
-    }
-}
-
-void Assembly::WriteBreadcrumb(const SString &ssDisplayName)
-{
-    STANDARD_VM_CONTRACT;
-
-    WCHAR path[MAX_LONGPATH];
-    HRESULT hr = WszSHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, ARRAYSIZE(path), path);
-    if (hr != S_OK)
-    {
-        return;
-    }
-
-    if (wcscat_s(path, W("\\Microsoft\\NetFramework\\BreadcrumbStore\\")) != 0)
-    {
-        return;
-    }
-
-    size_t dirPathLen = wcslen(path);
-
-    // Validate the display name.  E.g., we don't want the display name to start with "..\\".
-    bool inSimpleName = true;
-    for (SString::CIterator it = ssDisplayName.Begin(); it != ssDisplayName.End(); ++it)
-    {
-        WCHAR c = *it;
-
-        // The following characters are always allowed: a-zA-Z0-9_
-        if (c >= W('a') && c <= W('z') || c >= W('A') && c <= W('Z') || c >= W('0') && c <= W('9') || c == W('_')) continue;
-
-        // The period is allowed except as the first char.
-        if (c == W('.') && it != ssDisplayName.Begin()) continue;
-
-        // A comma terminates the assembly simple name, and we are in key=value portion of the display name.
-        if (c == W(','))
-        {
-            inSimpleName = false;
-            continue;
-        }
-
-        // In key=value portion, space and equal sign are also allowed.
-        if (!inSimpleName && (c == W(' ') || c == W('='))) continue;
-
-        // If we reach here, we have an invalid assembly display name. Return without writing breadcrumb.
-        return;
-    }
-
-    // Log a breadcrumb using full display name.
-    if (wcscat_s(path, ssDisplayName.GetUnicode()) == 0)
-    {
-        HandleHolder hFile = WszCreateFile(path, 0, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
-    }
-
-    // Log another breadcrumb using display name without version.
-    // First make a copy of the display name, and look for its version part.
-    StackSString ssNoVersion(ssDisplayName);
-    SString::Iterator itVersion = ssNoVersion.Begin();
-    if (!ssNoVersion.Find(itVersion, W(", Version=")))
-    {
-        return;
-    }
-
-    // Start from the comma before Version=, advance past the comma, then look for the next comma.
-    SString::Iterator itVersionEnd = itVersion;
-    ++itVersionEnd;
-    if (!ssNoVersion.Find(itVersionEnd, W(',')))
-    {
-        // Version is the last key=value pair.
-        itVersionEnd = ssNoVersion.End();
-    }
-
-    // Erase the version.
-    ssNoVersion.Delete(itVersion, itVersionEnd - itVersion);
-
-    // Generate the full path string and create the file.
-    path[dirPathLen] = W('\0');
-    if (wcscat_s(path, ssNoVersion.GetUnicode()) == 0)
-    {
-        HandleHolder hFile = WszCreateFile(path, 0, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
-    }
-
-}
-
-bool Assembly::HasServiceableAttribute()
-{
-    STANDARD_VM_CONTRACT;
-
-    IMDInternalImport *pImport = GetManifestImport();
-    MDEnumHolder hEnum(pImport);
-    HRESULT hr = pImport->EnumCustomAttributeByNameInit(GetManifestToken(), ASSEMBLY_METADATA_TYPE, &hEnum);
-    if (hr != S_OK)
-    {
-        return false;
-    }
-
-    mdCustomAttribute tkAttribute;
-    while (pImport->EnumNext(&hEnum, &tkAttribute))
-    {
-        // Get raw custom attribute.
-        const BYTE  *pbAttr = NULL;         // Custom attribute data as a BYTE*.
-        ULONG cbAttr = 0;                   // Size of custom attribute data.
-        if (FAILED(pImport->GetCustomAttributeAsBlob(tkAttribute, reinterpret_cast<const void **>(&pbAttr), &cbAttr)))
-        {
-            THROW_BAD_FORMAT(BFA_INVALID_TOKEN, GetManifestModule());
-        }
-
-        CustomAttributeParser cap(pbAttr, cbAttr);
-        if (FAILED(cap.ValidateProlog()))
-        {
-            THROW_BAD_FORMAT(BFA_BAD_CA_HEADER, GetManifestModule());
-        }
-
-        // Get the metadata key. It is not null terminated.
-        LPCUTF8 key;
-        ULONG   cbKey;
-        if (FAILED(cap.GetString(&key, &cbKey)))
-        {
-            THROW_BAD_FORMAT(BFA_BAD_CA_HEADER, GetManifestModule());
-        }
-
-        const LPCUTF8 szServiceable = "Serviceable";
-        const ULONG cbServiceable = 11;
-        if (cbKey != cbServiceable || strncmp(key, szServiceable, cbKey) != 0)
-        {
-            continue;
-        }
-
-        // Get the metadata value. It is not null terminated.
-        if (FAILED(cap.GetString(&key, &cbKey)))
-        {
-            THROW_BAD_FORMAT(BFA_BAD_CA_HEADER, GetManifestModule());
-        }
-
-        const LPCUTF8 szTrue = "True";
-        const ULONG cbTrue = 4;
-        if (cbKey == cbTrue && strncmp(key, szTrue, cbKey) == 0)
-        {
-            return true;
-        }
-    }
-
-    return false;
-}
-
-bool Assembly::IsExistingOobAssembly()
-{
-    WRAPPER_NO_CONTRACT;
-
-    return ExistingOobAssemblyList::Instance()->IsOnlist(this);
-}
-
-void Assembly::CheckDenyList(const SString &ssDisplayName)
-{
-    STANDARD_VM_CONTRACT;
-
-    StackSString ssKeyName(W("SOFTWARE\\Microsoft\\.NETFramework\\Policy\\DenyList\\"));
-
-    ssKeyName.Append(ssDisplayName);
-
-    RegKeyHolder hKey;
-    LONG status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ssKeyName.GetUnicode(), 0, KEY_WOW64_64KEY | GENERIC_READ, &hKey);
-
-    if (status != ERROR_SUCCESS)
-    {
-        return;
-    }
-
-    StackSString ssFwlink;
-    HRESULT hr = Clr::Util::Reg::ReadStringValue(hKey, NULL, NULL, ssFwlink);
-    if (FAILED(hr) || ssFwlink.GetCount() == 0)
-    {
-        ssFwlink.Set(W("http://go.microsoft.com/fwlink/?LinkID=286319"));
-    }
-
-    StackSString ssMessageTemplate;
-    if(!ssMessageTemplate.LoadResource(CCompRC::Optional, IDS_EE_ASSEMBLY_ON_DENY_LIST))
-    {
-        ssMessageTemplate.Set(W("The assembly %1 that the application tried to load has a known vulnerability. Please go to %2 to find a fix for this issue."));
-    }
-
-    StackSString ssMessage;
-    ssMessage.FormatMessage(FORMAT_MESSAGE_FROM_STRING, ssMessageTemplate.GetUnicode(), 0, 0, ssDisplayName, ssFwlink);
-
-    ClrReportEvent(
-        W(".NET Runtime"),            // Event source
-        EVENTLOG_ERROR_TYPE,        // Type
-        0,                          // Category
-        SecurityConfig,             // Event ID
-        NULL,                       // User SID
-        ssMessage.GetUnicode());    // Message
-
-    NewHolder<EEMessageException> pEx(new EEMessageException(kSecurityException, IDS_EE_ASSEMBLY_ON_DENY_LIST, ssDisplayName.GetUnicode(), ssFwlink.GetUnicode()));
-    EEFileLoadException::Throw(m_pManifestFile, pEx->GetHR(), pEx);
-}
-
-BOOL IsReportableAssembly(PEAssembly *pPEAssembly)
-{
-    STANDARD_VM_CONTRACT;
-
-    // If the assembly could have used a native image, but did not, report the IL image
-    BOOL fCanUseNativeImage = (pPEAssembly->HasHostAssembly() || pPEAssembly->IsContextLoad()) && 
-                               pPEAssembly->CanUseNativeImage() && 
-                               !IsNativeImageOptedOut(pPEAssembly->GetFusionAssemblyName());
-
-    return fCanUseNativeImage;
-}
-
-BOOL Assembly::SupportsAutoNGenWorker()
-{
-    STANDARD_VM_CONTRACT;
-
-    PEAssembly *pPEAssembly = GetManifestFile();
-
-    if (pPEAssembly->IsSourceGAC() && Fusion::Util::IsUnifiedAssembly(pPEAssembly->GetFusionAssemblyName()) == S_OK)
-    {
-        // Assemblies in the .NET Framework supports Auto NGen.
-        return TRUE;
-    }
-
-    if (IsAfContentType_WindowsRuntime(GetFlags()))
-    {
-        // WinMD files support Auto NGen.
-        return TRUE;
-    }
-    
-    if (pPEAssembly->HasHostAssembly())
-    {
-        // Auto NGen is enabled on all Metro app assemblies.
-        return TRUE;
-    }
-
-    if (pPEAssembly->IsSourceGAC())
-    {
-        // For non-framework assemblies in GAC, look for TargetFrameworkAttriute.
-        const BYTE  *pbAttr;                // Custom attribute data as a BYTE*.
-        ULONG       cbAttr;                 // Size of custom attribute data.
-        HRESULT hr = GetManifestImport()->GetCustomAttributeByName(GetManifestToken(), TARGET_FRAMEWORK_TYPE, (const void**)&pbAttr, &cbAttr);
-        if (hr != S_OK)
-        {
-            return FALSE;
-        }
-
-        CustomAttributeParser cap(pbAttr, cbAttr);
-        if (FAILED(cap.ValidateProlog()))
-        {
-            THROW_BAD_FORMAT(BFA_BAD_CA_HEADER, GetManifestModule());
-        }
-        LPCUTF8 lpTargetFramework;
-        ULONG cbTargetFramework;
-        if (FAILED(cap.GetString(&lpTargetFramework, &cbTargetFramework)))
-        {
-            THROW_BAD_FORMAT(BFA_BAD_CA_HEADER, GetManifestModule());
-        }
-
-        if (lpTargetFramework == NULL || cbTargetFramework == 0)
-        {
-            return FALSE;
-        }
-
-        SString ssTargetFramework(SString::Utf8, lpTargetFramework, cbTargetFramework);
-
-        // Look for two special TargetFramework values that disables AutoNGen.  To guard against future
-        // variations of the string values, we do prefix matches.
-        SString ssFramework40(SString::Literal, W(".NETFramework,Version=v4.0"));
-        SString ssPortableLib(SString::Literal, W(".NETPortable,"));
-        if (ssTargetFramework.BeginsWithCaseInsensitive(ssFramework40) || ssTargetFramework.BeginsWithCaseInsensitive(ssPortableLib))
-        {
-            return FALSE;
-        }
-
-        // If TargetFramework doesn't match one of the two special values, we enable Auto NGen.
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-void Assembly::ReportAssemblyUse()
-{
-    STANDARD_VM_CONTRACT;
-
-    // Do not log if we don't have a global gac logger object
-    if (g_pIAssemblyUsageLogGac != NULL)
-    {
-        // Only consider reporting for loads that could possibly use native images.
-        PEAssembly *pPEAssembly = this->GetManifestFile();
-        if (IsReportableAssembly(pPEAssembly) && !pPEAssembly->IsReportedToUsageLog())
-        {
-            // Do not log repeatedly
-            pPEAssembly->SetReportedToUsageLog();
-
-            ReleaseHolder<IAssemblyUsageLog> pRefCountedUsageLog;
-            IAssemblyUsageLog *pUsageLog = NULL;
-            if (SupportsAutoNGen())
-            {
-                if (pPEAssembly->IsSourceGAC())
-                {
-                    pUsageLog = g_pIAssemblyUsageLogGac;
-                }
-                else if (pPEAssembly->HasHostAssembly())
-                {
-                    UINT_PTR binderId;
-                    IfFailThrow(pPEAssembly->GetHostAssembly()->GetBinderID(&binderId));
-                    pRefCountedUsageLog = AssemblyUsageLogManager::GetUsageLogForBinder(binderId);
-                    pUsageLog = pRefCountedUsageLog;
-                }
-            }
-
-            if (pUsageLog)
-            {
-                PEAssembly *pPEAssembly = GetManifestFile();
-                StackSString name;
-                // GAC Assemblies are reported by assembly name
-                if (pUsageLog == g_pIAssemblyUsageLogGac)
-                {
-                    this->GetDisplayName(name);
-                }
-                // Other assemblies (AppX...) are reported by file path
-                else
-                {
-                    name.Set(pPEAssembly->GetILimage()->GetPath().GetUnicode());
-                }
-
-                if (pPEAssembly->HasNativeImage())
-                {
-                    if(!IsSystem())
-                    {
-                        // If the assembly used a native image, report it
-                        ReleaseHolder<PEImage> pNativeImage = pPEAssembly->GetNativeImageWithRef();
-                        pUsageLog->LogFile(name.GetUnicode(), pNativeImage->GetPath().GetUnicode(), ASSEMBLY_USAGE_LOG_FLAGS_NI);
-                    }
-                }
-                else
-                {
-                    // If the assembly could have used a native image, but did not, report the IL image
-                    pUsageLog->LogFile(name.GetUnicode(), NULL, ASSEMBLY_USAGE_LOG_FLAGS_IL);
-                }
-            }
-        }
-    }
-}
-#endif // FEATURE_CORECLR && !CROSSGEN_COMPILE
 
 #endif // #ifndef DACCESS_COMPILE
 
@@ -4857,31 +3762,6 @@ FriendAssemblyDescriptor *FriendAssemblyDescriptor::CreateFriendAssemblyDescript
 
             // CoreCLR does not have a valid scenario for strong-named assemblies requiring their dependencies
             // to be strong-named as well.
-#if !defined(FEATURE_CORECLR)        
-            // If this assembly has a strong name, then its friends declarations need to have strong names too
-            if (pAssembly->IsStrongNamed())
-            {
-#ifdef FEATURE_FUSION        
-                DWORD dwSize = 0;
-                if (SUCCEEDED(hr = pFriendAssemblyName->GetProperty(ASM_NAME_PUBLIC_KEY, NULL, &dwSize)))
-                {
-                    // If this call succeeds with an empty buffer, then the supplied name doesn't have a public key.
-                    THROW_HR_ERROR_WITH_INFO(META_E_CA_FRIENDS_SN_REQUIRED, pAssembly);
-                }
-                else if (hr != HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER))
-                {
-                    IfFailThrow(hr);
-                }
-#else // FEATURE_FUSION
-                // Desktop crossgen comes here
-                if (!pFriendAssemblyName->IsStrongNamed())
-                {
-                    // If this call succeeds with an empty buffer, then the supplied name doesn't have a public key.
-                    THROW_HR_ERROR_WITH_INFO(META_E_CA_FRIENDS_SN_REQUIRED, pAssembly);
-                }
-#endif // FEATURE_FUSION            
-            }
-#endif // !defined(FEATURE_CORECLR)
 
             pFriendAssemblies->AddFriendAssembly(pFriendAssemblyName);
 
@@ -4974,70 +3854,3 @@ bool FriendAssemblyDescriptor::IsAssemblyOnList(PEAssembly *pAssembly, const Arr
 #endif // !DACCESS_COMPILE
 
 
-#if !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE) && !defined(DACCESS_COMPILE)
-
-ExistingOobAssemblyList::ExistingOobAssemblyList()
-{
-    STANDARD_VM_CONTRACT;
-
-    RegKeyHolder hKey;
-    LONG status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, W("SOFTWARE\\Microsoft\\.NETFramework\\Policy\\Servicing"), 0, KEY_WOW64_64KEY | GENERIC_READ, &hKey);
-    if (status != ERROR_SUCCESS)
-    {
-        return;
-    }
-
-    for (DWORD i = 0; ; i++)
-    {
-        WCHAR name[MAX_PATH_FNAME + 1];
-        DWORD cchName = ARRAYSIZE(name);
-        status = RegEnumKeyExW(hKey, i, name, &cchName, NULL, NULL, NULL, NULL);
-
-        if (status == ERROR_NO_MORE_ITEMS)
-        {
-            break;
-        }
-
-        if (status == ERROR_SUCCESS)
-        {
-            NonVMComHolder<IAssemblyName> pAssemblyName;
-            HRESULT hr = CreateAssemblyNameObject(&pAssemblyName, name, CANOF_PARSE_DISPLAY_NAME, NULL);
-            if (SUCCEEDED(hr))
-            {
-                hr = m_alExistingOobAssemblies.Append(pAssemblyName.GetValue());
-                if (SUCCEEDED(hr))
-                {
-                    pAssemblyName.SuppressRelease();
-                }
-            }
-        }
-    }
-}
-
-bool ExistingOobAssemblyList::IsOnlist(Assembly *pAssembly)
-{
-    STANDARD_VM_CONTRACT;
-
-    ArrayList::Iterator itAssemblyNames = m_alExistingOobAssemblies.Iterate();
-    while (itAssemblyNames.Next())
-    {
-        IAssemblyName *pAssemblyName = static_cast<IAssemblyName *>(itAssemblyNames.GetElement());
-        HRESULT hr = pAssemblyName->IsEqual(pAssembly->GetFusionAssemblyName(), ASM_CMPF_DEFAULT);
-        if (hr == S_OK)
-        {
-            return true;
-        }
-    }
-
-    return false;
-}
-
-void ExistingOobAssemblyList::Init()
-{
-    STANDARD_VM_CONTRACT;
-
-    s_pInstance = new ExistingOobAssemblyList();
-}
-
-ExistingOobAssemblyList *ExistingOobAssemblyList::s_pInstance;
-#endif // !defined(FEATURE_CORECLR) && !defined(CROSSGEN_COMPILE) && !defined(DACCESS_COMPILE)