Skip to content

Commit 2cf4826

Browse files
authored
Moved AssemblyName helpers to managed (part 2) (#63915)
* implement GetAssemblyName via dynamic call to MetadataReader * A few more file-locking tests. * fix #28153 * no need for version when getting MetadataReader * rename the argument to match AssemblyName * perf tweaks * use memory-mapped file to read metadata * adjust tests for the new implementation * use "bufferSize: 1" when stream is going to be mapped. * null-conditional operator. * do Dispose before re-throwing * get rid of the platform-specific/native stuff * remove assemblyname.hpp * remove `VerifyIsAssembly()` * PR feedback * put back gStdMngIEnumerableFuncs and the others
1 parent cbc4cd8 commit 2cf4826

File tree

29 files changed

+100
-296
lines changed

29 files changed

+100
-296
lines changed

src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@ internal AssemblyName(string? name,
3232
_flags = flags;
3333
}
3434

35-
// This call opens and closes the file, but does not add the
36-
// assembly to the domain.
37-
[MethodImpl(MethodImplOptions.InternalCall)]
38-
internal static extern AssemblyName nGetFileInformation(string s);
39-
40-
internal static AssemblyName GetFileInformationCore(string assemblyFile)
41-
{
42-
string fullPath = Path.GetFullPath(assemblyFile);
43-
return nGetFileInformation(fullPath);
44-
}
45-
4635
internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm)
4736
{
4837
#pragma warning disable SYSLIB0037 // AssemblyName.ProcessorArchitecture is obsolete

src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
<Compile Include="System\Reflection\AssemblyRuntimeNameHelpers.cs" />
130130
<Compile Include="System\Reflection\Attribute.CoreRT.cs" />
131131
<Compile Include="System\Reflection\Assembly.CoreRT.cs" />
132-
<Compile Include="System\Reflection\AssemblyName.CoreRT.cs" />
133132
<Compile Include="System\Reflection\BinderBundle.cs" />
134133
<Compile Include="System\Reflection\Emit\AssemblyBuilder.cs" />
135134
<Compile Include="System\Reflection\Emit\ConstructorBuilder.cs" />

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreRT.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static unsafe PEReader OpenPEFile(string filePath, out MemoryMappedViewAc
157157
try
158158
{
159159
// Create stream because CreateFromFile(string, ...) uses FileShare.None which is too strict
160-
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, false);
160+
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1);
161161
mappedFile = MemoryMappedFile.CreateFromFile(
162162
fileStream, null, fileStream.Length, MemoryMappedFileAccess.Read, HandleInheritability.None, true);
163163
accessor = mappedFile.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read);
@@ -174,12 +174,9 @@ public static unsafe PEReader OpenPEFile(string filePath, out MemoryMappedViewAc
174174
}
175175
finally
176176
{
177-
if (accessor != null)
178-
accessor.Dispose();
179-
if (mappedFile != null)
180-
mappedFile.Dispose();
181-
if (fileStream != null)
182-
fileStream.Dispose();
177+
accessor?.Dispose();
178+
mappedFile?.Dispose();
179+
fileStream?.Dispose();
183180
}
184181
}
185182

src/coreclr/tools/Common/TypeSystem/Ecma/SymbolReader/PortablePdbSymbolReader.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private static unsafe MetadataReader TryOpenMetadataFile(string filePath, Metada
2626
try
2727
{
2828
// Create stream because CreateFromFile(string, ...) uses FileShare.None which is too strict
29-
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, false);
29+
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1);
3030
mappedFile = MemoryMappedFile.CreateFromFile(
3131
fileStream, null, fileStream.Length, MemoryMappedFileAccess.Read, HandleInheritability.None, true);
3232

@@ -56,12 +56,9 @@ private static unsafe MetadataReader TryOpenMetadataFile(string filePath, Metada
5656
}
5757
finally
5858
{
59-
if (accessor != null)
60-
accessor.Dispose();
61-
if (mappedFile != null)
62-
mappedFile.Dispose();
63-
if (fileStream != null)
64-
fileStream.Dispose();
59+
accessor?.Dispose();
60+
mappedFile?.Dispose();
61+
fileStream?.Dispose();
6562
}
6663
}
6764

src/coreclr/tools/dotnet-pgo/TraceTypeSystemContext.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public static unsafe PEReader OpenPEFile(string filePath, byte[] moduleBytes, ou
260260
try
261261
{
262262
// Create stream because CreateFromFile(string, ...) uses FileShare.None which is too strict
263-
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, false);
263+
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1);
264264
mappedFile = MemoryMappedFile.CreateFromFile(
265265
fileStream, null, fileStream.Length, MemoryMappedFileAccess.Read, HandleInheritability.None, true);
266266
accessor = mappedFile.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read);
@@ -278,12 +278,9 @@ public static unsafe PEReader OpenPEFile(string filePath, byte[] moduleBytes, ou
278278
}
279279
finally
280280
{
281-
if (accessor != null)
282-
accessor.Dispose();
283-
if (mappedFile != null)
284-
mappedFile.Dispose();
285-
if (fileStream != null)
286-
fileStream.Dispose();
281+
accessor?.Dispose();
282+
mappedFile?.Dispose();
283+
fileStream?.Dispose();
287284
}
288285
}
289286

src/coreclr/vm/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ set(GC_HEADERS_DAC
289289
set(VM_SOURCES_WKS
290290
${VM_SOURCES_DAC_AND_WKS_COMMON}
291291
appdomainnative.cpp
292-
assemblyname.cpp
293292
assemblynative.cpp
294293
assemblyspec.cpp
295294
baseassemblyspec.cpp
@@ -392,7 +391,6 @@ set(VM_HEADERS_WKS
392391
${VM_HEADERS_DAC_AND_WKS_COMMON}
393392
../inc/jithelpers.h
394393
appdomainnative.hpp
395-
assemblyname.hpp
396394
assemblynative.hpp
397395
assemblyspec.hpp
398396
assemblyspecbase.h

src/coreclr/vm/appdomain.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "eeconfig.h"
1212
#include "gcheaputilities.h"
1313
#include "eventtrace.h"
14-
#include "assemblyname.hpp"
1514
#include "eeprofinterfaces.h"
1615
#include "dbginterface.h"
1716
#ifndef DACCESS_COMPILE

src/coreclr/vm/assembly.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
#include "assembly.hpp"
1919
#include "appdomain.hpp"
20-
#include "assemblyname.hpp"
21-
22-
2320

2421
#include "eeprofinterfaces.h"
2522
#include "reflectclasswriter.h"

src/coreclr/vm/assemblyname.cpp

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)