当安装程序不支持 GacInstallation 时如何安装到 GAC(并向 COM 公开)
我们使用 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>
是否有正确的方法可以让我进行调用,这样我就不会收到错误,而且我没有调用一些遗留设置?
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 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
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论