Beispiel #1
0
        /// <summary> Serialize an assembly to a byte array </summary>
        /// <param name="assembly"> Assembly to be serialized </param>
        /// <param name="referencedDynamicAssembly">
        /// List of other assembly that have types referenced by <see cref="assembly"/>
        /// and that are dynamic assembly. The .net assembly loader can't find those
        /// otherwize
        /// </param>
        /// <returns> The serialized assembly. </returns>
        public byte[] GenerateAssemblyBytes(Assembly assembly, IEnumerable <Assembly> referencedDynamicAssembly)
        {
            Initialize(assembly, referencedDynamicAssembly);

            if (_metadata.SourceAssembly.EntryPoint != null)
            {
                // See "<Module>" type definition below.
                throw new NotSupportedException("Entry point is not supported.");
            }

            var name = _metadata.SourceAssembly.GetName();

            var assemblyPublicKey = name.GetPublicKey();
            var assemblyHandle    = _metadata.Builder.AddAssembly(
                _metadata.GetOrAddString(ApplyNameChange(name.Name)),
                name.Version,
                _metadata.GetOrAddString(name.CultureName),
                assemblyPublicKey.Length > 0 ? _metadata.GetOrAddBlob(name.GetPublicKey()) : default,