BadImageFormat Exception at Microsoft.CSharp library - c#

I'm having little problem running my C# application after switching to Windows 8.1 from 8.
The problem is that I get this exception from title and there's not much help online. I tried to pinpoint the problem and it seems like my x64 application is trying to call x86 CSharp library. The reference in project leads to a DLL file, that upon calling x64 dumpbin program with /headers parameter outputs:
Dump of file Microsoft.CSharp.dll
PE signature found
File Type: DLL
FILE HEADER VALUES
14C machine (x86)
3 number of sections
4FFA5C64 time date stamp Mon Jul 09 06:21:56 2012
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
2022 characteristics
Executable
Application can handle large (>2GB) addresses
DLL
Notice the machine is x86, while the application is running in x64 (checked with Environment.Is64BitProcess). This might be the problem I'm facing, however I can't find way to solve it - there seems to be no x64 .Net libraries installed. The only ones I have found are at: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework. Or maybe I'm completely off and there's some other problem. Anyway the exception occurs at startup in one of constructors and full detail is:
Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
"Could not load file or assembly 'Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The module was expected to contain an assembly manifest."
Edit:
While still panicking, I solved this by downloading CSharp.dll and replacing the dummy 0-byte file in path shown in answer by it.

The module was expected to contain an assembly manifest
You've been looking at a reference assembly, it is not the one that's actually loaded when you run your program. Microsoft.CSharp.dll is stored in the GAC, put there by the .NET installer. You can see the file by navigating to c:\windows\microsoft.net\assembly\gac_msil\microsoft.csharp. Keep clicking until you get to the file.
The exception message is a very unhealthy one, it doesn't recognize the DLL as a .NET assembly. There are few decent explanations for that, other than the file being corrupted. File corruption is always bad news, a strong hint that your hard-disk is failing. You'll need to get it fixed, follow-up if necessary at superuser.com

Related

Could not load file or assembly 'WebDriver, Version=2.53.1.0 when using coded UI Testing

Since today I get the following new Error message:
System.IO.FileLoadException: Could not load file or assembly 'WebDriver, Version=2.53.1.0, Culture=neutral, PublicKeyToken=1c2bd1631853048f' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044) ---> System.IO.FileLoadException: A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
Everything worked fine until yesterday and now I lost 6 out of my 7 test VMs to this error.
I read every documentation I could find and tried to compare the non working VMs with the the non working version and could not find a difference.
Suspicious is the Version=2.53.1.0 as the current WebDriver DLL is 4.4.0. Where could the reference to this potential old DLL come from?
Is there a debug or logging option I could activate? A way to see which DLLs are loaded?
Needless to say that with only 1 out of 7 Testmachines we will not be able to meet the deadline.
Got it. It's the other way around. I must not use a new version. I must use an old 2.53 version.
The update must have slipped in because I can't remember updating them consciously.
For those who have similar problems: Extract the content of selenium-dotnet-strongnamed-2.53.1.zip into C:\Program Files (x86)\Common Files\microsoft shared\VSTT\Cross Browser Selenium Components\
Adjust destination directory if you have an unusual Windows installation.

Windows Phone XAP Obfuscation with ConfuserEx

We have came accross a requirement where we need to obfuscate windows phone application (.xap) file.
We are looking for an open source tool which can do basic obfuscation for an .xap file.
After little search we found ConfuserEx.This tool as of now support .dll and .exe obfuscation.
Can i obfuscate .xap file with this tool is my question.
Options i have tried so far is have extracted .xap file and put .dll files to obfuscate but it gives following error?
[ERROR] Failed to resolve dependency of 'MyApp.dll'.
Exception: dnlib.DotNet.AssemblyResolveException: Could not resolve assembly: Microsoft.Phone, Version=8.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e
at dnlib.DotNet.Extensions.ResolveThrow(IAssemblyResolver self, IAssembly assembly, ModuleDef sourceModule) in E:\Source\Public\Confuser2\dnlib\src\DotNet\IAssemblyResolver.cs:line 113
at Confuser.Core.ConfuserEngine.Inspection(ConfuserContext context) in e:\Source\Public\Confuser2\Confuser.Core\ConfuserEngine.cs:line 254
Failed at 3:09 PM, 0:00 elapsed.
Please let me know if my question is not clear.
I don't use Confuserex to obfuscate xap file like you, I use Crypto Obfuscator, and I meet the same bug, too.
Exception: dnlib.DotNet.AssemblyResolveException: Could not resolve assembly: Microsoft.Phone, Version=8.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e
So it take me 1h to work around and found that I need to make a reference to file Microsoft.Phone.dll (in Crypto Obfuscator)
Path: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.1\
Hope it works with your case.

