1

Closed

Error in DynamicLoader: Local variable scope was not properly closed.

description

I've attached a file, I am compiling that file into an assembly then using CCI to dynamically load that assembly. I am using the version of cci available on nuget (v1.0.13.0).

I am able to successfully use this on other code, however this particular example is causing cci to have an error for some reason.

Here is the code I am using to load the assembly:
using (var host = new PeReader.DefaultHost())
{
    using (var pdbStream = File.OpenRead(generatedPdb))
    {
        var pdbreader = new PdbReader(pdbStream, host);
        var name = Path.GetFileNameWithoutExtension(generatedAssembly);
        var loaded = host.LoadAssembly(new Microsoft.Cci.AssemblyIdentity(host.NameTable.GetNameFor(name), null, new Version(), null, generatedAssembly));

        var dynamicLoader = new DynamicLoader(pdbreader, pdbreader);
        var dynamicAssembly = dynamicLoader.Load(loaded);
        var type = dynamicAssembly.GetType(transformerType);
        var instance = (Transformer)Activator.CreateInstance(type);
        runAssembly(instance, type.GetMethod("Parse", new[] { typeof(string) }));
    }
}
InvalidOperationException
Message:
Local variable scope was not properly closed.

Stack:
at System.Reflection.Emit.MethodBuilder.CreateMethodBodyHelper(ILGenerator il)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at Microsoft.Cci.ReflectionEmitter.DynamicLoader.TypeCreator.TraverseChildren(INamespaceTypeDefinition namespaceTypeDefinition)
at Microsoft.Cci.MetadataTraverser.Traverse(INamespaceTypeDefinition namespaceTypeDefinition)
at Microsoft.Cci.MetadataTraverser.Dispatcher.Visit(INamespaceTypeDefinition namespaceTypeDefinition)
at Microsoft.Cci.MetadataReader.ObjectModelImplementation.NamespaceType.Dispatch(IMetadataVisitor visitor)
at Microsoft.Cci.MetadataTraverser.Traverse(ITypeDefinition typeDefinition)
at Microsoft.Cci.MetadataTraverser.Traverse(IEnumerable1 types)
at Microsoft.Cci.ReflectionEmitter.DynamicLoader.Load(IAssembly assembly)
at MetaSharp.Transformation.Tests.Integration.IntegrationTests2.CompileAndRunGrammar(GrammarParser2 parser, GrammarTransformer2 transformer, String grammarPath, String transformerType, Action
2 runAssembly) in C:\Users\justin\projects\codeplex\metasharp\src\MetaSharp.Transformation.Tests\Integration\IntegrationTests2.cs:line 215
at MetaSharp.Transformation.Tests.Integration.IntegrationTests2.CanCompileTokenizer() in C:\Users\justin\projects\codeplex\metasharp\src\MetaSharp.Transformation.Tests\Integration\IntegrationTests2.cs:line 41

file attachments

Closed May 6, 2014 at 6:15 PM by mikebarnett
Fixed with revision 72784.

comments