I currently have an app.config with the following config value:
<configuration>
<runtime>
<loadFromRemoteSources enabled="true" />
</runtime>
</configuration>
So far I have been able to remove everything else out of my app.config and configure things just using pure C# code except the loadFromRemoteSources.
Is there a way to enable loadFromRemoteSources through C# code?
I understand the pros and cons of having an app.config, but I would prefer not to have one.
Thanks!
I can’t find any way to enable
loadFromRemoteSourcesin code, and if there is, I doubt it would allow you to apply it to an application domain after it has been created. But I could be wrong!You could instead use the technique described in “More Implicit Uses of CAS Policy: loadFromRemoteSources“. They suggest creating a new application domain with
PermissionState.Unrestricted, and loading remote assemblies into there. An application domain created this way does not throwNotSupportedExceptionwhen you try to load a remote assembly.They describe this technique as a solution for when you want to load only some remote assemblies with full trust, and thus do not want to enable
loadFromRemoteSourcesin your app.config. You could use the same technique, but load your entire program into the new app domain.Here is an example program which, when executed, immediately creates a new application domain with
PermissionState.Unrestrictedand runs itself in it:And here is the source code for MyRemoteAssembly.dll, which you can put on your network share: