C# – Could not load file or assembly ‘ Version=3.0.1.0, PublicKeyToken=null or one of its dependencies.A strongly-named assembly is required.

.net-assemblyasp.net-mvcc++visual-studio

In my application after giving the assemblies strong key names including the third parties DLLs with VS 2012 Command Prompt I get the assembly loading error.

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

I have removed all bin and obj folder from all the solution and rebuild and batch build including cleaned the solution also changed the assembly version and still not able to find the exact error.

Best Solution

What you listed above is a jumbled mess. HOWEVER, I just had this error last week so you are in luck. In order for the strong name to work you need to

  1. Create the key
  2. Add the key to the assembly file
  3. In projects properties add signature

Thats it! all of the info on how to do it is right here http://www.codeproject.com/Articles/7859/Building-COM-Objects-in-C

In order for the COM object to be exposed, your class library assembly must also have a strong name. To create a strong name, use the utility SN.EXE.

Collapse | Copy Code sn -k Database_COM_Key.snk Open the AssemblyInfo.cs and modify the line:

Collapse | Copy Code [assembly: AssemblyKeyFile("Database_COM_Key.snk")] Build the object. The build also results into a type library that can be imported into your managed or unmanaged code.

Also you can refer to my question here on stack.

and