So I'm a fairly new developer, and was hoping someone might explain some things to me and help me understand how I can complete my task.
Okay so we have a "Web aplication" for one of our services that was written in C# quite some time ago. It has come to my employers attention, and he has requested me to update it to the newest framework/add or remove packages and make it build again (it doesn't build right now).
So the issue comes when I am adding packages. I have tried the old method of copying DLL files that are missing manually since the VPC does not allow for "NuGet" usage. I have tried to do this at home with NuGet and still failed.
Mostly I get errors of type:
Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken="CustomNumber"' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).
Note: CustomNumber represents the public key token I just didn't copy it.
One is for DocumentFormat.OpenXml the other is for Ajax.min control toolkit.
Can anyone give me any pointers or explanations on how to update old projects, or how to even solve them? Is there a specific way or method on how you solve problems like this or is it just basic googling untill you burn? (I have tried googling but I still got stuck)
Did you add a reference to WindowsBase
?
VS 2019 / VS 2017:
In VS menu,
Also see: How to include the reference of DocumentFormat.OpenXml.dll on Mono2.10?
If you're looking for the latest version, you'll want to look at:
Download .NET, .NET Core, and .NET Framework
Github: Open-XML-SDK
NuGet: DocumentFormat.OpenXml
Since you stated that you're a "fairly new developer", below is some information that may be useful to you.
ildasm
If you're interested in viewing which assemblies are used in a .NET DLL file or .NET .exe file, you can use ildasm.exe
from the Windows Kit.
Note: SDKs can be found in %ProgramFiles(x86)%\Microsoft SDKs\Windows\
(ex: C:\Program Files (x86)\Microsoft SDKs\Windows)
ildasm.exe
can be found in one or more of the following locations (given that the SDK was installed in the default location):
Win 10:
Win 8.1:
Win 7:
Run ildasm.exe
ildasm.exe
to run it (or open a cmd
window and type ildasm.exe
)You'll see something like the following:
When you see: .assembly extern <name>
(ex: .assembly extern System.Core
), this specifies an assembly that is required. Look at .ver
inside the curly brackets to see the version of the assembly being used. For a .NET assembly this, is the .NET version for that library (ex: 3:5:0:0), shows that .NET 3.5 is used.
If one looks at ".ver" for .assembly DocumentFormat.OpenXml
, the version shows as 2:0:5022:0
which is version 2.0.5022.0.
NuGet packages
Here's some information about NuGet packages, if you install one (at home). If one installs a NuGet package, it can be found in %UserProfile%\.nuget\packages
. For example, the latest NuGet package DocumentFormat.OpenXml
, can be found in C:\Users\<username>\.nuget\packages\open-xml-sdk\<version>\lib\<.NET version>
(ex: C:\Users\TestUser\.nuget\packages\open-xml-sdk\2.9.1\lib\net46). OpenXml version 2.0, can be found in NuGet package DocumentFormat.OpenXmlSDK
(C:\Users\<username>\.nuget\packages\documentformat.openxmlsdk\2.0.0\lib\Net35)
In Visual Studio, the following setting determines whether or not the .NuGet package is copied to your local project folder:
In VS menu:
Note: When Packages.config is specified, and a .NuGet package is installed in your project, it will be downloaded to %UserProfile%\.nuget\packages\<NuGet package name>
and then copied to your solution folder (or project folder) to a folder called "packages". If PackageReference is specified, the .NuGet package is installed in your project, and it will be downloaded to %UserProfile%\.nuget\packages\<NuGet package name>
where your project will reference it which ensures that all of your projects use the same version of the NuGet package (it won't be copied to your solution folder/project folder). Also some settings are different in the .csproj file.
The file you listed above may be from the NuGet package DocumentFormat.OpenXmlSDK
(v.2.0.0) which looks like it requires .NET 3.5. The newest/lastest NuGet package for OpenXml is DocumentFormat.OpenXml
(v.2.12.1) and DLL's exist for .NET 3.5, .NET 4.0, and .NET 4.6.
See Package references (PackageReference) in project files and Migrate from packages.config to PackageReference
Due to error, it is mostly caused by your pc environment and your PC cannot find DocumentFormat.OpenXml.dll version 2.0.5022.0
. So one solution is to add this dll into GAC so that your environment can find that.
Check this link.
User contributions licensed under CC BY-SA 3.0