Esempio n. 1
0
    static int Main(string[] args)
    {
        var context = new DesigntimeLicenseContext();

        context.SetSavedLicenseKey(typeof(int), "key");
        AppContext.SetSwitch("System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization", true);

        using (MemoryStream stream = new MemoryStream())
        {
            long position = stream.Position;
            System.ComponentModel.Design.DesigntimeLicenseContextSerializer.Serialize(stream, "key", context);
            stream.Seek(position, SeekOrigin.Begin);

            byte[] currentBuffer = stream.ToArray();
            // Verify contents with saved stream
            byte[] correctBytes = TrimmingTests.DesigntimeLicenseContextSerialization_Stream.ASampleStream;

            if (currentBuffer.Length != correctBytes.Length)
            {
                return(-1);
            }
            for (int i = 0; i < currentBuffer.Length; i++)
            {
                if (currentBuffer[i] != correctBytes[i])
                {
                    return(-1);
                }
            }
        }

        return(100);
    }
        private static void IntSerialize(Stream o,
                                         string cryptoKey,
                                         DesigntimeLicenseContext context)
        {
            Object[] lData = new Object[2];
            lData[0] = cryptoKey;
            Hashtable lNewTable = new Hashtable();
            FieldInfo fi        =
                typeof(DesigntimeLicenseContext).GetField("savedLicenseKeys", BindingFlags.NonPublic | BindingFlags.Instance) ??
                typeof(DesigntimeLicenseContext).GetField("keys", BindingFlags.NonPublic | BindingFlags.Instance)
            ;
            Hashtable lOrgTable = (Hashtable)fi.GetValue(context);

            foreach (DictionaryEntry et in lOrgTable)
            {
                if (et.Key is string)
                {
                    lNewTable.Add(et.Key, et.Value);
                }
                else
                {
                    lNewTable.Add(((Type)et.Key).AssemblyQualifiedName, et.Value);
                }
            }
            lData[1] = lNewTable;

            BinaryFormatter lFormatter = new BinaryFormatter();

            lFormatter.Serialize(o, lData);
        }
Esempio n. 3
0
            // The CLR invokes this whenever a COM client invokes
            // IClassFactory2::GetLicInfo on a managed class.
            //
            // COM normally doesn't expect this function to fail so this method
            // should only throw in the case of a catastrophic error (stack, memory, etc.)
            private void GetLicInfo(RuntimeTypeHandle rth, ref int pRuntimeKeyAvail, ref int pLicVerified)
            {
                pRuntimeKeyAvail = 0;
                pLicVerified     = 0;

                Type    type = Type.GetTypeFromHandle(rth);
                License license;
                string  licenseKey;

                if (helperContext == null)
                {
                    helperContext = new DesigntimeLicenseContext();
                }
                else
                {
                    helperContext.savedLicenseKeys.Clear();
                }

                if (LicenseManager.ValidateInternalRecursive(helperContext, type, null, false, out license, out licenseKey))
                {
                    if (helperContext.savedLicenseKeys.Contains(type.AssemblyQualifiedName))
                    {
                        pRuntimeKeyAvail = 1;
                    }

                    if (license != null)
                    {
                        license.Dispose();
                        license = null;

                        pLicVerified = 1;
                    }
                }
            }
