TDaver
TDaver

Reputation: 7264

Can I load a silverlight dll (reflection only) into a .net application?

I realize the difference in SL and .net CLR and Class Library, and I don't want to execute any code (just query some attributes and check whether some types implement an interface declared in a shared assembly).

But I cannot load the SL dll with Assembly.LoadFrom, because it doesn't found the dependencies (like System.Windows.dll and such). I've tried the Assembly.ReflectionOnlyLoadFrom, but that gives me pretty much the same error (cannot load dependencies) just with different wording...

Is there ANY way to reflect an SL assembly from outside of SL?

Upvotes: 3

Views: 1039

Answers (2)

TDaver
TDaver

Reputation: 7264

I've switched back to LoadFrom instead of ReadOnlyLoadFrom. At least NOW it found my own assemblies, and it's only missing System.Windows and so on.
So I've subscribed to AppDomain.Current.AssemblyResolve, and passed my SL installation folder as a parameter to my app. So now, for every unresolved Assembly, I look it up by name from the SL directory (c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0)

Upvotes: 1

C. Dragon 76
C. Dragon 76

Reputation: 10072

Try copying the dependencies (System.Windows.dll, etc.) to the same directory as the Silverlight assembly you are trying to load.

The loader/fusion has to be able to locate and load the correct dependent assemblies (even for "reflection only") because vital metadata (such as method signatures inherited from base classes) may only reside in those dependencies.

Upvotes: 2

Related Questions