Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C#

Self Contained Assembly

Rate me:
Please Sign up or sign in to vote.
4.95/5 (13 votes)
13 Nov 2011CPOL9 min read 48.2K   1.5K   43  
Shows how deployment of dynamically loaded assembly can be simplified by reducing the assembly to single self contained file.
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text;

namespace AssemblyLoader
{
    internal class ZipAssemblyInfo
    {
        public string AssemblyFileName { get; private set; }

        public ZipAssemblyInfo(string assemblyFileName, Assembly containingAssembly, string manifestResourceName,
                              ZipStorer.ZipFileEntry zipFileEntry)
        {
            if (string.IsNullOrWhiteSpace(assemblyFileName))
            {
                throw new ArgumentNullException("assemblyFileName", "Assembly file name is missing.");
            }

            if (string.IsNullOrWhiteSpace(manifestResourceName))
            {
                throw new ArgumentNullException("manifestResourceName", "Manifest Resource Name is missing.");
            }

            if (containingAssembly == null)
            {
                throw new ArgumentNullException("containingAssembly", "Containing assembly is missing.");
            }

            this.AssemblyFileName = assemblyFileName;
            this.ContainingAssembly = containingAssembly;
            this.ManifestResourceName = manifestResourceName;
            this.ZipFileEntry = zipFileEntry;
        }

        public Assembly ContainingAssembly { get; private set; }

        public string ManifestResourceName { get; private set; }

        public ZipStorer.ZipFileEntry ZipFileEntry { get; private set; }

        public override string ToString()
        {
            return "AssemblyFileName = " + this.AssemblyFileName + Environment.NewLine
                  + "ContainingAssembly = " + this.ContainingAssembly.FullName + Environment.NewLine
                  + "ManifestResourceName = " + this.ManifestResourceName + Environment.NewLine
                  + "FileCrc32 = " + this.ZipFileEntry.Crc32.ToString();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Honeywell Automation India Ltd.
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions