Пример #1
0
        public static void SerializeWithBinaryFormatter_DeserializeWithBinaryWriter(string key)
        {
            AppContext.SetSwitch(enableBinaryFormatter, true);
            AppContext.SetSwitch(enableBinaryFormatterInTypeConverter, true);
            var context = new DesigntimeLicenseContext();

            context.SetSavedLicenseKey(typeof(int), key);
            string tempPath = Path.GetTempPath();

            try
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    long position = stream.Position;
                    DesigntimeLicenseContextSerializer.Serialize(stream, key, context);
                    stream.Seek(position, SeekOrigin.Begin);
                    VerifyStreamFormatting(stream);

                    using (FileStream outStream = File.Create(Path.Combine(tempPath, "_temp_SerializeWithBinaryFormatter_DeserializeWithBinaryWriter")))
                    {
                        stream.Seek(position, SeekOrigin.Begin);
                        stream.CopyTo(outStream);
                    }
                }

                RemoteInvokeHandle handle = RemoteExecutor.Invoke((key) =>
                {
                    var assembly = typeof(DesigntimeLicenseContextSerializer).Assembly;
                    Type runtimeLicenseContextType = assembly.GetType("System.ComponentModel.Design.RuntimeLicenseContext");
                    Assert.NotNull(runtimeLicenseContextType);
                    object runtimeLicenseContext = Activator.CreateInstance(runtimeLicenseContextType);
                    Assert.NotNull(runtimeLicenseContext);
                    FieldInfo _savedLicenseKeys = runtimeLicenseContextType.GetField("_savedLicenseKeys", BindingFlags.NonPublic | BindingFlags.Instance);
                    Assert.NotNull(_savedLicenseKeys);
                    _savedLicenseKeys.SetValue(runtimeLicenseContext, new Hashtable());

                    Type designtimeLicenseContextSerializer = assembly.GetType("System.ComponentModel.Design.DesigntimeLicenseContextSerializer");
                    Assert.NotNull(designtimeLicenseContextSerializer);
                    MethodInfo deserializeMethod = designtimeLicenseContextSerializer.GetMethod("Deserialize", BindingFlags.NonPublic | BindingFlags.Static);
                    Assert.NotNull(deserializeMethod);

                    string tempPath = Path.GetTempPath();
                    using (FileStream stream = File.Open(Path.Combine(tempPath, "_temp_SerializeWithBinaryFormatter_DeserializeWithBinaryWriter"), FileMode.Open))
                    {
                        TargetInvocationException exception = Assert.Throws <TargetInvocationException>(() => deserializeMethod.Invoke(null, new object[] { stream, key, runtimeLicenseContext }));
                        Assert.IsType <NotSupportedException>(exception.InnerException);
                    }
                }, key);

                handle.Process.WaitForExit();
                handle.Dispose();
            }
            finally
            {
                File.Delete(Path.Combine(tempPath, "_temp_SerializeWithBinaryFormatter_DeserializeWithBinaryWriter"));
            }
        }
