I have a project in c# that uses c++ library and some dlls. When I run it it works great.
The library is Awesomium, contains both c++ library and c# wrappers
When I create reference to this project from my ASP.NET MVC 4 project I get the following error:
Exception Details: System.BadImageFormatException: Could not load file or assembly ‘file:///D:ProjectsDevelopmentProGamersGamingSitebinavcodec-52.dll’ or one of its dependencies. The module was expected to contain an assembly manifest.
Things I’ve tried:
-
Coping the dlls, but it still doesn’t work (The file exists).
-
Registering it in the GAC but I’ve got the same error there.
-
Make sure using .NET Framework 4.0 (and not client profile)
-
2 files with the same dll/exe name causing conflict — I dont have it.
-
Change the platform of the solution to AnyCPU/Mixed Platforms.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'file:///D:ProjectsDevelopmentProGamersGamingSitebinavcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +102
System.Reflection.Assembly.LoadFrom(String assemblyFile) +34
WebActivator.ActivationManager.Run() +190
[InvalidOperationException: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'file:///D:ProjectsDevelopmentProGamersGamingSitebinavcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
System.Web.Compilation.BuildManager.ExecutePreAppStart() +135
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'file:///D:ProjectsDevelopmentProGamersGamingSitebinavcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9850940
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +456
- Remove From My Forums
-
Question
-
Hi, I can get started debugging my application.
When I hit «Run» I’ll get error message «Error while trying to run project: Could not load file or assembly ‘CANopenConf’ or one of it dependecies. The module was expected to contain an assembly manifest
But when I look in my debug folder, all needed dll’s are there, and if I start the application by double clicking in Explorer, all works fine.
what is wrong?
thanks in advance, Patrik
Answers
-
Can you tell us some more details on your application type? Does your solution contain C++ or C# or VB projects? Are you sure that you have set the correct project to be the startup project?
John
I have a project in c# that uses c++ library and some dlls. When I run it it works great.
The library is Awesomium, contains both c++ library and c# wrappers
When I create reference to this project from my ASP.NET MVC 4 project I get the following error:
Exception Details: System.BadImageFormatException: Could not load file or assembly ‘file:///D:ProjectsDevelopmentProGamersGamingSitebinavcodec-52.dll’ or one of its dependencies. The module was expected to contain an assembly manifest.
Things I’ve tried:
-
Coping the dlls, but it still doesn’t work (The file exists).
-
Registering it in the GAC but I’ve got the same error there.
-
Make sure using .NET Framework 4.0 (and not client profile)
-
2 files with the same dll/exe name causing conflict — I dont have it.
-
Change the platform of the solution to AnyCPU/Mixed Platforms.
Stack Trace:
[BadImageFormatException: Could not load file or assembly 'file:///D:ProjectsDevelopmentProGamersGamingSitebinavcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest.] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152 System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +102 System.Reflection.Assembly.LoadFrom(String assemblyFile) +34 WebActivator.ActivationManager.Run() +190 [InvalidOperationException: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'file:///D:ProjectsDevelopmentProGamersGamingSitebinavcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest..] System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +550 System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90 System.Web.Compilation.BuildManager.ExecutePreAppStart() +135 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516 [HttpException (0x80004005): The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Could not load file or assembly 'file:///D:ProjectsDevelopmentProGamersGamingSitebinavcodec-52.dll' or one of its dependencies. The module was expected to contain an assembly manifest..] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9850940 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +456
What is assembly manifest file?
An assembly manifest contains all the metadata needed to specify the assembly’s version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes. The assembly manifest can be stored in either a PE file (an .exe or .
Can not load file or assembly?
In summary if you get the «Could not load file or assembly error», this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.
I found that, I am using a different InstallUtil from my target .NET Framework. I am building a .NET Framework 4.5, meanwhile the error occured if I am using the .NET Framework 2.0 release. Having use the right InstallUtil for my target .NET Framework, solved this problem!
BadImageFormatException
, in my experience, is almost always to do with x86 versus x64 compiled assemblies. It sounds like your C++ assembly is compiled for x86 and you are running on an x64 process. Is that correct?
Instead of using AnyCPU/Mixed
as the platform. Try to manually set it to x86
and see if it will run after that.
Only Visible to You and DevExpress Support
Visible to All Users
Modify
support ticket and change its visibility
Urgent
Duplicate
We have closed this ticket because another page addresses its subject:
Answers approved by DevExpress Support
Disclaimer: The information provided on DevExpress.com and its affiliated web properties is provided «as is» without warranty of any kind.
Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose.
Please refer to the DevExpress.com Website Terms of Use for more information.
Recently viewed tickets
You have yet to view any tickets.
Your search criteria do not match any tickets.
A server error occurred while processing your request. Please try again at a later time.
To install service need to follow below steps
open cmd
as admin and switch to output/publish dir of project. Then type
sc create TestService BinPath=D:LCWindowService/TestService.exe
You will get message [SC] CreateService SUCCESS
. Other commands also available including start
service
sc start TestService
sc stop TestService
sc delete TestService
Note: In .Net Core services avoid using InstallUtil.exe
.