XDocument.Load fails to load xml document

Feb 20, 2011 at 10:31 PM

I have a Silverlight Unit test project which reads a xml file (build action of the xml in File properties is set to "Content") using XDocument.Load. The load and read operation is successful when i run it from VS. But it fails when i run it from Statlight. 

I poked around the Statlight src code and found this piece of code which reads the Silverlight Test project (SUT) xap and adds it to Statlight xap. 


        private byte[] RewriteXapWithSpecialFiles(byte[] xapHost, XapReadItems xapReadItems)
            if (xapReadItems != null)
                //TODO: maybe specify this list as something passed in by the user???
                var specialFilesToCopyIntoHostXap = new List<string>
                var filesToCopyIntoHostXap = (from x in xapReadItems.FilesContianedWithinXap
                                              from specialFile in specialFilesToCopyIntoHostXap
                                              where x.FileName.Equals(specialFile, StringComparison.OrdinalIgnoreCase)
                                              select x).ToList();
                if (filesToCopyIntoHostXap.Any())
                    xapHost = RewriteZipHostWithFiles(xapHost, filesToCopyIntoHostXap);
            return xapHost;


This section allows "ServiceReferences.ClientConfig" to be added to Statlight xap and rest are ignored. This impacts loading any file which is contained inside SUT xap and are not embedded resource.

Any reason behind this decision. What would be the best solution to this defect?.




Feb 21, 2011 at 4:34 AM

We have some options.

1. You embed the file as a resource so when your assembly is loaded, you just stream the resource out of the loaded assembly.

2. We look to copy (in the function you found above) every file that is not a .dll over. (might save some people some debugging of their tests).

3. We push people to write Silverlight tests and not take dependencies on such external resources.

I've encouraged #3 above except for the WCF config file as you can't work around that. However, I'm leaning more toward #2 above just to avoid such questions in the discussion forum. If you'd like to fork the project and give it a try I'd be interested in what you find out.

Hope this helps.

Mar 4, 2011 at 5:30 PM

StatLight has been re-written to apply the option 2 above - with the exception of it copies all files, including *.dll's and should now work. Hope this helps.

Mar 4, 2011 at 6:03 PM

Thanks much Jason.


- Krishna