Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2018,6 +2018,9 @@
<data name="BadImageFormat_BadILFormat" xml:space="preserve">
<value>Bad IL format.</value>
</data>
<data name="BadImageFormat_EmptyAssembly" xml:space="preserve">
<value>Assembly image is empty. The stream or byte array must contain a valid PE file.</value>
</data>
<data name="BadImageFormat_InvalidType" xml:space="preserve">
<value>Corrupt .resources file. The specified type doesn't exist.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public static Assembly Load(byte[] rawAssembly, byte[]? rawSymbolStore)
ArgumentNullException.ThrowIfNull(rawAssembly);

if (rawAssembly.Length == 0)
throw new BadImageFormatException(SR.BadImageFormat_BadILFormat);
throw new BadImageFormatException(SR.BadImageFormat_EmptyAssembly);

SerializationInfo.ThrowIfDeserializationInProgress("AllowAssembliesFromByteArrays",
ref s_cachedSerializationSwitch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public Assembly LoadFromStream(Stream assembly, Stream? assemblySymbols)
ReadOnlySpan<byte> spanAssembly = ReadAllBytes(assembly);
if (spanAssembly.IsEmpty)
{
throw new BadImageFormatException(SR.BadImageFormat_BadILFormat);
throw new BadImageFormatException(SR.BadImageFormat_EmptyAssembly);
}

// Read the symbol stream if provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,9 @@ public void AssemblyLoadFromBytes()
public void AssemblyLoadFromBytesNeg()
{
Assert.Throws<ArgumentNullException>(() => Assembly.Load((byte[])null));
Assert.Throws<BadImageFormatException>(() => Assembly.Load(new byte[0]));

BadImageFormatException ex = Assert.Throws<BadImageFormatException>(() => Assembly.Load(new byte[0]));
Assert.Contains("empty", ex.Message, StringComparison.OrdinalIgnoreCase);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsAssemblyLoadingSupported), nameof(PlatformDetection.HasAssemblyFiles))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public void LoadFromStream_Location_IsEmpty()
Assert.Empty(assembly.Location);
}

[Fact]
public void LoadFromStream_EmptyStream_ThrowsBadImageFormatException()
{
using (var emptyStream = new MemoryStream())
{
BadImageFormatException ex = Assert.Throws<BadImageFormatException>(
() => AssemblyLoadContext.Default.LoadFromStream(emptyStream));
Assert.Contains("empty", ex.Message, StringComparison.OrdinalIgnoreCase);
}
}

[Fact]
public void EntryPoint()
{
Expand Down
Loading