Skip to content

Instantly share code, notes, and snippets.

@chamons chamons/hack.cs Secret
Last active Sep 26, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.