Пример #2
0
        public static void SerializeAndDeserialize(bool useBinaryFormatter, string key)
        {
            RemoteInvokeOptions options = new RemoteInvokeOptions();

            if (useBinaryFormatter)
            {
                options.RuntimeConfigurationOptions.Add(enableBinaryFormatterInTypeConverter, bool.TrueString);
            }
            RemoteExecutor.Invoke((key) =>
            {
                var context = new DesigntimeLicenseContext();
                context.SetSavedLicenseKey(typeof(int), key);
                var assembly = typeof(DesigntimeLicenseContextSerializer).Assembly;
                Type runtimeLicenseContextType = assembly.GetType("System.ComponentModel.Design.RuntimeLicenseContext");
                Assert.NotNull(runtimeLicenseContextType);
                object runtimeLicenseContext = Activator.CreateInstance(runtimeLicenseContextType);
                FieldInfo _savedLicenseKeys  = runtimeLicenseContextType.GetField("_savedLicenseKeys", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.NotNull(_savedLicenseKeys);
                _savedLicenseKeys.SetValue(runtimeLicenseContext, new Hashtable());
                Assert.NotNull(runtimeLicenseContext);

                Type designtimeLicenseContextSerializer = assembly.GetType("System.ComponentModel.Design.DesigntimeLicenseContextSerializer");
                Assert.NotNull(designtimeLicenseContextSerializer);
                MethodInfo deserializeMethod = designtimeLicenseContextSerializer.GetMethod("Deserialize", BindingFlags.NonPublic | BindingFlags.Static);

                using (MemoryStream stream = new MemoryStream())
                {
                    long position = stream.Position;
                    DesigntimeLicenseContextSerializer.Serialize(stream, key, context);
                    stream.Seek(position, SeekOrigin.Begin);
                    VerifyStreamFormatting(stream);
                    deserializeMethod.Invoke(null, new object[] { stream, key, runtimeLicenseContext });
                    Hashtable savedLicenseKeys = runtimeLicenseContext.GetType().GetField("_savedLicenseKeys", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(runtimeLicenseContext) as Hashtable;
                    Assert.NotNull(savedLicenseKeys);
                    var value = savedLicenseKeys[typeof(int).AssemblyQualifiedName];
                    Assert.True(value is string);
                    Assert.Equal(key, value);
                }
            }, key, options).Dispose();
        }
Пример #3
0
            /// <summary>
            /// Creates the whole license file.
            /// </summary>
            /// <param name="licenseTask">The <see cref="LicenseTask" /> instance for which the license file should be created.</param>
            /// <param name="licensesFile">The .licenses file to create.</param>
            public void CreateLicenseFile(LicenseTask licenseTask, string licensesFile)
            {
                ArrayList assemblies = new ArrayList();

                // create assembly resolver
                AssemblyResolver assemblyResolver = new AssemblyResolver(licenseTask);

                // attach assembly resolver to the current domain
                assemblyResolver.Attach();

                licenseTask.Log(Level.Verbose, ResourceUtils.GetString("String_LoadingAssemblies"));

                try {
                    // first, load all the assemblies so that we can search for the
                    // licensed component
                    foreach (string assemblyFileName in licenseTask.Assemblies.FileNames)
                    {
                        Assembly assembly = Assembly.LoadFrom(assemblyFileName);
                        if (assembly != null)
                        {
                            // output assembly filename to build log
                            licenseTask.Log(Level.Verbose, ResourceUtils.GetString("String_AssemblyLoaded"),
                                            assemblyFileName);
                            // add assembly to list of loaded assemblies
                            assemblies.Add(assembly);
                        }
                    }

                    DesigntimeLicenseContext dlc = new DesigntimeLicenseContext();
                    LicenseManager.CurrentContext = dlc;

                    // read the input file
                    using (StreamReader sr = new StreamReader(licenseTask.InputFile.FullName)) {
                        Hashtable licenseTypes = new Hashtable();

                        licenseTask.Log(Level.Verbose, ResourceUtils.GetString("String_CreatingLicenses"));

                        while (true)
                        {
                            string line = sr.ReadLine();

                            if (line == null)
                            {
                                break;
                            }

                            line = line.Trim();
                            // Skip comments, empty lines and already processed assemblies
                            if (line.StartsWith("#") || line.Length == 0 || licenseTypes.Contains(line))
                            {
                                continue;
                            }

                            licenseTask.Log(Level.Verbose, "{0}: ", line);

                            // Strip off the assembly name, if it exists
                            string typeName;

                            if (line.IndexOf(',') != -1)
                            {
                                typeName = line.Split(',')[0];
                            }
                            else
                            {
                                typeName = line;
                            }

                            Type tp = null;

                            // try to locate the type in each assembly
                            foreach (Assembly assembly in assemblies)
                            {
                                if (tp == null)
                                {
                                    tp = assembly.GetType(typeName, false, true);
                                }

                                if (tp != null)
                                {
                                    break;
                                }
                            }

                            if (tp == null)
                            {
                                try {
                                    // final attempt, assuming line contains
                                    // assembly qualfied name
                                    tp = Type.GetType(line, false, false);
                                } catch {
                                    // ignore error, we'll report the load
                                    // failure later
                                }
                            }

                            if (tp == null)
                            {
                                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                                       ResourceUtils.GetString("NA2016"), typeName), licenseTask.Location);
                            }
                            else
                            {
                                // add license type to list of processed license types
                                licenseTypes[line] = tp;
                            }

                            // ensure that we've got a licensed component
                            if (tp.GetCustomAttributes(typeof(LicenseProviderAttribute), true).Length == 0)
                            {
                                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                                       ResourceUtils.GetString("NA2017"), tp.FullName),
                                                         licenseTask.Location);
                            }

                            try {
                                LicenseManager.CreateWithContext(tp, dlc);
                            } catch (Exception ex) {
                                if (IsSerializable(ex))
                                {
                                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                                           ResourceUtils.GetString("NA2018"), tp.FullName),
                                                             licenseTask.Location, ex);
                                }

                                // do not directly pass the exception as inner
                                // exception to BuildException as the exception
                                // is not serializable, so construct a new
                                // exception with message set to message of
                                // original exception
                                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                                       ResourceUtils.GetString("NA2018"), tp.FullName),
                                                         licenseTask.Location, new Exception(ex.Message));
                            }
                        }
                    }

                    // overwrite the existing file, if it exists - is there a better way?
                    if (File.Exists(licensesFile))
                    {
                        File.SetAttributes(licensesFile, FileAttributes.Normal);
                        File.Delete(licensesFile);
                    }

                    // write out the license file, keyed to the appropriate output
                    // target filename
                    // this .license file will only be valid for this exe/dll
                    using (FileStream fs = new FileStream(licensesFile, FileMode.Create)) {
                        DesigntimeLicenseContextSerializer.Serialize(fs, licenseTask.Target, dlc);
                        licenseTask.Log(Level.Verbose, ResourceUtils.GetString("String_CreatedNewLicense"),
                                        licensesFile);
                    }

                    dlc = null;
                } catch (BuildException) {
                    // re-throw exception
                    throw;
                } catch (Exception ex) {
                    if (IsSerializable(ex))
                    {
                        throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                               ResourceUtils.GetString("NA2019"), licenseTask.InputFile.FullName),
                                                 licenseTask.Location, ex);
                    }
                    else
                    {
                        // do not directly pass the exception as inner exception to
                        // BuildException as the exception might not be serializable,
                        // so construct a
                        // new exception with message set to message of
                        // original exception
                        throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                               ResourceUtils.GetString("NA2019"), licenseTask.InputFile.FullName),
                                                 licenseTask.Location, new Exception(ex.Message));
                    }
                } finally {
                    // detach assembly resolver from the current domain
                    assemblyResolver.Detach();
                }
            }
