我现在做一个安装包,其中要注册组件服务。请问怎么写;
try
{
string applicationName = "MyApp";
string typeLibraryName = null;
RegistrationHelper helper = new RegistrationHelper();
// takes precedence over the application name you provide to InstallAssembly.
helper.InstallAssembly(@"C:\RCOM.dll", ref applicationName, ref typeLibraryName, InstallationFlags.CreateTargetApplication);
this.label1.Text = "Registration succeeded: Type library {0} created." + typeLibraryName;
RegistrationConfig registrationConfiguration = new RegistrationConfig();
registrationConfiguration.AssemblyFile = @"C:\RCOM.dll";
registrationConfiguration.Application = "MyApp";
registrationConfiguration.InstallationFlags = InstallationFlags.CreateTargetApplication;
RegistrationHelper helperFromConfig = new RegistrationHelper();
helperFromConfig.InstallAssemblyFromConfig(ref registrationConfiguration);
}
catch (RegistrationException e1)
{
this.textBox1.Text = e1.ToString();
}
上面是我写的,总是报错:System.EnterpriseServices.RegistrationException: 加载程序集“c:\RCOM.dll”失败。 ---> System.BadImageFormatException: 未能加载文件或程序集“file:///c:\RCOM.dll”或它的某一个依赖项。该模块应包含一个程序集清单。
文件名:“file:///c:\RCOM.dll”
在 System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
在 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
在 System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
在 System.Reflection.Assembly.LoadFrom(String assemblyFile)
在 System.EnterpriseServices.RegistrationDriver.LoadAssembly(String assembly)
=== 预绑定状态信息 ===
日志: 用户 = aaas-21NY48PS\scdf
日志: Where-ref 绑定。位置 = c:\RCOM.dll
日志: Appbase = file:///C:/RCOM/RCOM/bin/Debug/
日志: 初始 PrivatePath = NULL
调用程序集: (Unknown)。
===
日志: 此绑定从 LoadFrom 加载上下文开始。
警告: 将不在 LoadFrom 上下文中探测本机映像。仅在默认加载上下文中探测本机映像,例如,使用 Assembly.Load()。
日志: 未找到应用程序配置文件。
日志: 使用 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config 的计算机配置文件。
日志: 试图下载新的 URL file:///c:/rcom
另上面的C:\RCOM.dll怎么写成相对路经;
try
{
string applicationName = "MyApp";
string typeLibraryName = null;
RegistrationHelper helper = new RegistrationHelper();
// takes precedence over the application name you provide to InstallAssembly.
helper.InstallAssembly(@"C:\RCOM.dll", ref applicationName, ref typeLibraryName, InstallationFlags.CreateTargetApplication);
this.label1.Text = "Registration succeeded: Type library {0} created." + typeLibraryName;
RegistrationConfig registrationConfiguration = new RegistrationConfig();
registrationConfiguration.AssemblyFile = @"C:\RCOM.dll";
registrationConfiguration.Application = "MyApp";
registrationConfiguration.InstallationFlags = InstallationFlags.CreateTargetApplication;
RegistrationHelper helperFromConfig = new RegistrationHelper();
helperFromConfig.InstallAssemblyFromConfig(ref registrationConfiguration);
}
catch (RegistrationException e1)
{
this.textBox1.Text = e1.ToString();
}
上面是我写的,总是报错:System.EnterpriseServices.RegistrationException: 加载程序集“c:\RCOM.dll”失败。 ---> System.BadImageFormatException: 未能加载文件或程序集“file:///c:\RCOM.dll”或它的某一个依赖项。该模块应包含一个程序集清单。
文件名:“file:///c:\RCOM.dll”
在 System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
在 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
在 System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
在 System.Reflection.Assembly.LoadFrom(String assemblyFile)
在 System.EnterpriseServices.RegistrationDriver.LoadAssembly(String assembly)
=== 预绑定状态信息 ===
日志: 用户 = aaas-21NY48PS\scdf
日志: Where-ref 绑定。位置 = c:\RCOM.dll
日志: Appbase = file:///C:/RCOM/RCOM/bin/Debug/
日志: 初始 PrivatePath = NULL
调用程序集: (Unknown)。
===
日志: 此绑定从 LoadFrom 加载上下文开始。
警告: 将不在 LoadFrom 上下文中探测本机映像。仅在默认加载上下文中探测本机映像,例如,使用 Assembly.Load()。
日志: 未找到应用程序配置文件。
日志: 使用 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config 的计算机配置文件。
日志: 试图下载新的 URL file:///c:/rcom
另上面的C:\RCOM.dll怎么写成相对路经;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货