More reliable way to generate assembly cache files - suggestion

SyntaxEditor .NET Languages Add-on for Silverlight Forum

Posted 6 years ago by Chris Honselaar
Avatar

The documentation instructs us to generate assembly cache files indirectly by loading the assemblies into the application project and then retrieving the cache files that should be generated automatically. But this seems to work unreliably - for a lot of assemblies, the cache file is never generated for some reason, although the assemblies themselves load perfectly fine (and their types are resolved properly in the editor). Perhaps this has something to do with optimizations in the file-based cache generator.

The following snippet will create cache files directly, and works 100% reliably for me:

private void GetCache(params string[] paths)
{
    var repository = new FileBasedAssemblyRepository(@"C:\temp\Cache");
    paths.ToList().ForEach(path =>
        {
            var assemblyCache = repository.LoadFrom(path);
            var serializer = new BinaryAssemblySerializer();
            using (var stream = File.Create(String.Format(@"c:\temp\Cache\{0}.Reflection.dat", Path.GetFileName(path))))
            {
                serializer.SaveToStream(assemblyCache, stream);
            }                    
        });
}

 

Is this approach valid? In that case it might be good to mention this in the documentation. I was completely stuck until I found this.

[Modified 6 years ago]

Comments (3)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Chris,

Odd, we haven't heard of there being any problems with the code mentioned in that documentation topic.  Are you able to reliably reproduce it?  If so, can you e-mail our support address with a simple project that shows it?  Please reference this post and rename the .zip file extension so it doesn't get spam blocked.

I would think that the code you posted should work fine too though.


Actipro Software Support

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Chris,

Thanks for the sample, it looks like it was due to the change we made in 2013.1 for this thread.  Basically if we load the assembly in AssemblyRepositoryBase.LoadFrom via File.ReadAllBytes, then the path information is lost.  So in the next version, we have updated our internal code to pass along the path properly and that gets it working.

As a workaround, you can continue using your method for now, or could use Assembly.ReflectionOnlyLoadFrom and pass that resulting Assembly in instead, since that will include path info.


Actipro Software Support

Posted 6 years ago by Chris Honselaar
Avatar

Thanks! That would explain why mscorlib worked but any other assembly wouldn't - and also why I thought it was working sometimes: I guess I stumbled across some older assembly cache files generated by the previous version of the SyntaxEditor.

I do think using BinaryAssemblySerializer to create the files directly is actually easier to understand and affords more control. For my current scenario I need to generate assembly caches on demand at runtime, so this seems like the way to go.

The latest build of this product (v2018.1 build 0233) was released 21 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.