Could not load file or assembly, PublicKeyToken=null

Could not load file or assembly 'NCrawler.GeckoProcessor,
Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies.
When I call CrawlUsingGeckoProcessor.Run();
What does this mean? I can click "go to definition" and I can see the Run() method.
This error usually means that the assembly was not found.
Try verifying that the file exists in the directory where your application is running.
If you still can't figure out which file fails loading, try using a tool such as Fusion Log Viewer (run fuslogvw.exe from the Visual Studio command prompt), to determine which files the CLR was trying to load and from where, so that you can see exactly what failed.
I experienced the same problem, and the reason was that I compiled my EXE and DLL on 32 bit machine for "x86", because it depends on C++\CLI library compiled for Win32. Then I tried to use this library on 64 bit machine from 64 bit process. Obviously 64 bit process can't load 32 bit libraries, so I got this error, which does not really help to understand the problem.
So the reason could be that you try to use 32 bit library from 64 bit process.
Building over nogard answer, try setting the Solution Platform to x86
try going to app advance settings .. Enable 32 bit processing ..
if the app was built in .net 2.0 and current server is IIS 7

Problem with error messages in solution

I have a solution with around 10 projects, I have not written any of this myself, but I'm going to take over a project here. The project that is the main project is based on WPF. When I try to run this project, I get the following compiler error:
The tag 'RoutingManagerView' does not exist in XML namespace 'clr-namespace:RoutingManager.Views;assembly=RoutingManager'. Line 29 Position 14. C:\Source\WSA\WsaClient\Views\MainView.xaml 29 14 WsaClient
Then, if I double click this error message, so that the xaml is opened, and the designer is loaded, the designer does not load, and I get 3 more error messages:
Unable to load the metadata for assembly 'WsaClient'. This assembly may have been downloaded from the web. See http://go.microsoft.com/fwlink/?LinkId=179545. The following error was encountered during load: Could not load file or assembly 'WsaClient' or one of its dependencies. The system cannot find the file specified. C:\Source\WSA\WsaClient\Views\MainView.xaml 1 1 WsaClient
Unable to load the metadata for assembly 'RoutingManager'. This assembly may have been downloaded from the web. See http://go.microsoft.com/fwlink/?LinkId=179545. The following error was encountered during load: Could not load file or assembly 'RoutingManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. C:\Steria\Forsvaret\P6088\Source\WSA\WsaClient\Views\MainView.xaml 1 1 WsaClient
The type 'Views:RoutingManagerView' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. C:\Source\WSA\WsaClient\Views\MainView.xaml 29 14 WsaClient
I googled it, and many have suggested that this is because a DLL is locked since it originates from the internet. However in my condition, I do not have a DLL. It's complaining on two projects that are a part of the solution, WsaManager and RoutingManager. I got all the source code on a zip file on an usb pen, and I have extracted it to somewhere on my c drive, so there is no remote access of the code.
If anyone have had the same or similar problem earlier, I would highly appreciate any pointers here on how to resolve this.
EDIT
The last error message is given on this line in the XAML file:
<Views:RoutingManagerView DataContext="{Binding Dependency}"/>
And on the top of the XAML file, this is the import for the assembly:
xmlns:Views="clr-namespace:RoutingManager.Views;assembly=RoutingManager"
Resolve this by right clicking on the solution and choosing 'Rebuild Solution'
An additional point for other readers: if your projects builds successfully, but you get this error message while trying to load your view in the designer, make sure your assembly is x86 or Any CPU, because Visual Studio 2010 is a 32bit process and cannot load x64 assemblies in the designer.
To resolve this problem, I had to compile the projects one by one, starting from the project with no dependencies on other projects, and then working my way "up".
It seems that the Build all did not manage to do this properly automatically.
Try this, this was the only advice that worked for me:
Unable to load the metadata for assembly ''. This assembly may have been downloaded from the web. See http://go.microsoft.com/fwlink/?LinkId=179545.  The following error was encountered during load: Could not load file or assembly '' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
In WPF project to allow the project to load from remote source we have to enable it in the configuration file devenv.exe.config.
Step 1: Search the configuration file devenv.exe.config in your system. Usually it is located at
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config
Step 2: Edit the configuration file. Add following line in the tag
<loadFromRemoteSources enabled="true" />
Step3: Restart your visual studio.
http://exacthelp.blogspot.cz/2012/02/unable-to-load-metadata-for-assembly.html
Unable to load the metadata for assembly 'WsaClient'. This assembly
may have been downloaded from the web. See
http://go.microsoft.com/fwlink/?LinkId=179545. The following error was
encountered during load: Could not load file or assembly 'WsaClient'
or one of its dependencies. The system cannot find the file specified.
C:\Source\WSA\WsaClient\Views\MainView.xaml 1 1 WsaClient
I run into same error: I can build and run my project, but I can not design XAML. I realized that it was local configuration issue because it's not replicable on my other machine (using same repository revision).
I started digging more and figured out that VS 2010 does not like # symbol in path. So error shows up when I have my sources in
C:\#projects\<my project>
After I moved them to
C:\projects\<my project>
Problem is gone.
I hope this will help to someone else.
I suspect the ..
The tag 'RoutingManagerView' does not exist in XML namespace 'clr-namespace:RoutingManager.Views;assembly=RoutingManager'. Line 29 Position 14. C:\Source\WSA\WsaClient\Views\MainView.xaml 29 14 WsaClient
.. error is causing a cascade of other errors. It looks like you're trying to create a RoutingManagerView from the namespace RoutingManager.Views in the assembly RoutingManager. However, it is not there. Make sure the class is visible to the outside world. Or try to clean and rebuild the solution and see on which project the first error occurs. Because if the projects are interdependent, an error in one project might cause reference errors in others.

