.Net: Running code when assembly is loaded
The CLR supports module initializers. You’d have to hack C++/CLI code or ilasm.exe to use them. UPDATE: directly supported in C# as well since .NET 5 with the [ModuleInitializer] attribute
The CLR supports module initializers. You’d have to hack C++/CLI code or ilasm.exe to use them. UPDATE: directly supported in C# as well since .NET 5 with the [ModuleInitializer] attribute
I can only tell how the Mono Project does this. The theorem is quite simple, though it gives a code mess. They first compile System.Configuration.dll, without the part needing the reference to System.Xml.dll. After this, they compile System.Xml.dll the normal way. Now comes the magic. They recompile System.configuration.dll, with the part needing the reference to … Read more
Yes it is, more exactly in the .text section of the PE file (portable executable = *.exe or *.dll). More information can be found here. The best choice is to use ILSpy (Reflector is no longer free). It’s a free disassembler that can dissassemble your assembly into MSIL but also C#, VB (to some extent). … Read more
If both assemblies are compatible you can define in the app.exe.config or web.config file to always use the new version by declaring bindingRedirect . example <configuration> <runtime> <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″ appliesTo=”v1.0.3705″> <dependentAssembly> <assemblyIdentity name=”Regcode” publicKeyToken=”b03f5f7f11d50a3a” culture=””/> <bindingRedirect oldVersion=”0.0.0.0-65535.65535.65535.65535″ newVersion=”1.0.3300.0″/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> this config entry for dotnet 1.0 tells the asembly loader always to use … Read more
On a 32-bit machine: Any CPU: runs as a 32-bit process, can load Any CPU and x86 assemblies, will get BadImageFormatException if it tries to load an x64 assembly. x86: same as Any CPU. x64: BadImageFormatException always. On a 64-bit machine: Any CPU: runs as a 64-bit process, can load Any CPU and x64 assemblies, … Read more
The only way I can see this working is by creating a class that derives from ResourceManager and then overriding the InternalGetResourceSet and GetResourceFileName methods. From there, you should be able to override where resources are obtained, given a CultureInfo instance.
Question: When should I deploy my assemblies into the GAC? Answer: Never Actual, honest, Real Answer: Hardly Ever Discussion Only drop things into the GAC when multiple apps on the machine will use the assembly, and when the assembly is foundational (likely to be used by multiple apps), when it is signed, and when you … Read more
Getting loaded assemblies for the current AppDomain: var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); Getting the assemblies referenced by another assembly: var referencedAssemblies = someAssembly.GetReferencedAssemblies(); Note that if assembly A references assembly B and assembly A is loaded, that does not imply that assembly B is also loaded. Assembly B will only be loaded if and when it … Read more
To avoid this error you could either: Load the assembly dynamically, or Sign the third-party assembly. You will find instructions on signing third-party assemblies in .NET-fu: Signing an Unsigned Assembly (Without Delay Signing). Signing Third-Party Assemblies The basic principle to sign a thirp-party is to Disassemble the assembly using ildasm.exe and save the intermediate language … Read more
ILMerge does merge assemblies, which is nice, but sometimes not quite what you want. For example, when the assembly in question is a strongly-named assembly, and you don’t have the key for it, then you cannot do ILMerge without breaking that signature. Which means you have to deploy multiple assemblies. As an alternative to ilmerge, … Read more