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 @@ -5,8 +5,7 @@ namespace System
{
public partial class BadImageFormatException
{
// Do not delete: this is invoked from native code.
private BadImageFormatException(string? fileName, int hResult)
internal BadImageFormatException(string? fileName, int hResult)
: base(null)
{
HResult = hResult;
Expand Down
30 changes: 30 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,35 @@ internal static unsafe void CreateTargetInvocationException(Exception* pInnerExc
*pException = ex;
}
}

// See clrex.cpp for native version.
internal enum ArgumentExceptionKind
{
Argument,
ArgumentNull,
ArgumentOutOfRange
}

[UnmanagedCallersOnly]
internal static unsafe void CreateArgumentException(ArgumentExceptionKind kind, char* pResourceName, char* pParamName, object* pThrowable, Exception* pException)
{
try
{
string? message = pResourceName is not null ? SR.GetResourceString(new string(pResourceName)) : null;
string? paramName = pParamName is not null ? new string(pParamName) : null;

Debug.Assert(Enum.IsDefined(kind));
*pThrowable = kind switch
{
ArgumentExceptionKind.ArgumentNull => new ArgumentNullException(paramName, message),
ArgumentExceptionKind.ArgumentOutOfRange => new ArgumentOutOfRangeException(paramName, message),
_ /* ArgumentExceptionKind.Argument */ => new ArgumentException(message, paramName)
};
}
catch (Exception ex)
{
*pException = ex;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System.IO
{
public partial class FileLoadException
{
// Do not delete: this is invoked from native code.
private FileLoadException(string? fileName, int hResult)
: base(null)
{
Expand Down Expand Up @@ -36,5 +36,35 @@ internal static string FormatFileLoadExceptionMessage(string? fileName, int hRes

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "FileLoadException_GetMessageForHR")]
private static partial void GetMessageForHR(int hresult, StringHandleOnStack retString);

// See clrex.cpp for native version.
internal enum FileLoadExceptionKind
{
FileLoad,
BadImageFormat,
FileNotFound,
OutOfMemory
}

[UnmanagedCallersOnly]
internal static unsafe void Create(FileLoadExceptionKind kind, char* pFileName, int hresult, object* pThrowable, Exception* pException)
{
try
{
string? fileName = pFileName is not null ? new string(pFileName) : null;
Debug.Assert(Enum.IsDefined(kind));
*pThrowable = kind switch
{
FileLoadExceptionKind.BadImageFormat => new BadImageFormatException(fileName, hresult),
FileLoadExceptionKind.FileNotFound => new FileNotFoundException(fileName, hresult),
FileLoadExceptionKind.OutOfMemory => new OutOfMemoryException(),
_ /* FileLoadExceptionKind.FileLoad */ => new FileLoadException(fileName, hresult),
};
}
catch (Exception ex)
{
*pException = ex;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace System.IO
{
public partial class FileNotFoundException
{
// Do not delete: this is invoked from native code.
private FileNotFoundException(string? fileName, int hResult)
internal FileNotFoundException(string? fileName, int hResult)
: base(null)
{
HResult = hResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace System
{
public partial class TypeLoadException : SystemException
{
// This is called from inside the EE.
private TypeLoadException(string? className,
string? assemblyName,
string? messageArg,
Expand Down Expand Up @@ -48,5 +47,21 @@ private void SetMessageField()

[LibraryImport(RuntimeHelpers.QCall)]
private static partial void GetTypeLoadExceptionMessage(int resourceId, StringHandleOnStack retString);

[UnmanagedCallersOnly]
internal static unsafe void Create(char* pClassName, char* pAssemblyName, char* pMessageArg, int resourceId, object* pResult, Exception* pException)
{
try
{
string? className = pClassName is not null ? new string(pClassName) : null;
string? assemblyName = pAssemblyName is not null ? new string(pAssemblyName) : null;
string? messageArg = pMessageArg is not null ? new string(pMessageArg) : null;
*pResult = new TypeLoadException(className, assemblyName, messageArg, resourceId);
}
catch (Exception ex)
{
*pException = ex;
}
}
}
}
Loading
Loading