Compiler error in new version (2.0.0) for C# code in old version (1.8.1)
Closed this issue · 2 comments
Hello:
I found VectSharp now has a new version: 2.0.0. So, I tried to upgrade my C# code to use the new version.
My C# used old version 1.8.1, it works well. I am using Visual Studio 2022 for targeting .NET 6.0.
The following code works in Version 1.8.1:
Font titleFont = new(new FontFamily(FontFamily.StandardFontFamilies.HelveticaBold), 16);
Font regularFont = new(new FontFamily(FontFamily.StandardFontFamilies.Helvetica), 14);
But after I upgraded VectSharp Nuget package to 2.0.0, I got compiler errors:
Error CS0619 'FontFamily.FontFamily(FontFamily.StandardFontFamilies)' is obsolete: 'Please use the FontFamily.DefaultFontLibrary.ResolveFontFamily(StandardFontFamilies) method instead!'
I tried the following code:
Font titleFont = new(new FontFamily(ResolveFontFamily.HelveticaBold), 16);
But I got another compiler error:
Error CS0119 'FontFamily.ResolveFontFamily(string)' is a method, which is not valid in the given context
The repo is rather complicated, please help me on how to write the C# code using the latest version 2.0.0.
Thanks,
Hi! That error message just means that the new way to create a FontFamily
object is by using the FontFamily.ResolveFontFamily
static method, instead of the new FontFamily
constructor.
Old code:
- Font titleFont = new Font(new FontFamily(FontFamily.StandardFontFamilies.HelveticaBold), 16);
New code:
Font titleFont = new Font(FontFamily.ResolveFontFamily(FontFamily.StandardFontFamilies.HelveticaBold), 16);
A project-wide search and replace, replacing new FontFamily
with FontFamily.ResolveFontFamily
should be enough to make your code compatible with the new version of VectSharp.
Thanks,