Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET reflection
I want to modify Assembly.Location property at runtime in my application. I'm loading .NET Assemblies from the resources, and the loaded Assemblies (loaded from the memory) has this field empty and it breaks down application functionality.
 
I have no control over their source code. I know how to work around this bug in my own code, but that's not the case. And when they use Assembly.Location and gets an empty string the problem starts.
 
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.location.aspx[^]
 
It's read only. Is there any low level way to do it? Any ideas?
 
My application is a loader for those applications embedded in the resources, so it doesn't depend on them. Try to load any assembly from the memory and check the Assembly.Location field of those loaded assemblies, it will be blank. They don't have the location because they're loaded from the memory, still I want to change that, either by .NET internals modifications or any other method.
 
The compressed assemblies cannot be decompressed to the disk. I don't mind the danger of major problems if you just know how to achieve it.
Posted 1-Jul-13 23:29pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Short answer; No.
 
Slightly longer answer;
It would be somewhat difficult (as I am sure you're already suspecting), the reason for it being hard is that the value returned by the Location getter isn't stored in a backing field such as
  private readonly string location;
 
Instead, it is fetched using the native handle to the Assembly (or actually since that class is abstract, RuntimeAssembly which is the sub-class you get when loading stuff from memory) and then using an external dll call to read the location.
 
It looks something like this (simplified);
 
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
private static extern void GetLocation(RuntimeAssembly assembly, StringHandleOnStack retString);
 
public override String Location {
  get {
    String location = null;
    GetLocation(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref location));
 
    return location;
  }
}
 
I think it is going to be easier for you to change the code that requires this to be non-empty than inject a value into that.
 
Hope this helps,
Fredrik
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 504
1 Maciej Los 349
2 Kornfeld Eliyahu Peter 325
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100