Skip to content

Commit 5cef42e

Browse files
authored
Assembly.Location should return empty string for assemblies loaded from single-file bundle (#39275)
Changes made to PEFile to report empty string for path when it comes directly from the bundle. I experimented with changing the PEImage m_path to empty string, but way too many things break. It is valid for the m_path to be empty, but we only use it to memory-loaded assemblies where the assembly loaded via PEImage::LoadFlat which does things very differently. The bundle still relies on opening the assembly as a file (file handle and offset). The end result is that internally the assembly's PEImage has a non-existent m_path (it points to the base directory and the file name of the assembly, but no such file will normally exist). I don't think anything will actually use the path to access the file though. Also changed how we load CoreLib from bundle. We used to give it path "System.Private.CoreLib.dll" which causes asserts in the runtime in couple of places (the one I hit was when trying to load assembly from memory - it gets CoreLib as its creator and we call GetPath on the creator and then validate the path in debug builds). As far as I can tell this change should not make any observable effect, other than fixing the fact that we expect the m_path of a PEImage to be either empty or absolute path.
1 parent 9057343 commit 5cef42e

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

src/coreclr/src/binder/assemblybinder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ namespace BINDER_SPACE
396396
BundleFileLocation bundleFileLocation = Bundle::ProbeAppBundle(sCoreLibName, /*pathIsBundleRelative */ true);
397397
if (!bundleFileLocation.IsValid())
398398
{
399-
sCoreLib.Set(systemDirectory);
400399
pathSource = BinderTracing::PathSource::ApplicationAssemblies;
401400
}
401+
sCoreLib.Set(systemDirectory);
402402
CombinePath(sCoreLib, sCoreLibName, sCoreLib);
403403

404404
IF_FAIL_GO(AssemblyBinder::GetAssembly(sCoreLib,

src/coreclr/src/vm/pefile.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ inline const SString &PEFile::GetPath()
180180
}
181181
CONTRACTL_END;
182182

183-
if (IsDynamic())
183+
if (IsDynamic() || m_identity->IsInBundle ())
184184
{
185185
return SString::Empty();
186186
}

src/coreclr/src/vm/peimage.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ class PEImage
237237
// Private routines
238238
// ------------------------------------------------------------
239239

240-
void Init(LPCWSTR pPath, BundleFileLocation bundleFileLocation);
241-
void Init(IStream* pStream, UINT64 uStreamAsmId,
242-
DWORD dwModuleId, BOOL resourceFile);
240+
void Init(LPCWSTR pPath, BundleFileLocation bundleFileLocation);
243241

244242
void VerifyIsILOrNIAssembly(BOOL fIL);
245243

0 commit comments

Comments
 (0)