无法加载文件或程序集 ' 版本=3.0.1.0、公钥令牌=null 或其依赖项之一。需要强名称程序集。



在我的应用程序中,在给出程序集强密钥名称后,包括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文件夹,并重新构建和批量构建,包括清理解决方案,还更改了程序集版本,但仍然无法找到确切的错误。

你上面列出的是一团乱麻。然而,我上周刚刚犯了这个错误,所以你很幸运。为了使强名称工作,您需要

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

这是它!关于如何做到这一点的所有信息都在这里http://www.codeproject.com/Articles/7859/Building-COM-Objects-in-C

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

崩溃|复制代码sn -k Database_COM_Key。蛇打开AssemblyInfo.cs并修改行

崩溃|复制代码[汇编:AssemblyKeyFile("Database_COM_Key.snk")]构建对象。构建还生成一个类型库,该类型库可以导入到您的托管或非托管代码。

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

  • 如何从非托管c++调用托管c++方法

    在非托管c++程序中实现c# DLL COM文件

最新更新