diff options
author | Andrew Au <cshung@gmail.com> | 2018-10-29 09:09:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-29 09:09:48 -0700 |
commit | f61c6080439ebab6c1ca2afcc7f486cc97703840 (patch) | |
tree | dd161b2cbc716a52743e2857d372dcbbb706205a /src/System.Private.CoreLib/src/System/RtType.cs | |
parent | 2dd12d48321c27f7851be176f01d87e06307d4a9 (diff) | |
download | coreclr-f61c6080439ebab6c1ca2afcc7f486cc97703840.tar.gz coreclr-f61c6080439ebab6c1ca2afcc7f486cc97703840.tar.bz2 coreclr-f61c6080439ebab6c1ca2afcc7f486cc97703840.zip |
Unhelpful error when Activator.CreateInstance can't find default constructor (#20491)
Diffstat (limited to 'src/System.Private.CoreLib/src/System/RtType.cs')
-rw-r--r-- | src/System.Private.CoreLib/src/System/RtType.cs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/System.Private.CoreLib/src/System/RtType.cs b/src/System.Private.CoreLib/src/System/RtType.cs index 3bab50597e..743e2291e5 100644 --- a/src/System.Private.CoreLib/src/System/RtType.cs +++ b/src/System.Private.CoreLib/src/System/RtType.cs @@ -4768,11 +4768,16 @@ namespace System { RuntimeMethodHandleInternal runtime_ctor = default; bool bCanBeCached = false; + bool bHasNoDefaultCtor = false; if (!skipCheckThis) CreateInstanceCheckThis(); - object instance = RuntimeTypeHandle.CreateInstance(this, publicOnly, wrapExceptions, ref bCanBeCached, ref runtime_ctor); + object instance = RuntimeTypeHandle.CreateInstance(this, publicOnly, wrapExceptions, ref bCanBeCached, ref runtime_ctor, ref bHasNoDefaultCtor); + if (bHasNoDefaultCtor) + { + throw new MissingMethodException(SR.Format(SR.Arg_NoDefCTor, this)); + } if (bCanBeCached && fillCache) { @@ -4809,7 +4814,7 @@ namespace System if (ace.m_ctor != null && (ace.m_ctorAttributes & MethodAttributes.MemberAccessMask) != MethodAttributes.Public) { - throw new MissingMethodException(SR.Arg_NoDefCTor); + throw new MissingMethodException(SR.Format(SR.Arg_NoDefCTor, this)); } } |