Getting types in mscorlib 2.0.5.0 (aka Silverlight mscorlib) via reflection on?
Asked Answered
O

2

7

I am trying to add Silverlight support to my favorite programming langauge Nemerle.

Nemerle , on compilation procedure, loads all types via reflection mainly in 2 steps

1-) Uses Assembly.LoadFrom to load assembly 2-) Usese Assembly.GetTypes() to get the types

Then at the end of compilation it emits the resolved types with Reflection.Emit.

This procedure works for all assemblies including Silverlight ones except mscorlib of silverlight.

In c# this fails:

 var a = System.Reflection.Assembly.LoadFrom(@"c:\mscorlib.dll");

but this passes :

var a = System.Reflection.Assembly.ReflectionOnlyLoadFrom(@"c:\mscorlib.dll"); 

Bu in the latter , a.GetTypes() throws an exception sayin System.Object's parent does not exist.

Is there a way out ?

Ouachita answered 16/4, 2009 at 6:35 Comment(1)
Are you doing this from Silverlight itself or the standard CLR?Catlin
C
5

Assuming you're trying to reflect over Silverlight's mscorlib from the standard CLR, this won't work because the CLR doesn't permit loading multiple versions of mscorlib. (Perhaps this is because it could upset resolution of its core types).

A workaround is to use Mono.Cecil to inspect the types: http://mono-project.com/Cecil. This library actually performs better than .NET's Reflection and is supposed to be more powerful.

Here's some code to get you started:

AssemblyDefinition asm = AssemblyFactory.GetAssembly(@"C:\mscorlib.dll");

var types =
    from ModuleDefinition m in asm.Modules
    from TypeDefinition t in m.Types
    select t.Name;
Catlin answered 21/4, 2009 at 13:44 Comment(0)
E
0

You can compile Nemerle with Silverlight assembly and then you have Nemerle working on top of Silverlight :)

Epigenesis answered 8/3, 2011 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.