Emit metadata for type forwarders - #5054
Conversation
Why is System.Security.Permissions a problem? It should be in the framework set. Edit: I see that it is not there for some reason. It should be fine to add more package references next to https://github.com/dotnet/corert/blob/master/src/Framework/Framework.depproj#L28 if it helps.
Would a better fix for this be to not throw from GetType when mscorlib does not exist? It should be just a matter of calling TryGetRuntimeAssembly instead of GetRuntimeAssembly. |
That depends. Would it be better if The problem is that |
|
All non-throwing metadata APIs return null for the tree-shaken types or methods. They do not try to "help" by throwing exceptions. I agree that it is not always easy to diagnose these. I do not see a good reason why this API should be on a different plan and try to "help". |
Typically if one gets this null returning behavior, the fix is to put the thing they're looking for in RD.XML (so in this case, as a user, I would expect adding |
|
As for the mechanism that decides what type forwards to include metadata for - how consistent are we with .NET Native for UWP apps currently uses similar heuristic ("if we're generating metadata for something, and there's a type forward for it somewhere within the inputs, generate the type forward too"). This has it's own set of problems too though (e.g. with this you can't really have a type forward within the app that forwards to a type implemented in the shared assembly, because shared assembly has the metadata and we don't look at type forwards for those types during app build). We've been getting away without it, but it's not great. |
Agree. I think it is good enough to stick with it, at least for now. For GetType, I think there are two case:
So I think changing the API to no throw for case 2 is more to enable us to experiment with leaner modes than to have much effect on self-diagnosability. |
Manually parse the AssemblyReference record.
| { | ||
| throw new NotSupportedException("Multi-module assemblies"); | ||
| string simpleName = obj.Name; | ||
| return simpleName != null ? simpleName.GetHashCode() : 0; |
There was a problem hiding this comment.
Nit: This could be written as return obj.Name?.GetHashCode() ?? 0.
|
@dotnet-bot test Windows_NT Release please |
Fixes #2279, probably also #5051. I haven't checked.
I'm marking it as WIP, because I'm not too happy with how this turned out - emitting the metadata is easy; deciding what to emit is hard. Seeking some feedback.
I chose to use RD.XML as the mechanism to include the (otherwise unused) assemblies into the metadata. So the user has to put
<Assembly Name="mscorlib" />in their RD.XML to get forwarders from mscorlib. It's really not great.The other problem is that mscorlib has a lot of garbage in it (like references to System.Security.Permissions). This code throws a lot.