Skip to content

Commit cdb3549

Browse files
Create error message when UnmanagedCallersOnly is used with DllImport. (#114240)
1 parent 39b1172 commit cdb3549

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

src/coreclr/dlls/mscorrc/mscorrc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ STRINGTABLE DISCARDABLE
151151
BEGIN
152152
IDS_EE_THREAD_APARTMENT_NOT_SUPPORTED "The system does not support the %1 thread apartment."
153153
IDS_EE_NDIRECT_UNSUPPORTED_SIG "Method's type signature is not PInvoke compatible."
154+
IDS_EE_NDIRECT_UNSUPPORTED_UNMANAGEDCALLERSONLY "Method '%1.%2' cannot be marked with both DllImportAttribute and UnmanagedCallersOnlyAttribute."
154155
IDS_EE_COM_UNSUPPORTED_SIG "Method's type signature is not Interop compatible."
155156
IDS_EE_COM_UNSUPPORTED_TYPE "The method returned a COM Variant type that is not Interop compatible."
156157
IDS_EE_MULTIPLE_CALLCONV_UNSUPPORTED "Multiple unmanaged calling conventions are specified. Only a single calling convention is supported."

src/coreclr/dlls/mscorrc/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define IDS_DS_DSOTHREADMODEL 0x1707
3636

3737
#define IDS_EE_NDIRECT_UNSUPPORTED_SIG 0x1708
38+
#define IDS_EE_NDIRECT_UNSUPPORTED_UNMANAGEDCALLERSONLY 0x1709
3839
#define IDS_EE_NDIRECT_BADNATL 0x170a
3940
#define IDS_EE_NDIRECT_LOADLIB_WIN 0x170b
4041
#define IDS_EE_NDIRECT_GETPROCADDRESS_WIN 0x170c

src/coreclr/vm/dllimport.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,7 +3415,6 @@ BOOL NDirect::MarshalingRequired(
34153415
return FALSE;
34163416
}
34173417

3418-
34193418
// factorization of CreateNDirectStubWorker
34203419
static MarshalInfo::MarshalType DoMarshalReturnValue(MetaSig& msig,
34213420
mdParamDef* params,
@@ -4291,7 +4290,13 @@ static void CreateNDirectStubAccessMetadata(
42914290
// P/Invoke marked with UnmanagedCallersOnlyAttribute is not
42924291
// presently supported.
42934292
if (pMD->HasUnmanagedCallersOnlyAttribute())
4294-
COMPlusThrow(kNotSupportedException, IDS_EE_NDIRECT_UNSUPPORTED_SIG);
4293+
{
4294+
SString namespaceOrClassName;
4295+
SString methodName;
4296+
pMD->GetMethodInfoNoSig(namespaceOrClassName, methodName);
4297+
COMPlusThrow(kNotSupportedException, IDS_EE_NDIRECT_UNSUPPORTED_UNMANAGEDCALLERSONLY,
4298+
namespaceOrClassName.GetUnicode(), methodName.GetUnicode());
4299+
}
42954300

42964301
// Check to see if we need to do LCID conversion.
42974302
lcidArg = GetLCIDParameterIndex(pMD);

src/mono/mono/metadata/marshal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3582,7 +3582,7 @@ mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions,
35823582
* In AOT mode and embedding scenarios, it is possible that the icall is not registered in the runtime doing the AOT compilation.
35833583
* Emit a wrapper that throws a NotSupportedException.
35843584
*/
3585-
get_marshal_cb ()->mb_emit_exception (mb, "System", "NotSupportedException", "Method canot be marked with both DllImportAttribute and UnmanagedCallersOnlyAttribute");
3585+
get_marshal_cb ()->mb_emit_exception (mb, "System", "NotSupportedException", "Method cannot be marked with both DllImportAttribute and UnmanagedCallersOnlyAttribute");
35863586
goto emit_exception_for_error;
35873587
} else if (!pinvoke && !piinfo->addr && !aot) {
35883588
/* if there's no code but the error isn't set, just use a fairly generic exception. */

0 commit comments

Comments
 (0)