System.IO.FileLoadException

I have got this error when using Enterprise Library 3.1 May 2007 version. We are developing a product and have a common lib directory beneath the Subversion Trunk directory
<>\Trunk\Lib\ into which we put all the third party DLLs. Inside this we have Microsoft\EnterpriseLibrary\v3.1 in which we have copied all the dlls from \Program Files\Microsoft Enterprise Library May2007\bin. Everything was working properly until one of the developers installed the source code on this machine. There were some dlls copied at the end of the source code installation and once that was done, he is not able to run the project anymore. He always gets this error
'Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
What is the problem here? I thought that when the source code was installed it was just supposed to build everything and copy in the bin directory within the source code parent directory. Also we have copied the Dlls from Microsoft Enterprise Library May 2007\bin directory into our product development directory and references into our project with a copylocal flag set to true.
Can anyone help me out here
RK
I used to get that when I developed against the signed version of the dll and deployed where only the unsigned version was available.
Also, fuslogvw.exe. EVERY. TIME.
I assume the error lies in the developer having compiled the code against the unsigned source code compilation he has.
Make sure he adds the reference to the signed DLLs before compiling his code.
Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null
should be something like:
Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=fa03fef243232
maybe you should check the Assembly- and FileVersion of the dll. if they do not match this exception can occur.
Read here to get started with assembly loading debugging.
In short you need to check the Fusion log for more information.
For a "The located assembly's manifest
definition with name [yourAssembly]
does not match the assembly reference"
message (for hresult
FUSION_E_REF_DEF_MISMATCH,
0x80131040): The Fusion log will say
which part of the assembly reference
failed to match what was found. It
will be the assembly name, culture,
public key (or token) or version (if
the found assembly was
strongly-named).

Categories