3 out of 22 rated this helpful Rate this topic

<loadFromRemoteSources> Element

Updated: April 2011

Specifies whether assemblies from remote sources should be granted full trust.

NoteNote

If you were directed to this topic because of an error message in the Visual Studio project error list or a build error, see How to: Use an Assembly from the Web in Visual Studio.

<configuration> Element
  <runtime> Element
    <loadFromRemoteSources> Element
<loadFromRemoteSources  
   enabled="true|false"/>

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute

Description

enabled

Required attribute.

Specifies whether an assembly that is loaded from remote sources should be granted full trust.

enabled Attribute

Value

Description

false

Do not grant full trust to applications from remote sources. This is the default.

true

Grant full trust to applications from remote sources.

Child Elements

None.

Parent Elements

Element

Description

configuration

The root element in every configuration file used by the common language runtime and .NET Framework applications.

runtime

Contains information about runtime initialization options.

In the .NET Framework version 3.5 and earlier versions, if you loaded an assembly from a remote location, the assembly would run partially trusted with a grant set that depended on the zone in which it was loaded. For example, if you loaded an assembly from a Web site, it was loaded into the Internet zone and granted the Internet permission set. In other words, it executed in an Internet sandbox. If you try to run that assembly in the .NET Framework version 4, an exception is thrown; you must either explicitly create a sandbox for the assembly, or run it in full trust.

The <loadFromRemoteSources> element lets you specify that the assemblies that run partially trusted in earlier versions of the .NET Framework should be run fully trusted in the .NET Framework 4.

Note Note

If an application has been copied from the Web, it is flagged by Windows as being a Web application, even if it resides on the local computer. You can change that designation by changing the file properties, or you can use the <loadFromRemoteSources> element to grant the assembly full trust.

The enabled attribute for this element is effective only when code access security (CAS) is disabled. By default, CAS policy is disabled in the .NET Framework 4 and later versions. If you set enabled to true, remote applications are granted full trust.

If <loadFromRemoteSources> enabled is not set to true, an exception is thrown under the following conditions:

  • The sandboxing behavior of the current domain is different from its behavior in the .NET Framework 3.5. This requires CAS policy to be disabled, and the current domain not to be sandboxed.

  • The assembly being loaded is not from the MyComputer zone.

Note Note

You may get a FileLoadException in a Windows Virtual PC application when you try to load a file from linked folders on the hosting computer. This error may also occur when you try to load a file from a folder linked over Remote Desktop Services (Terminal Services). To avoid the exception, set enabled to true.

Setting the <loadFromRemoteSources> element to true prevents this exception from being thrown. It enables you to specify that you are not relying on the common language runtime to sandbox the loaded assemblies for security, and that they can be allowed to execute as full trust.

Important note Important

If the assembly should not run in full trust, do not set this configuration element. Instead, create a sandboxed AppDomain in which to load the assembly.

Configuration File

This element can be used only in the application configuration file. For more information, see the "Application Configuration Files" section in Configuration Files.

The following example shows how to grant full trust to applications from remote sources.

<configuration>
   <runtime>
      <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>

Date

History

Reason

April 2011

Updated information about using the element in application configuration files.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Expression 4.0 won't install

I am directed to go.microsoft.com/fwlink/?LinkId=155569 when I try and setup Expression 4.0 after installing .NET 4.0 (which it requires). What is the name of the config file in the setup package in which I need to edit: <loadFromRemoteSources enabled="true">

EDIT: I have recently created a file, Setup.exe.config, of type XML, with the following code: <configuration> <runtime> <loadFromRemoteSources enabled="true"/? </runtime> </configuration> and placed it into the same directory as Setup.exe, yet still get the same error code from Setup.exe.

Please assist.

Try to mount the ISO with a program like MagicIso


Possible Workaround
It will work if you mount the ISO with a program like Magic Iso...
Should Narrow Scope by IP/URL

There should be a way to specify in the loadFromRemoteSources tag which URLs/IPs/Domains will be allowed to load assemblies with FULL trust.  Also, there should be a way to exclude specific URLs/IPs/Domains from having full trust.  Below is an example of how I think it should work:

<configuration>
<runtime>
    <loadFromRemoteSources enabled="true" "https://my.company.com" />
    <loadFromRemoteSources enabled="true" "https://192.168.0.*" />
    <loadFromRemoteSources enabled="false" "*" />
</runtime>
</configuration>

So that any assemblies from my.company.com or IP 192.168.0.* will be loaded with full trust, but assemblies from all other locations will be given very little trust.

Best,

Shawn

File system Virtualization might edit the wrong copy of "devenv.exe.config"
Under Vista or Windows7 take care of thefile system Virtualization.
Editing devenv.exe.config might result in creating a copy under
 \Users\{%UserName%}\AppData\local\VirtualStore\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config

leaving the original file untouched. This depends on your user settings.
It might help to open "VS 2010 as administrator" (or another XML-Editor of your choice),
edit devenv.exe.config, inserting the

<loadFromRemoteSources enabled=true />

tag, save the file and close.
This will edit the original file, not the virtualized copy.
Having done so referencing "remote" assemblies in your projects
should work

Let me guess, you complain when people don't RTFM
There's a saying that if you want people to read the f'ing manual you should write a better manual.

Providing documentation on how to fix a problem with no hint to where the fix goes is a pretty pathetic failure.

How about fixing this so people don't need to go to 3rd party websites to figure out the solution?
MSBuild
If you are running MSBuild, rather than Visual Studio, the element needs to be added to msbuild.exe.config.  I found 10 copies of this file on my build machine - 6 in Windows\Microsoft.Net\Framework... and 4 in Windows\winsxs....  Due to permission issues, I was not able to change the copies in winsxs..., but that didn't matter.  I changed all 6 in the Framework hierarchy and that solved the problem.
devenv.exe.config
It appears the correct config file is: devenv.exe.config
potentially located under: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE(which, by the way, I had to grant security rights to myself to edit...)

Answer originally found at: http://stackoverflow.com/questions/1823339/error-building-visual-studio-2010-silverlight-4-projects-on-windows-7-with-xp-mod
Finally got it working
Thank goodness. It took me a while to get it working. I have an application I am developing that loads plugins from a local intranet. Since it is a research project that uses condor, we would rather not have to copy these plugins everywhere (especially since they change rapidly)

With help from this post http://blogs.msdn.com/b/shawnfa/archive/2009/06/08/more-implicit-uses-of-cas-policy-loadfromremotesources.aspx, I realized that this was not an assembly specific flag, but a process-wide flag. So I moved it from the test assembly I was using to the parent processes configuration, and it works!

Hope this helps everyone else with their problems.
Seriously?
Why can't I run code from my own local area network? BTY, I set this and it still doesn't work. Please don't blame me that it doesn't work BTW. It's your fault with your stupid security.

Should this work on WindowsXP with .net 4.0?
I'm trying to open a .dll in nunit 2.5.5 on Windows XP with a .net 4.0 installation. I get the error described, and adding the <loadFromRemoteSource> element to the nunit.exe.config file does not resolve the situation. Why not?