Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete some .NET Nativisms #73553

Merged
merged 2 commits into from
Aug 9, 2022
Merged
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 @@ -26,7 +26,7 @@ public static uint GetStructFieldOffset(RuntimeTypeHandle structureTypeHandle, s
throw new ArgumentException(SR.Format(SR.Argument_OffsetOfFieldNotFound, RuntimeAugments.GetLastResortString(structureTypeHandle)), nameof(fieldName));
}

throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
throw new NotSupportedException(SR.Format(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle)));
}

public static int GetStructUnsafeStructSize(RuntimeTypeHandle structureTypeHandle)
Expand All @@ -44,7 +44,7 @@ public static int GetStructUnsafeStructSize(RuntimeTypeHandle structureTypeHandl
return structureTypeHandle.GetValueTypeSize();
}

throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
throw new NotSupportedException(SR.Format(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle)));
}

public static IntPtr GetStructUnmarshalStub(RuntimeTypeHandle structureTypeHandle)
Expand All @@ -54,7 +54,7 @@ public static IntPtr GetStructUnmarshalStub(RuntimeTypeHandle structureTypeHandl
return stub;
}

throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
throw new NotSupportedException(SR.Format(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle)));
}

public static IntPtr GetStructMarshalStub(RuntimeTypeHandle structureTypeHandle)
Expand All @@ -64,7 +64,7 @@ public static IntPtr GetStructMarshalStub(RuntimeTypeHandle structureTypeHandle)
return stub;
}

throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
throw new NotSupportedException(SR.Format(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle)));
}

public static IntPtr GetDestroyStructureStub(RuntimeTypeHandle structureTypeHandle, out bool hasInvalidLayout)
Expand All @@ -74,15 +74,15 @@ public static IntPtr GetDestroyStructureStub(RuntimeTypeHandle structureTypeHand
return stub;
}

throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
throw new NotSupportedException(SR.Format(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle)));
}


public static IntPtr GetForwardDelegateCreationStub(RuntimeTypeHandle delegateTypeHandle)
{
GetMarshallersForDelegate(delegateTypeHandle, out _, out _, out IntPtr delegateCreationStub);
if (delegateCreationStub == IntPtr.Zero)
throw new MissingInteropDataException(SR.DelegateMarshalling_MissingInteropData, Type.GetTypeFromHandle(delegateTypeHandle));
throw new NotSupportedException(SR.Format(SR.DelegateMarshalling_MissingInteropData, Type.GetTypeFromHandle(delegateTypeHandle)));
return delegateCreationStub;
}

Expand All @@ -91,7 +91,7 @@ public static IntPtr GetDelegateMarshallingStub(RuntimeTypeHandle delegateTypeHa
GetMarshallersForDelegate(delegateTypeHandle, out IntPtr openStub, out IntPtr closedStub, out _);
IntPtr pStub = openStaticDelegate ? openStub : closedStub;
if (pStub == IntPtr.Zero)
throw new MissingInteropDataException(SR.DelegateMarshalling_MissingInteropData, Type.GetTypeFromHandle(delegateTypeHandle));
throw new NotSupportedException(SR.Format(SR.DelegateMarshalling_MissingInteropData, Type.GetTypeFromHandle(delegateTypeHandle)));
return pStub;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
<Compile Include="System\Runtime\InteropServices\PInvokeMarshal.cs" />
<Compile Include="System\Runtime\InteropServices\Marshal.NativeAot.cs" />
<Compile Include="System\Runtime\InteropServices\Marshal.Com.cs" Condition="'$(FeatureCominterop)' == 'true'" />
<Compile Include="System\Runtime\InteropServices\MissingInteropDataException.cs" />
<Compile Include="System\Runtime\InteropServices\MemoryMarshal.NativeAot.cs" />
<Compile Include="System\Runtime\InteropServices\SafeHandle.NativeAot.cs" />
<Compile Include="System\Runtime\InteropServices\UnsafeGCHandle.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ internal static MissingMetadataException Create(TypeInfo? pertainant, string nes

string usefulPertainant = ComputeUsefulPertainantIfPossible(pertainant);
if (usefulPertainant == null)
return new MissingMetadataException(Format(SR.Reflection_InsufficientMetadata_NoHelpAvailable, pertainant.ToString()));
return new MissingMetadataException(SR.Format(SR.Reflection_InsufficientMetadata_NoHelpAvailable, pertainant.ToString()));
else
{
usefulPertainant = usefulPertainant + "." + DiagnosticMappingTables.ConvertBackTickNameToNameWithReducerInputFormat(nestedTypeName, null);
return new MissingMetadataException(Format(SR.Reflection_InsufficientMetadata_EdbNeeded, usefulPertainant));
return new MissingMetadataException(SR.Format(SR.Reflection_InsufficientMetadata_EdbNeeded, usefulPertainant));
}
}

Expand All @@ -55,7 +55,7 @@ private static MissingMetadataException CreateFromString(string? pertainant)
if (pertainant == null)
return new MissingMetadataException(SR.Format(SR.Reflection_InsufficientMetadata_NoHelpAvailable, "<unavailable>"));
else
return new MissingMetadataException(Format(SR.Reflection_InsufficientMetadata_EdbNeeded, pertainant));
return new MissingMetadataException(SR.Format(SR.Reflection_InsufficientMetadata_EdbNeeded, pertainant));
}

internal static MissingMetadataException CreateMissingArrayTypeException(Type elementType, bool isMultiDim, int rank)
Expand All @@ -78,9 +78,9 @@ internal static MissingMetadataException CreateFromMetadataObject(string resourc

string usefulPertainant = ComputeUsefulPertainantIfPossible(pertainant);
if (usefulPertainant == null)
return new MissingMetadataException(Format(SR.Reflection_InsufficientMetadata_NoHelpAvailable, pertainant.ToString()));
return new MissingMetadataException(SR.Format(SR.Reflection_InsufficientMetadata_NoHelpAvailable, pertainant.ToString()));
else
return new MissingMetadataException(Format(resourceId, usefulPertainant));
return new MissingMetadataException(SR.Format(resourceId, usefulPertainant));
}

public static string ComputeUsefulPertainantIfPossible(object pertainant)
Expand Down Expand Up @@ -299,22 +299,5 @@ private static string CreateConstructedGenericTypeStringIfAvailable(Type generic
return genericTypeName.ToString();
}

//
// This is a workaround to prevent crucial information being lost when compiling console apps using the retail ILC.
// This combination turns rich error messages from the framework into resource keys without the substitution strings.
// We'll detect this case here and append the substitution string manually.
//
private static string Format(string resourceMessage, object parameter)
{
if (resourceMessage.Contains("{0}"))
return SR.Format(resourceMessage, parameter);

// If the rich exception message was eaten by the IL2IL transform, make sure the resulting message
// has a link pointing the user towards the .NET Native debugging guide. These get normally appended
// to the restricted message by the transform, but the pattern here is not recognized by the rewriter.
// At this point we know the message doesn't come from resources (because message == resource key), so
// we can't do much to make this localizable.
return resourceMessage + ": " + parameter + ". For more information, visit http://go.microsoft.com/fwlink/?LinkId=623485";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public sealed override Exception CreateNonInvokabilityException(MemberInfo perta
}

string pertainantString = MissingMetadataExceptionCreator.ComputeUsefulPertainantIfPossible(pertainant);
return new MissingRuntimeArtifactException(SR.Format(resourceName, pertainantString ?? "?"));
return new MissingMetadataException(SR.Format(resourceName, pertainantString ?? "?"));
}

public sealed override Exception CreateMissingArrayTypeException(Type elementType, bool isMultiDim, int rank)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ public static MethodInfo GetDelegateMethodInfo(Delegate del)
callTryGetMethod = false;
methodHandle = QMethodDefinition.FromObjectAndInt(resolver->Reader, resolver->Handle);

