@@ -1060,6 +1060,7 @@ type PEReader =
10601060 resourcesAddr: int32
10611061 strongnameAddr: int32
10621062 vtableFixupsAddr: int32
1063+ noFileOnDisk: bool
10631064}
10641065
10651066[<NoEquality; NoComparison; RequireQualifiedAccess>]
@@ -1537,11 +1538,25 @@ let readBlobHeapAsDouble ctxt vidx = fst (sigptrGetDouble (readBlobHeap ctxt vid
15371538// (e) the start of the native resources attached to the binary if any
15381539// ----------------------------------------------------------------------*)
15391540
1540- let readNativeResources ( pectxt : PEReader ) =
1541+ // noFileOnDisk indicates that the PE file was read from Memory using OpenILModuleReaderFromBytes
1542+ // For example the assembly came from a type provider
1543+ // In this case we eagerly read the native resources into memory
1544+ let readNativeResources ( pectxt : PEReader ) =
15411545[ if pectxt.nativeResourcesSize<> 0x0 && pectxt.nativeResourcesAddr<> 0x0 then
1542- let start = pectxt.anyV2P( pectxt.fileName+ " : native resources" , pectxt.nativeResourcesAddr)
1543- yield ILNativeResource.In( pectxt.fileName, pectxt.nativeResourcesAddr, start, pectxt.nativeResourcesSize) ]
1544-
1546+ let start = pectxt.anyV2P( pectxt.fileName+ " : native resources" , pectxt.nativeResourcesAddr)
1547+ if pectxt.noFileOnDiskthen
1548+ #if ! FX_ NO_ LINKEDRESOURCES
1549+ let unlinkedResource =
1550+ let linkedResource = seekReadBytes( pectxt.pefile.GetView()) start pectxt.nativeResourcesSize
1551+ unlinkResource pectxt.nativeResourcesAddr linkedResource
1552+ yield ILNativeResource.Out unlinkedResource
1553+ #else
1554+ ()
1555+ #endif
1556+ else
1557+ yield ILNativeResource.In( pectxt.fileName, pectxt.nativeResourcesAddr, start, pectxt.nativeResourcesSize) ]
1558+
1559+
15451560let getDataEndPointsDelayed ( pectxt : PEReader ) ctxtH =
15461561lazy
15471562let ( ctxt : ILMetadataReader ) = getHole ctxtH
@@ -3688,7 +3703,7 @@ let openMetadataReader (fileName, mdfile: BinaryFile, metadataPhysLoc, peinfo, p
36883703// read of the AbsIL module.
36893704// ----------------------------------------------------------------------
36903705
3691- let openPEFileReader ( fileName , pefile : BinaryFile , pdbPath ) =
3706+ let openPEFileReader ( fileName , pefile : BinaryFile , pdbPath , noFileOnDisk ) =
36923707let pev = pefile.GetView()
36933708(* MSDOS HEADER*)
36943709let peSignaturePhysLoc = seekReadInt32 pev0x3c
@@ -3881,12 +3896,13 @@ let openPEFileReader (fileName, pefile: BinaryFile, pdbPath) =
38813896 pefile= pefile
38823897 fileName= fileName
38833898 entryPointToken= entryPointToken
3899+ noFileOnDisk= noFileOnDisk
38843900}
38853901let peinfo = ( subsys, ( subsysMajor, subsysMinor), useHighEnthropyVA, ilOnly, only32, is32bitpreferred, only64, platform, isDll, alignVirt, alignPhys, imageBaseReal)
38863902( metadataPhysLoc, metadataSize, peinfo, pectxt, pev, pdb)
38873903
3888- let openPE ( fileName , pefile , pdbPath , reduceMemoryUsage , ilGlobals ) =
3889- let ( metadataPhysLoc , _metadataSize , peinfo , pectxt , pev , pdb ) = openPEFileReader( fileName, pefile, pdbPath)
3904+ let openPE ( fileName , pefile , pdbPath , reduceMemoryUsage , ilGlobals , noFileOnDisk ) =
3905+ let ( metadataPhysLoc , _metadataSize , peinfo , pectxt , pev , pdb ) = openPEFileReader( fileName, pefile, pdbPath, noFileOnDisk )
38903906let ilModule , ilAssemblyRefs = openMetadataReader( fileName, pefile, metadataPhysLoc, peinfo, pectxt, pev, Some pectxt, reduceMemoryUsage, ilGlobals)
38913907 ilModule, ilAssemblyRefs, pdb
38923908
@@ -3963,7 +3979,7 @@ let tryMemoryMapWholeFile opts fileName =
39633979
39643980let OpenILModuleReaderFromBytes fileName bytes opts =
39653981let pefile = ByteFile( fileName, bytes) :> BinaryFile
3966- let ilModule , ilAssemblyRefs , pdb = openPE( fileName, pefile, opts.pdbPath, ( opts.reduceMemoryUsage= ReduceMemoryFlag.Yes), opts.ilGlobals)
3982+ let ilModule , ilAssemblyRefs , pdb = openPE( fileName, pefile, opts.pdbPath, ( opts.reduceMemoryUsage= ReduceMemoryFlag.Yes), opts.ilGlobals, true )
39673983new ILModuleReader( ilModule, ilAssemblyRefs, ( fun () -> ClosePdbReader pdb))
39683984
39693985let OpenILModuleReader fileName opts =
@@ -4011,7 +4027,7 @@ let OpenILModuleReader fileName opts =
40114027// Then use the metadata blob as the long-lived memory resource.
40124028let disposer , pefileEager = tryMemoryMapWholeFile opts fullPath
40134029use _disposer= disposer
4014- let ( metadataPhysLoc , metadataSize , peinfo , pectxtEager , pevEager , _pdb ) = openPEFileReader( fullPath, pefileEager, None)
4030+ let ( metadataPhysLoc , metadataSize , peinfo , pectxtEager , pevEager , _pdb ) = openPEFileReader( fullPath, pefileEager, None, false )
40154031let mdfile =
40164032match mdfileOptwith
40174033| Some mdfile-> mdfile
@@ -4025,7 +4041,7 @@ let OpenILModuleReader fileName opts =
40254041// If we are not doing metadata-only, then just go ahead and read all the bytes and hold them either strongly or weakly
40264042// depending on the heuristic
40274043let pefile = createByteFileChunk opts fullPath None
4028- let ilModule , ilAssemblyRefs , _pdb = openPE( fullPath, pefile, None, reduceMemoryUsage, opts.ilGlobals)
4044+ let ilModule , ilAssemblyRefs , _pdb = openPE( fullPath, pefile, None, reduceMemoryUsage, opts.ilGlobals, false )
40294045new ILModuleReader( ilModule, ilAssemblyRefs, ignore)
40304046
40314047if keyOkthen
@@ -4043,7 +4059,7 @@ let OpenILModuleReader fileName opts =
40434059//
40444060// We do however care about avoiding locks on files that prevent their deletion during a
40454061// multi-proc build. So use memory mapping, but only for stable files. Other files
4046- //fill use an in-memory ByteFile
4062+ //still use an in-memory ByteFile
40474063let _disposer , pefile =
40484064if alwaysMemoryMapFSC|| stableFileHeuristicApplies fullPaththen
40494065 tryMemoryMapWholeFile opts fullPath
@@ -4052,7 +4068,7 @@ let OpenILModuleReader fileName opts =
40524068let disposer = { new IDisposablewith member __.Dispose () = () }
40534069 disposer, pefile
40544070
4055- let ilModule , ilAssemblyRefs , pdb = openPE( fullPath, pefile, opts.pdbPath, reduceMemoryUsage, opts.ilGlobals)
4071+ let ilModule , ilAssemblyRefs , pdb = openPE( fullPath, pefile, opts.pdbPath, reduceMemoryUsage, opts.ilGlobals, false )
40564072let ilModuleReader = new ILModuleReader( ilModule, ilAssemblyRefs, ( fun () -> ClosePdbReader pdb))
40574073
40584074// Readers with PDB reader disposal logic don't go in the cache. Note the PDB reader is only used in static linking.