0

在我的应用程序中,在为程序集提供强键名(包括使用 VS 2012 命令提示符的第三方 DLL)后,我收到程序集加载错误。

Could not load file or assembly ', Version=3.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)



FileLoadException: Could not load file or assembly 'ClubStarterKit.Core, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)] 

  System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType) +0 `System.Reflection.RuntimeMethodInfo.get_ReturnType() +42 `System.Web.HttpApplicationFactory.ReflectOnMethodInfoIfItLooksLikeEventHandler(MethodInfo m) +19` 
System.Web.HttpApplicationFactory.ReflectOnApplicationType() +374


System.Web.HttpApplicationFactory.CompileApplication() +143` System.Web.HttpApplicationFactory.EnsureInited() +80
   System.Web.HttpApplicationFactory.SetupFileChangeNotifications() +67
   System.Web.Compilation.BuildManager.CompileGlobalAsax() +57
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +269`

[HttpException (0x80004005): Could not load file or assembly 'ClubStarterKit.Core, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)]


 System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +62
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +427
System.Web.Compilation.BuildManager.CallAppInitializeMethod() +31
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +530

[HttpException (0x80004005): Could not load file or assembly 'ClubStarterKit.Core, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)]

 System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +456

我已经从所有解决方案中删除了所有 bin 和 obj 文件夹,并重建和批量构建,包括清理解决方案也更改了程序集版本,但仍然无法找到确切的错误。

4

1 回答 1

2

您上面列出的内容是一团糟。但是,我上周刚刚遇到这个错误,所以你很幸运。为了使强名称起作用,您需要

  1. 创建密钥
  2. 将密钥添加到程序集文件
  3. 在项目属性中添加签名

而已!有关如何操作的所有信息都在这里 http://www.codeproject.com/Articles/7859/Building-COM-Objects-in-C

为了公开 COM 对象,您的类库程序集还必须有一个强名称。要创建强名称,请使用实用程序 SN.EXE。

折叠 | 语言:c sn -k Database_COM_Key.snk 打开 AssemblyInfo.cs 并修改以下行:

折叠 | 语言:c [assembly: AssemblyKeyFile("Database_COM_Key.snk")] 构建对象。该构建还会生成一个类型库,该类型库可以导入到您的托管或非托管代码中。

您也可以在堆栈上参考我的问题。

于 2013-05-04T18:37:12.263 回答