Esempio n. 4
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"));
            }
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        public void Test()
        {
            object lockObject = new object();

            //**DEFAULT CONTEXT & LicenseUsageMode**
            //Get CurrentContext, check default type
            Assert.AreEqual("System.ComponentModel.Design.RuntimeLicenseContext", LicenseManager.CurrentContext.GetType().ToString(), "LicenseManager #1");
            //Read default LicenseUsageMode, check against CurrentContext (LicCont).UsageMode
            Assert.AreEqual(LicenseManager.CurrentContext.UsageMode, LicenseManager.UsageMode, "LicenseManager #2");

            //**CHANGING CONTEXT**
            //Change the context and check it changes
            LicenseContext oldcontext = LicenseManager.CurrentContext;
            LicenseContext newcontext = new DesigntimeLicenseContext();

            LicenseManager.CurrentContext = newcontext;
            Assert.AreEqual(newcontext, LicenseManager.CurrentContext, "LicenseManager #3");
            //Check the UsageMode changed too
            Assert.AreEqual(newcontext.UsageMode, LicenseManager.UsageMode, "LicenseManager #4");
            //Set Context back to original
            LicenseManager.CurrentContext = oldcontext;
            //Check it went back
            Assert.AreEqual(oldcontext, LicenseManager.CurrentContext, "LicenseManager #5");
            //Check the UsageMode changed too
            Assert.AreEqual(oldcontext.UsageMode, LicenseManager.UsageMode, "LicenseManager #6");

            //**CONTEXT LOCKING**
            //Lock the context
            LicenseManager.LockContext(lockObject);
            //Try and set new context again, should throw System.InvalidOperationException: The CurrentContext property of the LicenseManager is currently locked and cannot be changed.
            bool exceptionThrown = false;

            try
            {
                LicenseManager.CurrentContext = newcontext;
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(InvalidOperationException), e.GetType(), "LicenseManager #7");
                exceptionThrown = true;
            }
            //Check the exception was thrown
            Assert.AreEqual(true, exceptionThrown, "LicenseManager #8");
            //Check the context didn't change
            Assert.AreEqual(oldcontext, LicenseManager.CurrentContext, "LicenseManager #9");
            //Unlock it
            LicenseManager.UnlockContext(lockObject);
            //Now's unlocked, change it
            LicenseManager.CurrentContext = newcontext;
            Assert.AreEqual(newcontext, LicenseManager.CurrentContext, "LicenseManager #10");
            //Change it back
            LicenseManager.CurrentContext = oldcontext;


            //Lock the context
            LicenseManager.LockContext(lockObject);
            //Unlock with different "user" should throw System.ArgumentException: The CurrentContext property of the LicenseManager can only be unlocked with the same contextUser.
            object wrongLockObject = new object();

            exceptionThrown = false;
            try
            {
                LicenseManager.UnlockContext(wrongLockObject);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(ArgumentException), e.GetType(), "LicenseManager #11");
                exceptionThrown = true;
            }
            Assert.AreEqual(true, exceptionThrown, "LicenseManager #12");
            //Unlock it
            LicenseManager.UnlockContext(lockObject);

            //** bool IsValid(Type);
            Assert.AreEqual(true, LicenseManager.IsLicensed(typeof(UnlicensedObject)), "LicenseManager #13");
            Assert.AreEqual(true, LicenseManager.IsLicensed(typeof(LicensedObject)), "LicenseManager #14");
            Assert.AreEqual(false, LicenseManager.IsLicensed(typeof(InvalidLicensedObject)), "LicenseManager #15");

            Assert.AreEqual(true, LicenseManager.IsValid(typeof(UnlicensedObject)), "LicenseManager #16");
            Assert.AreEqual(true, LicenseManager.IsValid(typeof(LicensedObject)), "LicenseManager #17");
            Assert.AreEqual(false, LicenseManager.IsValid(typeof(InvalidLicensedObject)), "LicenseManager #18");

            UnlicensedObject      unlicensedObject      = new UnlicensedObject();
            LicensedObject        licensedObject        = new LicensedObject();
            InvalidLicensedObject invalidLicensedObject = new InvalidLicensedObject();

            //** bool IsValid(Type, object, License);
            License license = null;

            Assert.AreEqual(true, LicenseManager.IsValid(unlicensedObject.GetType(), unlicensedObject, out license), "LicenseManager #19");
            Assert.AreEqual(null, license, "LicenseManager #20");

            license = null;
            Assert.AreEqual(true, LicenseManager.IsValid(licensedObject.GetType(), licensedObject, out license), "LicenseManager #21");
            Assert.AreEqual("TestLicense", license.GetType().Name, "LicenseManager #22");

            license = null;
            Assert.AreEqual(false, LicenseManager.IsValid(invalidLicensedObject.GetType(), invalidLicensedObject, out license), "LicenseManager #23");
            Assert.AreEqual(null, license, "LicenseManager #24");

            //** void Validate(Type);
            //Shouldn't throw exception
            LicenseManager.Validate(typeof(UnlicensedObject));
            //Shouldn't throw exception
            LicenseManager.Validate(typeof(LicensedObject));
            //Should throw exception
            exceptionThrown = false;
            try
            {
                LicenseManager.Validate(typeof(InvalidLicensedObject));
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(LicenseException), e.GetType(), "LicenseManager #25");
                exceptionThrown = true;
            }
            //Check the exception was thrown
            Assert.AreEqual(true, exceptionThrown, "LicenseManager #26");

            //** License Validate(Type, object);
            //Shouldn't throw exception, returns null license
            license = LicenseManager.Validate(typeof(UnlicensedObject), unlicensedObject);
            Assert.AreEqual(null, license, "LicenseManager #27");

            //Shouldn't throw exception, returns TestLicense license
            license = LicenseManager.Validate(typeof(LicensedObject), licensedObject);
            Assert.AreEqual("TestLicense", license.GetType().Name, "LicenseManager #28");

            //Should throw exception, returns null license
            exceptionThrown = false;
            try
            {
                license = null;
                license = LicenseManager.Validate(typeof(InvalidLicensedObject), invalidLicensedObject);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(LicenseException), e.GetType(), "LicenseManager #29");
                exceptionThrown = true;
            }
            //Check the exception was thrown
            Assert.AreEqual(true, exceptionThrown, "LicenseManager #30");
            Assert.AreEqual(null, license, "LicenseManager #31");


            //** object CreateWithContext (Type, LicenseContext);
            object cwc = null;

            //Test we can create an unlicensed object with no context
            cwc = LicenseManager.CreateWithContext(typeof(UnlicensedObject), null);
            Assert.AreEqual("UnlicensedObject", cwc.GetType().Name, "LicenseManager #32");
            //Test we can create RunTime with CurrentContext (runtime)
            cwc = null;
            cwc = LicenseManager.CreateWithContext(typeof(RuntimeLicensedObject),
                                                   LicenseManager.CurrentContext);
            Assert.AreEqual("RuntimeLicensedObject", cwc.GetType().Name, "LicenseManager #33");
            //Test we can't create DesignTime with CurrentContext (runtime)
            exceptionThrown = false;
            try
            {
                cwc = null;
                cwc = LicenseManager.CreateWithContext(typeof(DesigntimeLicensedObject), LicenseManager.CurrentContext);
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(LicenseException), e.GetType(), "LicenseManager #34");
                exceptionThrown = true;
            }
            //Check the exception was thrown
            Assert.AreEqual(true, exceptionThrown, "LicenseManager #35");
            //Test we can create DesignTime with A new DesignTimeContext
            cwc = null;
            cwc = LicenseManager.CreateWithContext(typeof(DesigntimeLicensedObject),
                                                   new DesigntimeLicenseContext());
            Assert.AreEqual("DesigntimeLicensedObject", cwc.GetType().Name, "LicenseManager #36");

            //** object CreateWithContext(Type, LicenseContext, object[]);
            //Test we can create RunTime with CurrentContext (runtime)
            cwc = null;
            cwc = LicenseManager.CreateWithContext(typeof(RuntimeLicensedObject),
                                                   LicenseManager.CurrentContext, new object [] { 7 });
            Assert.AreEqual("RuntimeLicensedObject", cwc.GetType().Name, "LicenseManager #37");
        }
        public void SetSavedLicenseKey_NullType_ThrowsNullReferenceException()
        {
            var context = new DesigntimeLicenseContext();

            AssertExtensions.Throws <ArgumentNullException, NullReferenceException>("type", () => context.SetSavedLicenseKey(null, "Key"));
        }
        public void SetSavedLicenseKey_ValidType_Success(string key)
        {
            var context = new DesigntimeLicenseContext();

            context.SetSavedLicenseKey(typeof(int), key);
        }
        public void GetService_Invoke_ReturnsNull()
        {
            var context = new DesigntimeLicenseContext();

            Assert.Null(context.GetService(null));
        }
        public void GetSavedLicenseKey_Invoke_ReturnsNull()
        {
            var context = new DesigntimeLicenseContext();

            Assert.Null(context.GetSavedLicenseKey(null, null));
        }
Esempio n. 11
0
 // Methods
 public static void Serialize(System.IO.Stream o, string cryptoKey, DesigntimeLicenseContext context)
 {
 }
Esempio n. 12
0
        public void SetSavedLicenseKey_NullType_ThrowsNullReferenceException()
        {
            var context = new DesigntimeLicenseContext();

            Assert.Throws <NullReferenceException>(() => context.SetSavedLicenseKey(null, "Key"));
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
        public void UsageMode_Get_ReturnsDesigntime()
        {
            var context = new DesigntimeLicenseContext();

            Assert.Equal(LicenseUsageMode.Designtime, context.UsageMode);
        }
Esempio n. 16
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();
                }
            }
	// Methods
	public static void Serialize(System.IO.Stream o, string cryptoKey, DesigntimeLicenseContext context) {}