Skip to content

Commit 0c2c992

Browse files
committed
Fixed BuildErrors after updating to .net8
* removed the configure method. thats only syntactic sugar and aot is not happy with that method
1 parent 7f0a1d8 commit 0c2c992

File tree

8 files changed

+28
-41
lines changed

8 files changed

+28
-41
lines changed

samples/ImageSharp.Web.Sample/ImageSharp.Web.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<LangVersion>10</LangVersion>

src/ImageSharp.Web.Providers.AWS/Caching/AWSS3StorageCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Web.Caching.AWS;
1515
/// </summary>
1616
public class AWSS3StorageCache : IImageCache
1717
{
18-
private readonly IAmazonS3 amazonS3Client;
18+
private readonly AmazonS3Client amazonS3Client;
1919
private readonly string bucketName;
2020
private readonly string cacheFolder;
2121

src/ImageSharp.Web/Commands/Converters/ColorConverter.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ namespace SixLabors.ImageSharp.Web.Commands.Converters;
1111
/// <summary>
1212
/// Allows the conversion of strings into rgba32 pixel colors.
1313
/// </summary>
14-
public sealed class ColorConverter : ICommandConverter<Color>
14+
public sealed partial class ColorConverter : ICommandConverter<Color>
1515
{
1616
/// <summary>
1717
/// The web color hexadecimal regex. Matches strings arranged
1818
/// in rgb, rgba, rrggbb, or rrggbbaa format to match web syntax.
1919
/// </summary>
20-
private static readonly Regex HexColorRegex = new("([0-9a-fA-F][^,;.-]\\B{3}){1,2}", RegexOptions.Compiled);
20+
private static readonly Regex HexColorRegex = CreateHexColorRegex();
2121

2222
/// <summary>
2323
/// The number color regex.
2424
/// </summary>
25-
private static readonly Regex NumberRegex = new(@"\d+", RegexOptions.Compiled);
25+
private static readonly Regex NumberRegex = CreateNumberRegex();
2626

2727
/// <summary>
2828
/// The color constants table map.
@@ -85,9 +85,9 @@ public Color ConvertFrom(CommandParser parser, CultureInfo culture, string? valu
8585
return default;
8686
}
8787

88-
private static IDictionary<string, Color> InitializeColorConstantsTable()
88+
private static Dictionary<string, Color> InitializeColorConstantsTable()
8989
{
90-
IDictionary<string, Color> table = new Dictionary<string, Color>(StringComparer.OrdinalIgnoreCase);
90+
Dictionary<string, Color> table = new(StringComparer.OrdinalIgnoreCase);
9191

9292
foreach (FieldInfo field in typeof(Color).GetFields(BindingFlags.Public | BindingFlags.Static))
9393
{
@@ -99,4 +99,10 @@ private static IDictionary<string, Color> InitializeColorConstantsTable()
9999

100100
return table;
101101
}
102+
103+
[GeneratedRegex(@"\d+", RegexOptions.Compiled)]
104+
private static partial Regex CreateNumberRegex();
105+
106+
[GeneratedRegex("([0-9a-fA-F][^,;.-]\\B{3}){1,2}", RegexOptions.Compiled)]
107+
private static partial Regex CreateHexColorRegex();
102108
}

src/ImageSharp.Web/Commands/Converters/EnumConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class EnumConverter : ICommandConverter<object>
2929
{
3030
if (string.IsNullOrWhiteSpace(value))
3131
{
32-
return Activator.CreateInstance(propertyType);
32+
return Enum.ToObject(propertyType, 0);
3333
}
3434

3535
try
@@ -51,7 +51,7 @@ public sealed class EnumConverter : ICommandConverter<object>
5151
catch
5252
{
5353
// Just return the default value
54-
return Activator.CreateInstance(propertyType);
54+
return Enum.ToObject(propertyType, 0);
5555
}
5656
}
5757

src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Web.Commands;
1313
/// </summary>
1414
public class PresetOnlyQueryCollectionRequestParser : IRequestParser
1515
{
16-
private readonly IDictionary<string, CommandCollection> presets;
16+
private readonly Dictionary<string, CommandCollection> presets;
1717

1818
/// <summary>
1919
/// The command constant for the preset query parameter.
@@ -49,7 +49,7 @@ public CommandCollection ParseRequestCommands(HttpContext context)
4949
return new CommandCollection();
5050
}
5151

52-
private static IDictionary<string, CommandCollection> ParsePresets(
52+
private static Dictionary<string, CommandCollection> ParsePresets(
5353
IDictionary<string, string> unparsedPresets) =>
5454
unparsedPresets
5555
.Select(keyValue =>

src/ImageSharp.Web/DependencyInjection/ImageSharpBuilderExtensions.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using Microsoft.Extensions.Configuration;
56
using Microsoft.Extensions.DependencyInjection;
67
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -23,7 +24,7 @@ public static class ImageSharpBuilderExtensions
2324
/// <typeparam name="TParser">The type of class implementing <see cref="IRequestParser"/> to add.</typeparam>
2425
/// <param name="builder">The core builder.</param>
2526
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
26-
public static IImageSharpBuilder SetRequestParser<TParser>(this IImageSharpBuilder builder)
27+
public static IImageSharpBuilder SetRequestParser<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TParser>(this IImageSharpBuilder builder)
2728
where TParser : class, IRequestParser
2829
{
2930
builder.Services.Replace(ServiceDescriptor.Singleton<IRequestParser, TParser>());
@@ -50,7 +51,7 @@ public static IImageSharpBuilder SetRequestParser(this IImageSharpBuilder builde
5051
/// <typeparam name="TCache">The type of class implementing <see cref="IImageCache"/> to add.</typeparam>
5152
/// <param name="builder">The core builder.</param>
5253
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
53-
public static IImageSharpBuilder SetCache<TCache>(this IImageSharpBuilder builder)
54+
public static IImageSharpBuilder SetCache<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TCache>(this IImageSharpBuilder builder)
5455
where TCache : class, IImageCache
5556
{
5657
builder.Services.Replace(ServiceDescriptor.Singleton<IImageCache, TCache>());
@@ -77,7 +78,7 @@ public static IImageSharpBuilder SetCache(this IImageSharpBuilder builder, Func<
7778
/// <typeparam name="TCacheKey">The type of class implementing <see cref="ICacheKey"/> to add.</typeparam>
7879
/// <param name="builder">The core builder.</param>
7980
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
80-
public static IImageSharpBuilder SetCacheKey<TCacheKey>(this IImageSharpBuilder builder)
81+
public static IImageSharpBuilder SetCacheKey<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TCacheKey>(this IImageSharpBuilder builder)
8182
where TCacheKey : class, ICacheKey
8283
{
8384
builder.Services.Replace(ServiceDescriptor.Singleton<ICacheKey, TCacheKey>());
@@ -104,7 +105,7 @@ public static IImageSharpBuilder SetCacheKey(this IImageSharpBuilder builder, Fu
104105
/// <typeparam name="TCacheHash">The type of class implementing <see cref="ICacheHash"/> to add.</typeparam>
105106
/// <param name="builder">The core builder.</param>
106107
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
107-
public static IImageSharpBuilder SetCacheHash<TCacheHash>(this IImageSharpBuilder builder)
108+
public static IImageSharpBuilder SetCacheHash<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TCacheHash>(this IImageSharpBuilder builder)
108109
where TCacheHash : class, ICacheHash
109110
{
110111
builder.Services.Replace(ServiceDescriptor.Singleton<ICacheHash, TCacheHash>());
@@ -131,7 +132,7 @@ public static IImageSharpBuilder SetCacheHash(this IImageSharpBuilder builder, F
131132
/// <typeparam name="TProvider">The type of class implementing <see cref="IImageProvider"/> to add.</typeparam>
132133
/// <param name="builder">The core builder.</param>
133134
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
134-
public static IImageSharpBuilder AddProvider<TProvider>(this IImageSharpBuilder builder)
135+
public static IImageSharpBuilder AddProvider<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProvider>(this IImageSharpBuilder builder)
135136
where TProvider : class, IImageProvider
136137
{
137138
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IImageProvider, TProvider>());
@@ -161,7 +162,7 @@ public static IImageSharpBuilder AddProvider<TProvider>(this IImageSharpBuilder
161162
/// <param name="builder">The core builder.</param>
162163
/// <param name="index">The zero-based index at which the provider should be inserted.</param>
163164
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
164-
public static IImageSharpBuilder InsertProvider<TProvider>(this IImageSharpBuilder builder, int index)
165+
public static IImageSharpBuilder InsertProvider<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TProvider>(this IImageSharpBuilder builder, int index)
165166
where TProvider : class, IImageProvider
166167
{
167168
List<ServiceDescriptor> descriptors = builder.Services.Where(x => x.ServiceType == typeof(IImageProvider)).ToList();
@@ -231,7 +232,7 @@ public static IImageSharpBuilder ClearProviders(this IImageSharpBuilder builder)
231232
/// <typeparam name="T">The type of class implementing <see cref="IImageWebProcessor"/> to add.</typeparam>
232233
/// <param name="builder">The core builder.</param>
233234
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
234-
public static IImageSharpBuilder AddProcessor<T>(this IImageSharpBuilder builder)
235+
public static IImageSharpBuilder AddProcessor<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this IImageSharpBuilder builder)
235236
where T : class, IImageWebProcessor
236237
{
237238
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IImageWebProcessor, T>());
@@ -290,7 +291,7 @@ public static IImageSharpBuilder ClearProcessors(this IImageSharpBuilder builder
290291
/// <typeparam name="TConverter">The type of class implementing <see cref="ICommandConverter"/> to add.</typeparam>
291292
/// <param name="builder">The core builder.</param>
292293
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
293-
public static IImageSharpBuilder AddConverter<TConverter>(this IImageSharpBuilder builder)
294+
public static IImageSharpBuilder AddConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConverter>(this IImageSharpBuilder builder)
294295
where TConverter : class, ICommandConverter
295296
{
296297
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ICommandConverter, TConverter>());
@@ -343,21 +344,6 @@ public static IImageSharpBuilder ClearConverters(this IImageSharpBuilder builder
343344
return builder;
344345
}
345346

346-
/// <summary>
347-
/// Registers an action used to configure a particular type of options.
348-
/// </summary>
349-
/// <typeparam name="TOptions">The options type to be configured.</typeparam>
350-
/// <param name="builder">The core builder.</param>
351-
/// <param name="config">The configuration being bound.</param>
352-
/// <returns>The <see cref="IImageSharpBuilder"/>.</returns>
353-
public static IImageSharpBuilder Configure<TOptions>(this IImageSharpBuilder builder, IConfiguration config)
354-
where TOptions : class
355-
{
356-
builder.Services.Configure<TOptions>(config);
357-
358-
return builder;
359-
}
360-
361347
/// <summary>
362348
/// Registers an action used to configure a particular type of options.
363349
/// </summary>

src/ImageSharp.Web/RequestAuthorizationUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static void ToComponents(
207207
}
208208
}
209209

210-
private HttpContext ToHttpContext(HostString host, PathString path, QueryString queryString, QueryCollection query)
210+
private DefaultHttpContext ToHttpContext(HostString host, PathString path, QueryString queryString, QueryCollection query)
211211
{
212212
DefaultHttpContext context = new() { RequestServices = this.serviceProvider };
213213
HttpRequest request = context.Request;

src/ImageSharp.Web/Synchronization/RefCountedConcurrentDictionary.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,7 @@ public RefCountedValue(TValue value, int refCount)
222222
this.RefCount = refCount;
223223
}
224224

225-
public bool Equals(
226-
#if NET5_0_OR_GREATER
227-
RefCountedValue? other)
228-
#else
229-
[System.Diagnostics.CodeAnalysis.AllowNull] RefCountedValue other)
230-
#endif
225+
public bool Equals(RefCountedValue? other)
231226
=> (other != null) && (this.RefCount == other.RefCount) && EqualityComparer<TValue>.Default.Equals(this.Value, other.Value);
232227

233228
public override bool Equals(object? obj)

0 commit comments

Comments
 (0)