RuntimeTypeHandle declaringTypeHandleIgnored;
MethodNameAndSignature nameAndSignatureIgnored;
if (!TypeLoaderEnvironment.Instance.TryGetRuntimeMethodHandleComponents(resolver->GVMMethodHandle, out declaringTypeHandleIgnored, out nameAndSignatureIgnored, out genericMethodTypeArgumentHandles))
throw new MissingRuntimeArtifactException(SR.DelegateGetMethodInfo_NoInstantiation);
if (!TypeLoaderEnvironment.Instance.TryGetRuntimeMethodHandleComponents(resolver->GVMMethodHandle, out _, out _, out genericMethodTypeArgumentHandles))
throw new MissingMetadataException(SR.DelegateGetMethodInfo_NoInstantiation);
}
}
}
Expand All @@ -79,9 +77,9 @@ public static MethodInfo GetDelegateMethodInfo(Delegate del)

string methodDisplayString = RuntimeAugments.TryGetMethodDisplayStringFromIp(ip);
if (methodDisplayString == null)
throw new MissingRuntimeArtifactException(SR.DelegateGetMethodInfo_NoDynamic);
throw new MissingMetadataException(SR.DelegateGetMethodInfo_NoDynamic);
else
throw new MissingRuntimeArtifactException(SR.Format(SR.DelegateGetMethodInfo_NoDynamic_WithDisplayString, methodDisplayString));
throw new MissingMetadataException(SR.Format(SR.DelegateGetMethodInfo_NoDynamic_WithDisplayString, methodDisplayString));
}
}
MethodBase methodBase = ReflectionCoreExecution.ExecutionDomain.GetMethod(typeOfFirstParameterIfInstanceDelegate, methodHandle, genericMethodTypeArgumentHandles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<value>This operation cannot be carried out because metadata for the following object was removed for performance reasons:\n\n {0}\n\nNo further information is available. Rebuild in debug mode for better information.\n\n</value>
</data>
<data name="Reflection_InsufficientMetadata_EdbNeeded" xml:space="preserve">
<value>'{0}' is missing metadata. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=392859</value>
<value>'{0}' is missing native code or metadata. This can happen for code that is not compatible with trimming or AOT. Inspect and fix trimming and AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility</value>
</data>
<data name="Arg_DlgtTargMeth" xml:space="preserve">
<value>Cannot bind to the target method because its signature is not compatible with that of the delegate type.</value>
Expand Down Expand Up @@ -151,7 +151,7 @@
<value>This object cannot be invoked because no code was generated for it: '{0}'.</value>
</data>
<data name="MakeGenericMethod_NoMetadata" xml:space="preserve">
<value>MakeGenericMethod() cannot create this generic method instantiation because no code was generated for it: '{0}'.</value>
<value>'{0}' is missing native code. MethodInfo.MakeGenericMethod() is not compatible with AOT compilation. Inspect and fix AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility</value>
</data>
<data name="PlatformNotSupported_CannotInvokeDelegateCtor" xml:space="preserve">
<value>Dynamic invocation of delegate constructors is not supported on this runtime.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<Compile Include="Internal\Reflection\Execution\PayForPlayExperience\MissingMetadataExceptionCreator.cs" />
<Compile Include="Internal\Reflection\Extensions\NonPortable\DelegateMethodInfoRetriever.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\LibraryInitializer.cs" />
<Compile Include="System\Reflection\MissingRuntimeArtifactException.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(CompilerCommonPath)\Internal\Runtime\MetadataBlob.cs" >
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3957,10 +3957,10 @@
<value>Must not be greater than the length of the buffer.</value>
</data>
<data name="StructMarshalling_MissingInteropData" xml:space="preserve">
<value>{0} is missing structure marshalling data. To enable structure marshalling data, add a MarshalStructure directive to the application rd.xml file. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=393965</value>
<value>'{0}' is missing structure marshalling data. This can happen for code that is not compatible with AOT. Inspect and fix AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility</value>
</data>
<data name="DelegateMarshalling_MissingInteropData" xml:space="preserve">
<value>{0} is missing delegate marshalling data. To enable delegate marshalling data, add a MarshalDelegate directive to the application rd.xml file. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=393965</value>
<value>'{0}' is missing delegate marshalling data. This can happen for code that is not compatible with AOT. Inspect and fix AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibility</value>
</data>
<data name="Argument_AssemblyGetTypeCannotSpecifyAssembly" xml:space="preserve">
<value>Type names passed to Assembly.GetType() must not specify an assembly.</value>
Expand Down