Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DLL is not valid PE-COFF file when opening a StaticLibrary #279

Open
siddhsql opened this issue Sep 30, 2024 · 3 comments
Open

DLL is not valid PE-COFF file when opening a StaticLibrary #279

siddhsql opened this issue Sep 30, 2024 · 3 comments

Comments

@siddhsql
Copy link

I build a DLL using msbuild and StaticLibrary configuration type. However when I try to open it in dependencies I get this error:


Invalid PE

xxx.dll is not a valid PE-COFF file

OK

How can I fix this? The old depends.exe also gives an error.

@sauzanniraula
Copy link

The error you're encountering suggests that you're trying to open a file that was built as a Static Library (typically with the .lib extension) instead of a Dynamic Link Library (DLL, with the .dll extension), and tools like depends.exe or Dependency Walker are expecting a valid Portable Executable (PE) file in the form of a DLL or EXE.

@sauzanniraula
Copy link

Reason for the Error:
A Static Library is not a PE file, and it doesn't contain the necessary headers and structures that PE-COFF (Portable Executable - Common Object File Format) files like DLLs or EXEs have.
When using the StaticLibrary configuration in MSBuild, you're generating a .lib file (static library), not a .dll. This is why Dependency Walker and similar tools are unable to open it, as they expect PE-COFF files.

@sauzanniraula
Copy link

Change the Project Configuration:

Ensure that you're building the project as a Dynamic Link Library (DLL) and not as a Static Library. To do this:
Open your project in Visual Studio.
Right-click on the project in Solution Explorer and select Properties.
Under the Configuration Properties > General, look for the Configuration Type setting.
Change the Configuration Type from Static Library (.lib) to Dynamic Library (.dll).
Rebuild the project.
Check Output Files:

After rebuilding the project, ensure that the output is a .dll file. You should now be able to open the .dll file in Dependency Walker without the PE-COFF error.
Verify MSBuild Configuration:

If you're using MSBuild directly (without Visual Studio), ensure your .csproj or .vcxproj is set to create a DLL. You can verify this in the project file: DynamicLibrary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants