October 20, 2010

How to solve LoadFromRemoteSources error in VS 2010

by admin
Categories: Development
Tags:
Comments: 1 Comment

 I was facing an issue during the migration of my silverlight application to Visual Studio 2010. The issue was something like there are some references into the application from the network shared folder. When compiling the application there was a weird error saying :

The “ValidateXaml” task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly ‘file://\\xxxxxxxx\Assemblies\xxxxx.dll’ or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0×80131515)
File name: ‘file://\\xxxxxxxx\Assemblies\xxxxx.dll’ —> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute(ITask task)
   at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute(ITask task)
   at Microsoft.Silverlight.Build.Tasks.ValidateXaml.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)

Navigating the microsoft link for this problem, it is bit confusing that we have to add the LoadFromRemoteSources switch to some app.config file or web.config file !! So here is the process to accomplish the task and get rid of thsi ridiculous error:-

  1. Goto this path in your windows explorer :
    C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE
  2. Open the devenv.exe.config file in notepad or any editor of your choice.
  3. Search for this element closing tag in the file:
    </runtime>
  4. Before this element closing tag, Copy and paste the below configuration switch
    <loadFromRemoteSources enabled=”true“/>
  5. Save and close the config file
  6. It’s done !!

Comments closed

1 Comment »

  1. Bradley Ward says:

    Thanks for this info… very useful.

    I wish that everyone that posts information about anything that is set in the .Net config file XML is that they would also state how the same thing can be done in code. As a software product architect and developer with multiple decades of experience, I do not want to expose my products to a curious system administrator or end user who might change such things without having a full understanding of the possible consequences of such a change.


Today is Tuesday
July 22, 2014