Skip to content

Instantly share code, notes, and snippets.

@chamons

chamons/hack.cs Secret

Last active September 26, 2016 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/f5de79eccc1aa775daa528da6aa17af3 to your computer and use it in GitHub Desktop.
Save chamons/f5de79eccc1aa775daa528da6aa17af3 to your computer and use it in GitHub Desktop.
void UseReflectionToHackAround_44707 ()
{
// As it says on the tin, this uses reflection to hack around bug 44707
// If mono changes their implementaiton at all, it will stop working, and throw InvalidOperationException
// First figure out where the config we ship inside the bundle is
string path = NSBundle.MainBundle.ResourceUrl.Append ("../MonoBundle/config", false).ToString ().Replace ("file://", "");
// Then force mono to load that instead
MethodInfo readConfigMethod = typeof (RemotingConfiguration).GetMethod ("ReadConfigFile", BindingFlags.NonPublic | BindingFlags.Static);
if (readConfigMethod == null)
throw new System.InvalidOperationException ("UseReflectionToHackAround_44707 failed due to mono changing implementation");
readConfigMethod.Invoke (this, new object[] { path });
// And then set the property that we already read it
FieldInfo defaultReadProp = typeof (RemotingConfiguration).GetField ("defaultConfigRead", BindingFlags.NonPublic | BindingFlags.Static);
if (defaultReadProp == null)
throw new System.InvalidOperationException ("UseReflectionToHackAround_44707 failed due to mono changing implementation");
defaultReadProp.SetValue (null, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment