我们使用Tarma Installer来安装我们的项目,但它缺少GAC安装设施。
因此,我们创建了自己的实用程序,在安装程序中调用该实用程序,以便在需要时执行组件的Gac安装。
这对于标准程序集(不需要暴露给COM)非常有用
在我的代码中,我有以下代码块,即安装已签名的.Net 2程序集,并向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
导致以下异常
Exception loading the 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
我知道通过将app.config放入以下信息可以解决问题
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
我是否应该以正确的方式进行呼叫,以便我不会收到错误,而且我没有调用某些遗留设置?