How to install into the GAC (and expose to COM) when Installer doesn't support GacInstallation
We use Tarma Installer to install our Project, but it lacks GAC Installation facilities.
Therefore we have created our own utility that is called from within the Installer to perform the Gac Installation of our Components when needed.
This has all been working great for standard assemblies (that don't require being Exposed to COM)
In my code I have the following code block, that is installing a .Net 2 assembly that has been signed, and exposes a number of interfaces to COM.
Dim a As System.Reflection.Assembly
Try
a = System.Reflection.Assembly.LoadFrom(p)
If codebase Then
rs.RegisterAssembly(a, Runtime.InteropServices.AssemblyRegistrationFlags.SetCodeBase)
Else
rs.RegisterAssembly(a, Runtime.InteropServices.AssemblyRegistrationFlags.None)
End If
Catch ex As Exception
If mDebug Then
MessageBox.Show(String.Format("Exception loading the type{3}Filename={0} {3}Mode={1} {3}CodeBase={2} {3}{4}", p, _
mode, codebase, Environment.NewLine, ex.ToString), "Exception Loading Assembly")
End If
End Try
which results in the following exception
Exception loading t开发者_StackOverflow中文版he type
System.IO.FileLoadException: Mixed mode assembly is built against
version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime
without additional configuration information.
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at System.Runtime.InteropServices.RegistrationServices.GetRegistrableTypesInAssembly(Assembly assembly)
at System.Runtime.InteropServices.RegistrationServices.RegisterAssembly(Assembly assembly, AssemblyRegistrationFlags flags)
at IdealBusinessSoftware.Utilities.Entry.Register(String p, String mode, Boolean codebase) in C:\Development\Utilities\GacManager4\Entry.vb:line 372
I know that by placing an app.config in with the following information resolves the situation
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
Is there a correct way that I should be doing the call so that I don't get the error, and I'm not invoking some legacy setting?
精彩评论