Updating an old C#

-1

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)

c#
visual-studio
nuget
asked on Stack Overflow Feb 3, 2021 by Mastawayne • edited Feb 3, 2021 by SSD

2 Answers

1

Did you add a reference to WindowsBase?

VS 2019 / VS 2017:

In VS menu,

  • Click Project
  • Select Add Reference...
  • Click Assemblies
  • Check WindowsBase
  • Click OK

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:

What's new in .NET 5

What is .NET Framework

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:

  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools
  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64
  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools
  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\x64
  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools
  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\x64 ...

Win 8.1:

  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64

Win 7:

  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools
  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\x64
  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin\
  • `%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin\x64

Run ildasm.exe

  • Double-click ildasm.exe to run it (or open a cmd window and type ildasm.exe)
  • Click File
  • Select Open
  • Choose your DLL file or .exe file (ex: TestDLL35.dll)
  • Double-click MANIFEST to open it in a new window

You'll see something like the following:

enter image description here ... enter image description here

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.

enter image description here

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:

  • Click Tools
  • Select Options
  • Expand NuGet Package Manager
  • Click General
  • Under Package Management, look at the value for Default package management format.

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

answered on Stack Overflow Feb 3, 2021 by user9938 • edited Feb 3, 2021 by user9938
0

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.

answered on Stack Overflow Feb 4, 2021 by Perry Qian-MSFT • edited Feb 5, 2021 by Perry Qian-MSFT

User contributions licensed under CC BY-SA 3.0