Microsoft Technologies based on the .NET software framework. Miscellaneous topics that do not fit into specific categories.
The behavior difference between the two projects indicates that the existing project is resolving a different PdfWriter type or a different iText version/assembly than the new test MVC project, even though the same NuGet package version appears installed.
The two specific errors:
- “
PdfWriterdoes not contain a constructor that takes 1 arguments” - “Cannot convert
PdfWritertoiTextKernel.Pdf.DocumentProperties”
mean that, at compile time, the PdfWriter symbol in the existing project does not match the iText 9 API that your code expects. This typically happens due to:
- Conflicting references (another assembly defining
PdfWriter, or an older iText version) being picked up first. - Mismatched target frameworks or binding redirects causing a different iText assembly to load/compile against.
To fix this in the existing project:
- Check the resolved type for
PdfWriter
In the problematic project, use the IDE to inspect the symbol:- Hover over
PdfWriterand confirm the fully qualified name (namespace and assembly). It must match the iText 9 type you expect. - If it shows a different namespace/assembly than in the new MVC project, that’s the conflict.
- Hover over
- Remove conflicting references
- In the existing project, open the project file and remove any old or duplicate iText references (e.g., older iText 7/8, or other libraries that define
PdfWriter). - Clean and rebuild after removing them.
- In the existing project, open the project file and remove any old or duplicate iText references (e.g., older iText 7/8, or other libraries that define
- Force the correct namespace
- Temporarily replace
PdfWriterwith its fully qualified name from iText 9 (for example,iText.Kernel.Pdf.PdfWriterif that is the correct namespace in your package). - If the error changes or disappears, it confirms a name collision.
- Temporarily replace
- Compare project files
- Compare the
.csprojof the working new MVC project with the existing project:- Ensure the same
TargetFrameworkand the same iText package reference (same version, same Include). - Remove any extra package references related to older PDF libraries.
- Ensure the same
- Compare the
- Clean build artifacts
- Delete
binandobjfolders of the existing project. - Rebuild the solution to ensure no stale assemblies are being used.
- Delete
Once the existing project resolves the same PdfWriter type as the new MVC project, the constructor call new PdfWriter(stream) and the PdfDocument constructor overload will compile and run as expected.
References: