none
Dynamic Assemblies without pointing to specific dependency versions? RRS feed

  • Question

  • We have a scenario where we create assemblies through code with the AssemblyBuilder class, and embed a XAML file (actually a WF.NET xaml workflow definition).

    Everything worked great until we ran into an upgrade version.  We are working on version 2 of the product and all of a sudden the dependencies for the dynamically built assemblies can no longer be resolved. 

    I believe this is because the assembly was built using 1.0.0.0 (for example) dependency versions, and our next release uses 1.1.0.0 dependency versions ... which no longer apply.

    I think my question is this - is it possible to dynamically build an assembly without it's dependencies pointing to (or looking for) a specific version?  Sort of like how you can change the VS reference of SpecificVersion="False" .... can u do the same thing somehow in code?

    Here's a snippet for how we're compiling the assembly:

     AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(ns) { Version = new Version(1, 0, 0, 0) },
    AssemblyBuilderAccess.RunAndSave, targetfolder);
    
    ModuleBuilder mb = ab.DefineDynamicModule(ns + ".dll", ns + ".dll");
                
    
    // Part 0: load the XAML
    XamlSchemaContext schemaContext = new XamlSchemaContext();
    
    Stream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(wfXamlDef.WorkflowXAMLDefinition));
    
    object xamlLoadedObject;
    using (var xamlReader = new XamlXmlReader(stream))
                {
                    var builderReader = ActivityXamlServices.CreateBuilderReader(xamlReader, schemaContext);
                    xamlLoadedObject = XamlServices.Load(builderReader);
                    builderReader.Close();
                }
    
    stream.Close();
    
    ActivityBuilder activityBuilder = (ActivityBuilder)xamlLoadedObject;
    activityBuilder.Name = Eclipsys.Infrastructure.VisualWorkflow.Security.InfrastructureConstants.SavedWorkflowClassName;
    
    // Part 1: define the class
    TypeBuilder newClass = BuildType(mb, activityBuilder, false, wfXamlDef);
    Type createdType = newClass.CreateType();
    
    string magicXaml = GenerateXAML(activityBuilder, fakeType);
    MemoryStream stringStream = new MemoryStream(Encoding.Unicode.GetBytes(magicXaml));
    
    // Part 2: embed the XAML as a manifest
    string xamlResourceName = createdType.FullName + ".xaml";
    
    mb.DefineManifestResource(xamlResourceName, stringStream, ResourceAttributes.Public);
    
                
    
    // End: save the generated assembly
    try
    {
        ab.Save(ns + ".dll");
    }

    Tuesday, November 6, 2012 10:32 PM

Answers

All replies