nav-left cat-right
cat-right

The “ValidateXaml” task failed unexpectedly

So, you found that code example that helps you solve the problem you have been beating your head against the wall for. You most likely downloaded a .zip file and extracted its contents onto your local machine. You then open the solution in your favorite flavor of Visual Studio. When you attempt to compile the sample, you get a compile-time that reads something like :

Error    3    The “ValidateXaml” task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly ‘file:///C:\MyDirectory\MyApplication\MyApplication\Bin\Debug\Assembly.dll’ or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0×80131515)
File name: ‘file:///C:\MyDirectory\MyApplication\MyApplication\Bin\Debug\Assembly.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)

Whoa! This looked a bit intimidating the first time I saw it. The good news is, it’s an easy fix. The key information related to this error begins with the text “System.NotSupportedException“. What this basically goes on to say is that the offending component  has been blocked by Windows for security reasons. To overcome this, open Windows Explorer and navigate to the directory where the offending component exists. One there right click on the component and choose “Properties”. For the sake of a visualization, this is what this looks like:

Properties

When you click the “Properties” option, a dialog window will appear. Towards the bottom of this dialog, you will see the “security” information which says: “This file came from another computer and might be blocked to help protect this computer”. To the right of this text is a button that says “Unblock”. This is the button we are looking for as highlighted here:

Security

Simply click the “Unblock” button and rebuild your application. You may have to do this several times if there are multiple assemblies that were downloaded along with the code sample. Regardless, I hope you have found this post valuable. If you would like to learn more about developing applications with Silverlight, I highly recommend Silverlight in Action by Pete Brown. The first version of this book series was written by Chad Campbell (me) and John Stockton.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Live
  • NewsVine
  • Reddit
  • Slashdot
  • StumbleUpon
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • Posterous

Leave a Reply

blog comments powered by Disqus