Click here to Skip to main content
13,048,406 members (147,816 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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.[^]

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 22:29pm

1 solution

Rate this: bad
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,

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2017
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