Пример #4
0
        static int Main(string[] args)
        {
            bool          verbose    = false;
            string        target     = null;
            string        complist   = null;
            string        targetdir  = ".";
            List <string> references = new List <string>();

            bool      nologo = false;
            bool      help   = false;
            OptionSet p      = new OptionSet()
            {
                { "v|verbose", "Verbose output", v => verbose = v != null },
                { "t|target=", "Target assembly name", v => target = v },
                { "c|complist=", "licx file to compile", v => complist = v },
                { "i|load=", "Reference to load", v => { if (v != null)
                                                         {
                                                             references.Add(v);
                                                         }
                  } },
                { "o|outdir=", "Output directory for the .licenses file", v => targetdir = v },
                { "nologo", "Do not display logo", v => nologo = null != v },
                { "h|?|help", "Show help", v => help = v != null }
            };
            List <string> extra;

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine("lc: " + e.Message);
                Console.WriteLine("try lc --help for more information");
                return(1);
            }
            if (!nologo)
            {
                Console.WriteLine("Mono License Compiler");
                Console.WriteLine("Copyright (c) 2009 by RemObjects Software");
            }
            if (help)
            {
                Console.WriteLine();
                Console.WriteLine("lc -c filename -t targetassembly [-i references] [-v] [-o] [-nologo]");
                Console.WriteLine();
                Console.WriteLine("Options:");
                p.WriteOptionDescriptions(Console.Out);
                return(1);
            }
            if (extra.Count > 0)
            {
                Console.WriteLine("Unexpected arguments passed on cmd line");
                return(1);
            }
            if (target == null || complist == null)
            {
                Console.WriteLine("No target/complist passed");
                return(1);
            }
            try
            {
                if (!File.Exists(complist))
                {
                    Console.WriteLine("Could not find file: " + complist);
                    return(1);
                }

                LCLicenseContext ctx = new LCLicenseContext();
                ctx.LicxFilename = complist;
                if (verbose)
                {
                    Console.WriteLine("Input file: " + complist);
                }
                ctx.OutputFilename = Path.Combine(targetdir ?? ".", target) + ".licenses";
                if (verbose)
                {
                    Console.WriteLine("Output filename: " + ctx.OutputFilename);
                }
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
                privatePaths.Add(".");
                Dictionary <string, Assembly> loaded = new Dictionary <string, Assembly>();
                foreach (string reference in references)
                {
                    string path = Path.GetDirectoryName(reference);
                    if (!privatePaths.Contains(path))
                    {
                        if (verbose)
                        {
                            Console.WriteLine("Adding " + Path.GetDirectoryName(reference) + " to private paths");
                        }
                        privatePaths.Add(path);
                    }
                    Assembly asm = Assembly.LoadFrom(reference);
                    loaded.Add(asm.GetName().Name, asm);
                    if (verbose)
                    {
                        Console.WriteLine("Loaded assembly: " + asm.GetName().ToString());
                    }
                }

                using (StreamReader sr = new StreamReader(complist))
                {
                    int    lineno = 0;
                    string line   = "";
                    while (sr.Peek() != -1)
                    {
                        try
                        {
                            line = sr.ReadLine();
                            if (line == null || line == "" || line[0] == '#')
                            {
                                continue;
                            }
                            if (verbose)
                            {
                                Console.WriteLine("Generating license for: " + line);
                            }

                            string[] sLine = line.Split(new char[] { ',' }, 2);
                            Type     stype = null;
                            if (sLine.Length == 1)
                            {
                                stype = Type.GetType(line, false, true);
                                if (stype == null)
                                {
                                    foreach (KeyValuePair <string, Assembly> et in loaded)
                                    {
                                        stype = et.Value.GetType(sLine[0], false, true);
                                        if (stype != null)
                                        {
                                            if (verbose)
                                            {
                                                Console.WriteLine("Found type in " + et.Key);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (sLine[1].IndexOf(',') >= 0)
                                {
                                    stype = Type.GetType(line, false, true);
                                }
                                else
                                {
                                    string s = sLine[1].Trim();
                                    foreach (KeyValuePair <string, Assembly> et in loaded)
                                    {
                                        if (String.Compare(et.Key, s, true, CultureInfo.InvariantCulture) == 0)
                                        {
                                            stype = et.Value.GetType(sLine[0], false, true);
                                            if (stype != null)
                                            {
                                                if (verbose)
                                                {
                                                    Console.WriteLine("Found type in " + et.Key);
                                                }
                                                break;
                                            }
                                        }
                                    }
                                    if (stype == null)
                                    {
                                        foreach (KeyValuePair <string, Assembly> et in loaded)
                                        {
                                            stype = et.Value.GetType(sLine[0], false, true);
                                            if (stype != null)
                                            {
                                                if (verbose)
                                                {
                                                    Console.WriteLine("Found type in " + et.Key);
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            if (stype == null)
                            {
                                throw new Exception("Unable to find type: " + line);
                            }
                            LicenseManager.CreateWithContext(stype, ctx);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Exception during compiling " + complist + ": " + lineno);
                            Console.WriteLine(e.ToString());
                        }
                    }
                }

                using (FileStream fs = new FileStream(ctx.OutputFilename, FileMode.Create))
                {
                    try
                    {
                        DesigntimeLicenseContextSerializer.Serialize(fs, target.ToUpper(CultureInfo.InvariantCulture), ctx);
                    }
                    catch {}
                    if (fs.Length == 0) // older mono does not support this, but when it does, we should use the proper version.
                    {
                        IntSerialize(fs, target.ToUpper(CultureInfo.InvariantCulture), ctx);
                    }
                }
                if (verbose)
                {
                    Console.WriteLine("Saved to: " + Path.GetFullPath(ctx.OutputFilename));
                }
                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.ToString());
                return(1);
            }
        }
        public override string?GetSavedLicenseKey(Type type, Assembly?resourceAssembly)
        {
            if (_savedLicenseKeys == null || _savedLicenseKeys[type.AssemblyQualifiedName !] == null)
            {
                if (_savedLicenseKeys == null)
                {
                    _savedLicenseKeys = new Hashtable();
                }

                if (resourceAssembly == null)
                {
                    resourceAssembly = Assembly.GetEntryAssembly();
                }

                if (resourceAssembly == null)
                {
                    // If Assembly.EntryAssembly returns null, then we will
                    // try everything.
                    foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        // Assemblies loaded in memory return empty string from Location.
                        string location = asm.Location;
                        if (location == string.Empty)
                        {
                            continue;
                        }

                        string fileName = new FileInfo(location).Name;

                        Stream?s = asm.GetManifestResourceStream(fileName + ".licenses");
                        if (s == null)
                        {
                            // Since the casing may be different depending on how the assembly was loaded,
                            // we'll do a case insensitive lookup for this manifest resource stream...
                            s = CaseInsensitiveManifestResourceStreamLookup(asm, fileName + ".licenses");
                        }

                        if (s != null)
                        {
                            DesigntimeLicenseContextSerializer.Deserialize(s, fileName.ToUpperInvariant(), this);
                            break;
                        }
                    }
                }
                else
                {
                    string location = resourceAssembly.Location;
                    if (location != string.Empty)
                    {
                        string fileName        = Path.GetFileName(location);
                        string licResourceName = fileName + ".licenses";

                        // First try the filename
                        Stream?s = resourceAssembly.GetManifestResourceStream(licResourceName);
                        if (s == null)
                        {
                            string?     resolvedName      = null;
                            CompareInfo comparer          = CultureInfo.InvariantCulture.CompareInfo;
                            string      shortAssemblyName = resourceAssembly.GetName().Name !;
                            // If the assembly has been renamed, we try our best to find a good match in the available resources
                            // by looking at the assembly name (which doesn't change even after a file rename) + ".exe.licenses" or + ".dll.licenses"
                            foreach (string existingName in resourceAssembly.GetManifestResourceNames())
                            {
                                if (comparer.Compare(existingName, licResourceName, CompareOptions.IgnoreCase) == 0 ||
                                    comparer.Compare(existingName, shortAssemblyName + ".exe.licenses", CompareOptions.IgnoreCase) == 0 ||
                                    comparer.Compare(existingName, shortAssemblyName + ".dll.licenses", CompareOptions.IgnoreCase) == 0)
                                {
                                    resolvedName = existingName;
                                    break;
                                }
                            }
                            if (resolvedName != null)
                            {
                                s = resourceAssembly.GetManifestResourceStream(resolvedName);
                            }
                        }
                        if (s != null)
                        {
                            DesigntimeLicenseContextSerializer.Deserialize(s, fileName.ToUpperInvariant(), this);
                        }
                    }
                }
            }
            return((string?)_savedLicenseKeys[type.AssemblyQualifiedName !]);
Пример #6
0
        /// <include file='doc\LicenseCompiler.uex' path='docs/doc[@for="LicenseCompiler.Main"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static int Main(string[] args)
        {
            int retcode = 0;

            try {
                if (ProcessArgs(args))
                {
                    // Hook up the type resolution events for the appdomain so we can delay load
                    // any assemblies/types users gave us in the /i option.
                    //
                    ResolveEventHandler assemblyResolveEventHandler = new ResolveEventHandler(OnAssemblyResolve);
                    AppDomain.CurrentDomain.AssemblyResolve += assemblyResolveEventHandler;

                    DesigntimeLicenseContext ctx = new DesigntimeLicenseContext();

                    foreach (string componentListFile in compLists)
                    {
                        OutputLine("Processing complist '" + componentListFile + "'...");
                        Hashtable    types = new Hashtable();
                        StreamReader sr    = new StreamReader(componentListFile);

                        string line       = null;
                        int    lineNumber = 0;
                        do
                        {
                            line = sr.ReadLine();
                            lineNumber++;

                            if (line != null && line.Length > 0)
                            {
                                if (!line.StartsWith("#"))
                                {
                                    if (!types.ContainsKey(line))
                                    {
                                        if (verbose)
                                        {
                                            OutputLine(componentListFile + "(" + lineNumber.ToString() + ") : info LC0001 : Processing component entry '" + line + "'");
                                        }
                                        types[line] = Type.GetType(line);
                                        if (types[line] != null)
                                        {
                                            if (verbose)
                                            {
                                                OutputLine(componentListFile + "(" + lineNumber.ToString() + ") : info LC0002 : Resolved entry to '" + ((Type)types[line]).AssemblyQualifiedName + "'");
                                            }
                                            try {
                                                LicenseManager.CreateWithContext((Type)types[line], ctx);
                                            }
                                            catch (Exception e) {
                                                OutputLine(componentListFile + "(" + lineNumber.ToString() + ") : error LC0004 : Exception occured creating type '" + e.GetType() + "'");
                                                if (verbose)
                                                {
                                                    OutputLine("Complete Error Message:");
                                                    OutputLine(e.ToString());
                                                }
                                            }
                                        }
                                        else
                                        {
                                            OutputLine(componentListFile + "(" + lineNumber.ToString() + ") : error LC0003 : Unabled to resolve type '" + line + "'");
                                            retcode = -1;
                                        }
                                    }
                                }
                            }
                        } while (line != null);
                    }

                    AppDomain.CurrentDomain.AssemblyResolve -= assemblyResolveEventHandler;

                    string targetName = null;
                    if (outputDir != null)
                    {
                        targetName = outputDir + "\\" + targetPE.ToLower(CultureInfo.InvariantCulture) + ".licenses";
                    }
                    else
                    {
                        targetName = targetPE.ToLower(CultureInfo.InvariantCulture) + ".licenses";
                    }

                    OutputLine("Creating Licenses file " + targetName + "...");
                    Stream fs = null;
                    try {
                        fs = File.Create(targetName);
                        DesigntimeLicenseContextSerializer.Serialize(fs, targetPE.ToUpper(CultureInfo.InvariantCulture), ctx);
                    }
                    finally {
                        if (fs != null)
                        {
                            fs.Flush();
                            fs.Close();
                        }
                    }
                }
            }
            catch (Exception e) {
                // UNDONE(SreeramN): Localize this.
                //
                OutputLine("Error LC0000: '" + e.Message + "'");
            }
            return(retcode);
        }
Пример #7
0
        /// <include file='doc\LicenseCompiler.uex' path='docs/doc[@for="LicenseCompiler.GenerateLicenses2"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static MemoryStream GenerateLicenses(string fileContents, string targetPE, ITypeResolutionService resolver, DesigntimeLicenseContext ctx)
        {
            // UNDONE(sreeramn): This is a temporary check... this is needed so the licensing
            // code works with 9216 of VS which does not have a fix from Izzy. We can safely
            // remove this with 9224 or greater VS.
            //
            if (ctx == null)
            {
                ctx = new DesigntimeLicenseContext();
            }

            Hashtable    types  = new Hashtable();
            StringReader reader = new StringReader(fileContents);

            string line       = null;
            int    lineNumber = 0;

            do
            {
                line = reader.ReadLine();
                lineNumber++;

                if (line != null && line.Length > 0)
                {
                    if (!line.StartsWith("#"))
                    {
                        if (!types.ContainsKey(line))
                        {
                            if (resolver != null)
                            {
                                types[line] = resolver.GetType(line);

                                // If we cannot find the strong-named type, then try to see
                                // if the TypeResolver can bind to partial names. For this,
                                // we will strip out the partial names and keep the rest of the
                                // strong-name informatio to try again.
                                //
                                if (types[line] == null)
                                {
                                    string[] typeParts = line.Split(new char[] { ',' });

                                    // Break up the type name from the rest of the assembly strong name.
                                    //
                                    if (typeParts != null && typeParts.Length > 2)
                                    {
                                        string partialName = typeParts[0].Trim();

                                        for (int i = 1; i < typeParts.Length; ++i)
                                        {
                                            string s = typeParts[i].Trim();
                                            if (!s.StartsWith("Version=") && !s.StartsWith("version="))
                                            {
                                                partialName = partialName + ", " + s;
                                            }
                                        }

                                        types[line] = resolver.GetType(partialName);
                                    }
                                }
                            }

                            // If the resolver completely failed, then see if the default
                            // Fusion look up will find the type.
                            //
                            if (types[line] == null)
                            {
                                types[line] = Type.GetType(line);
                            }

                            if (types[line] != null)
                            {
                                try {
                                    LicenseManager.CreateWithContext((Type)types[line], ctx);
                                }
                                catch (Exception e) {
                                    throw new LicenseCompilationException(lineNumber, 4, "Exception occured creating type '" + e.GetType() + "'");
                                }
                            }
                            else
                            {
                                throw new LicenseCompilationException(lineNumber, 3, "Unabled to resolve type '" + line + "'");
                            }
                        }
                    }
                }
            } while (line != null);

            MemoryStream ms = new MemoryStream();

            DesigntimeLicenseContextSerializer.Serialize(ms, targetPE.ToUpper(CultureInfo.InvariantCulture), ctx);
            return(ms);
        }