PeWriter should write IAssemblyReference.UnifiedAssemblyIdentity

Topics: PE Writer
Apr 22, 2011 at 9:56 AM
Edited Apr 22, 2011 at 11:10 AM

Hi,

Shouldn't PeWriter write out the UnifiedAssemblyIdentity's properties (Version, PublicKeyToken, Name, Culture and any other) in PopulateAssemblyRefTableRows?

I understand the unification logic in the case of PeReader, but, while modifying assemblies, isn't it logically correct to write out UnifiedAssemblyIdentity properties instead of AssemblyReference properties?

Coordinator
Apr 22, 2011 at 4:09 PM

I think that PeWriter should write exactly what it is given to write. If you want it to do something else you have the option of modifying the model before writing it out. It might not be the best for every scenario, but it does have the advantage of being the simplest mechanism that still allows you to do everything you might need to do.

Apr 22, 2011 at 10:54 PM

I have actually found how to work around it and still do not complicate things much. So you're right. Thanks.

Apr 23, 2011 at 5:38 AM

When I unify an assembly reference from mscorlib 2.0 to mscorlib 4.0, things like ITypeDefinition.IsEnum do not work, because platform resolves them to 4.0 version of System.Enum, while PeReader resolves the base class to 2.0 version.

Using TypeHelper.TypesAreEquivalent seems to not work either. Any thoughts?

Coordinator
Apr 23, 2011 at 6:08 AM

Hmm. That is not supposed to happen. One thing to look for is when the host decides on the platform.

Could you come up with a small program that illustrates the problem so that I can have a closer look?

Apr 24, 2011 at 8:34 AM
Edited Apr 24, 2011 at 8:37 AM

Nevermind. I have messed up when overriding GetCoreAssemblySymbolicIdentity and UnifyAssembly.

To solve my problems, my UnifyAssembly implementation is now searching for strongly-named assemblies located in the same path with CoreAssemblySymbolicIdentity.Location, load them and return their identity. The result is cached for performance reasons. Assuming CLR loads assemblies in the same way (http://msdn.microsoft.com/en-us/library/db7849ey.aspx), this works for .NET Framework as well as Silverlight/Windows Phone scenario (if respective library path is added).

Isn't this worth implementing in CCI?

Would you recommend doing it in a more performant way?