How can I get the assembly file version

See my comment above asking for clarification on what you really want. Hopefully this is it: System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion;

Is there a way to force all referenced assemblies to be loaded into the app domain?

This seemed to do the trick: var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray(); var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, “*.dll”); var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList(); toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path)))); As Jon noted, the ideal solution would need to recurse into the dependencies for each of the loaded assemblies, but in my specific scenario … Read more

Why should you remove unnecessary C# using directives?

There are few reasons for removing unused using(s)/namespaces, besides coding preference: removing the unused using clauses in a project, can make the compilation faster because the compiler has fewer namespaces to look-up types to resolve. (this is especially true for C# 3.0 because of extension methods, where the compiler must search all namespaces for extension … Read more

Using different versions of the same assembly in the same folder

I used the following configuration to resolve the issue. <configuration> <runtime> <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″> <dependentAssembly> <assemblyIdentity name=”Castle.DynamicProxy2″ publicKeyToken=”407dd0808d44fbdc” /> <codeBase version=”2.1.0.0″ href=”https://stackoverflow.com/questions/2460542/v2.1\Castle.DynamicProxy2.dll” /> <codeBase version=”2.2.0.0″ href=”v2.2\Castle.DynamicProxy2.dll” /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name=”Castle.Core” publicKeyToken=”407dd0808d44fbdc” /> <codeBase version=”1.1.0.0″ href=”v2.1\Castle.Core.dll” /> <codeBase version=”1.2.0.0″ href=”v2.2\Castle.Core.dll” /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>

Difference between LoadFile and LoadFrom with .NET Assemblies?

Does this clear it up? // path1 and path2 point to different copies of the same assembly on disk: Assembly assembly1 = Assembly.LoadFrom(path1); Assembly assembly2 = Assembly.LoadFrom(path2); // These both point to the assembly from path1, so this is true Console.WriteLine(assembly1.CodeBase == assembly2.CodeBase); assembly1 = Assembly.LoadFile(path1); assembly2 = Assembly.LoadFile(path2); // These point to different assemblies … Read more

How to Load an Assembly to AppDomain with all references recursively?

You need to invoke CreateInstanceAndUnwrap before your proxy object will execute in the foreign application domain. class Program { static void Main(string[] args) { AppDomainSetup domaininfo = new AppDomainSetup(); domaininfo.ApplicationBase = System.Environment.CurrentDirectory; Evidence adevidence = AppDomain.CurrentDomain.Evidence; AppDomain domain = AppDomain.CreateDomain(“MyDomain”, adevidence, domaininfo); Type type = typeof(Proxy); var value = (Proxy)domain.CreateInstanceAndUnwrap( type.Assembly.FullName, type.FullName); var assembly = … Read more

Can I load a .NET assembly at runtime and instantiate a type knowing only the name?

Yes. You need to use Assembly.LoadFrom to load the assembly into memory, then you can use Activator.CreateInstance to create an instance of your preferred type. You’ll need to look the type up first using reflection. Here is a simple example: Assembly assembly = Assembly.LoadFrom(“MyNice.dll”); Type type = assembly.GetType(“MyType”); object instanceOfMyType = Activator.CreateInstance(type); Update When you … Read more

What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?

AssemblyVersion Where other assemblies that reference your assembly will look. If this number changes, other assemblies must update their references to your assembly! Only update this version if it breaks backward compatibility. The AssemblyVersion is required. I use the format: major.minor (and major for very stable codebases). This would result in: [assembly: AssemblyVersion(“1.3”)] If you’re … Read more