@@ -1066,6 +1066,7 @@ type PEReader =
10661066 resourcesAddr: int32
10671067 strongnameAddr: int32
10681068 vtableFixupsAddr: int32
1069+ noFileOnDisk: bool
10691070}
10701071
10711072[<NoEquality; NoComparison; RequireQualifiedAccess>]
@@ -1543,11 +1544,25 @@ let readBlobHeapAsDouble ctxt vidx = fst (sigptrGetDouble (readBlobHeap ctxt vid
15431544// (e) the start of the native resources attached to the binary if any
15441545// ----------------------------------------------------------------------*)
15451546
1546- let readNativeResources ( pectxt : PEReader ) =
1547+ // noFileOnDisk indicates that the PE file was read from Memory using OpenILModuleReaderFromBytes
1548+ // For example the assembly came from a type provider
1549+ // In this case we eagerly read the native resources into memory
1550+ let readNativeResources ( pectxt : PEReader ) =
15471551[ if pectxt.nativeResourcesSize<> 0x0 && pectxt.nativeResourcesAddr<> 0x0 then
1548- let start = pectxt.anyV2P( pectxt.fileName+ " : native resources" , pectxt.nativeResourcesAddr)
1549- yield ILNativeResource.In( pectxt.fileName, pectxt.nativeResourcesAddr, start, pectxt.nativeResourcesSize) ]
1550-
1552+ let start = pectxt.anyV2P( pectxt.fileName+ " : native resources" , pectxt.nativeResourcesAddr)
1553+ if pectxt.noFileOnDiskthen
1554+ #if ! FX_ NO_ LINKEDRESOURCES
1555+ let unlinkedResource =
1556+ let linkedResource = seekReadBytes( pectxt.pefile.GetView()) start pectxt.nativeResourcesSize
1557+ unlinkResource pectxt.nativeResourcesAddr linkedResource
1558+ yield ILNativeResource.Out unlinkedResource
1559+ #else
1560+ ()
1561+ #endif
1562+ else
1563+ yield ILNativeResource.In( pectxt.fileName, pectxt.nativeResourcesAddr, start, pectxt.nativeResourcesSize) ]
1564+
1565+
15511566let getDataEndPointsDelayed ( pectxt : PEReader ) ctxtH =
15521567lazy
15531568let ( ctxt : ILMetadataReader ) = getHole ctxtH
@@ -3694,7 +3709,7 @@ let openMetadataReader (fileName, mdfile: BinaryFile, metadataPhysLoc, peinfo, p
36943709// read of the AbsIL module.
36953710// ----------------------------------------------------------------------
36963711
3697- let openPEFileReader ( fileName , pefile : BinaryFile , pdbDirPath ) =
3712+ let openPEFileReader ( fileName , pefile : BinaryFile , pdbDirPath , noFileOnDisk ) =
36983713let pev = pefile.GetView()
36993714(* MSDOS HEADER*)
37003715let peSignaturePhysLoc = seekReadInt32 pev0x3c
@@ -3887,12 +3902,13 @@ let openPEFileReader (fileName, pefile: BinaryFile, pdbDirPath) =
38873902 pefile= pefile
38883903 fileName= fileName
38893904 entryPointToken= entryPointToken
3905+ noFileOnDisk= noFileOnDisk
38903906}
38913907let peinfo = ( subsys, ( subsysMajor, subsysMinor), useHighEnthropyVA, ilOnly, only32, is32bitpreferred, only64, platform, isDll, alignVirt, alignPhys, imageBaseReal)
38923908( metadataPhysLoc, metadataSize, peinfo, pectxt, pev, pdb)
38933909
3894- let openPE ( fileName , pefile , pdbDirPath , reduceMemoryUsage , ilGlobals ) =
3895- let ( metadataPhysLoc , _metadataSize , peinfo , pectxt , pev , pdb ) = openPEFileReader( fileName, pefile, pdbDirPath)
3910+ let openPE ( fileName , pefile , pdbDirPath , reduceMemoryUsage , ilGlobals , noFileOnDisk ) =
3911+ let ( metadataPhysLoc , _metadataSize , peinfo , pectxt , pev , pdb ) = openPEFileReader( fileName, pefile, pdbDirPath, noFileOnDisk )
38963912let ilModule , ilAssemblyRefs = openMetadataReader( fileName, pefile, metadataPhysLoc, peinfo, pectxt, pev, Some pectxt, reduceMemoryUsage, ilGlobals)
38973913 ilModule, ilAssemblyRefs, pdb
38983914
@@ -3969,7 +3985,7 @@ let tryMemoryMapWholeFile opts fileName =
39693985
39703986let OpenILModuleReaderFromBytes fileName bytes opts =
39713987let pefile = ByteFile( fileName, bytes) :> BinaryFile
3972- let ilModule , ilAssemblyRefs , pdb = openPE( fileName, pefile, opts.pdbDirPath, ( opts.reduceMemoryUsage= ReduceMemoryFlag.Yes), opts.ilGlobals)
3988+ let ilModule , ilAssemblyRefs , pdb = openPE( fileName, pefile, opts.pdbDirPath, ( opts.reduceMemoryUsage= ReduceMemoryFlag.Yes), opts.ilGlobals, true )
39733989new ILModuleReader( ilModule, ilAssemblyRefs, ( fun () -> ClosePdbReader pdb))
39743990
39753991let OpenILModuleReader fileName opts =
@@ -4017,7 +4033,7 @@ let OpenILModuleReader fileName opts =
40174033// Then use the metadata blob as the long-lived memory resource.
40184034let disposer , pefileEager = tryMemoryMapWholeFile opts fullPath
40194035use _disposer= disposer
4020- let ( metadataPhysLoc , metadataSize , peinfo , pectxtEager , pevEager , _pdb ) = openPEFileReader( fullPath, pefileEager, None)
4036+ let ( metadataPhysLoc , metadataSize , peinfo , pectxtEager , pevEager , _pdb ) = openPEFileReader( fullPath, pefileEager, None, false )
40214037let mdfile =
40224038match mdfileOptwith
40234039| Some mdfile-> mdfile
@@ -4031,7 +4047,7 @@ let OpenILModuleReader fileName opts =
40314047// If we are not doing metadata-only, then just go ahead and read all the bytes and hold them either strongly or weakly
40324048// depending on the heuristic
40334049let pefile = createByteFileChunk opts fullPath None
4034- let ilModule , ilAssemblyRefs , _pdb = openPE( fullPath, pefile, None, reduceMemoryUsage, opts.ilGlobals)
4050+ let ilModule , ilAssemblyRefs , _pdb = openPE( fullPath, pefile, None, reduceMemoryUsage, opts.ilGlobals, false )
40354051new ILModuleReader( ilModule, ilAssemblyRefs, ignore)
40364052
40374053if keyOkthen
@@ -4049,7 +4065,7 @@ let OpenILModuleReader fileName opts =
40494065//
40504066// We do however care about avoiding locks on files that prevent their deletion during a
40514067// multi-proc build. So use memory mapping, but only for stable files. Other files
4052- //fill use an in-memory ByteFile
4068+ //still use an in-memory ByteFile
40534069let _disposer , pefile =
40544070if alwaysMemoryMapFSC|| stableFileHeuristicApplies fullPaththen
40554071 tryMemoryMapWholeFile opts fullPath
@@ -4058,7 +4074,7 @@ let OpenILModuleReader fileName opts =
40584074let disposer = { new IDisposablewith member __.Dispose () = () }
40594075 disposer, pefile
40604076
4061- let ilModule , ilAssemblyRefs , pdb = openPE( fullPath, pefile, opts.pdbDirPath, reduceMemoryUsage, opts.ilGlobals)
4077+ let ilModule , ilAssemblyRefs , pdb = openPE( fullPath, pefile, opts.pdbDirPath, reduceMemoryUsage, opts.ilGlobals, false )
40624078let ilModuleReader = new ILModuleReader( ilModule, ilAssemblyRefs, ( fun () -> ClosePdbReader pdb))
40634079
40644080// Readers with PDB reader disposal logic don't go in the cache. Note the PDB reader is only used in static linking.