diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index c5cbb5f24..7501b9560 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -1,7 +1,7 @@  - net472;net6.0;net7.0 + net472;net6.0;net7.0;net8.0 diff --git a/LibGit2Sharp/AmbiguousSpecificationException.cs b/LibGit2Sharp/AmbiguousSpecificationException.cs index 16c77f6df..7ab5f77f6 100644 --- a/LibGit2Sharp/AmbiguousSpecificationException.cs +++ b/LibGit2Sharp/AmbiguousSpecificationException.cs @@ -1,13 +1,14 @@ using LibGit2Sharp.Core; using System; -using System.Runtime.Serialization; namespace LibGit2Sharp { /// /// The exception that is thrown when the provided specification cannot uniquely identify a reference, an object or a path. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class AmbiguousSpecificationException : NativeException { /// @@ -43,6 +44,7 @@ public AmbiguousSpecificationException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -51,6 +53,7 @@ public AmbiguousSpecificationException(string message, Exception innerException) protected AmbiguousSpecificationException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal override GitErrorCode ErrorCode { diff --git a/LibGit2Sharp/BareRepositoryException.cs b/LibGit2Sharp/BareRepositoryException.cs index 7ee830a0c..1f817f478 100644 --- a/LibGit2Sharp/BareRepositoryException.cs +++ b/LibGit2Sharp/BareRepositoryException.cs @@ -1,6 +1,5 @@ -using System; -using System.Runtime.Serialization; using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { @@ -8,7 +7,9 @@ namespace LibGit2Sharp /// The exception that is thrown when an operation which requires a /// working directory is performed against a bare repository. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class BareRepositoryException : NativeException { /// @@ -43,6 +44,7 @@ public BareRepositoryException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -51,6 +53,7 @@ public BareRepositoryException(string message, Exception innerException) protected BareRepositoryException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal BareRepositoryException(string message, GitErrorCategory category) : base(message, category) diff --git a/LibGit2Sharp/CheckoutConflictException.cs b/LibGit2Sharp/CheckoutConflictException.cs index f2f5092e9..3e75e7d9f 100644 --- a/LibGit2Sharp/CheckoutConflictException.cs +++ b/LibGit2Sharp/CheckoutConflictException.cs @@ -1,6 +1,5 @@ -using System; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { @@ -9,7 +8,9 @@ namespace LibGit2Sharp /// because of a conflicting change staged in the index, or unstaged /// in the working directory. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class CheckoutConflictException : NativeException { /// @@ -44,6 +45,7 @@ public CheckoutConflictException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -52,6 +54,7 @@ public CheckoutConflictException(string message, Exception innerException) protected CheckoutConflictException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal CheckoutConflictException(string message, GitErrorCategory category) : base(message, category) diff --git a/LibGit2Sharp/Core/GitObjectLazyGroup.cs b/LibGit2Sharp/Core/GitObjectLazyGroup.cs index 11c83a81e..3bf2c24ca 100644 --- a/LibGit2Sharp/Core/GitObjectLazyGroup.cs +++ b/LibGit2Sharp/Core/GitObjectLazyGroup.cs @@ -1,5 +1,6 @@ -using System; using LibGit2Sharp.Core.Handles; +using System; +using System.Diagnostics.CodeAnalysis; namespace LibGit2Sharp.Core { @@ -21,7 +22,7 @@ protected override void EvaluateInternal(Action evaluator) } } - public static ILazy Singleton(Repository repo, ObjectId id, Func resultSelector, bool throwIfMissing = false) + public static ILazy Singleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TResult>(Repository repo, ObjectId id, Func resultSelector, bool throwIfMissing = false) { return Singleton(() => { diff --git a/LibGit2Sharp/Core/LazyGroup.cs b/LibGit2Sharp/Core/LazyGroup.cs index d8b13fa42..4c1ee34e9 100644 --- a/LibGit2Sharp/Core/LazyGroup.cs +++ b/LibGit2Sharp/Core/LazyGroup.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace LibGit2Sharp.Core { - internal abstract class LazyGroup + internal abstract class LazyGroup<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] T> { private readonly IList> evaluators = new List>(); private readonly object @lock = new object(); @@ -44,7 +45,7 @@ public void Evaluate() protected abstract void EvaluateInternal(Action evaluator); - protected static ILazy Singleton(Func resultSelector) + protected static ILazy Singleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TResult>(Func resultSelector) { return new LazyWrapper(resultSelector); } @@ -54,7 +55,7 @@ private interface IEvaluator void Evaluate(TInput input); } - private class Dependent : ILazy, IEvaluator + private class Dependent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TInput, TOutput> : ILazy, IEvaluator { private readonly Func valueFactory; private readonly LazyGroup lazyGroup; @@ -90,7 +91,7 @@ void IEvaluator.Evaluate(TInput input) } } - protected class LazyWrapper : Lazy, ILazy + protected class LazyWrapper<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TType> : Lazy, ILazy { public LazyWrapper(Func evaluator) : base(evaluator) diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index e20d755ba..6440bb7aa 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -1,10 +1,11 @@ +using LibGit2Sharp.Core.Handles; using System; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; -using LibGit2Sharp.Core.Handles; // Restrict the set of directories where the native library is loaded from to safe directories. [assembly: DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.ApplicationDirectory | DllImportSearchPath.SafeDirectories)] @@ -76,6 +77,7 @@ private static bool TryUseNativeLibrary() return true; } + [UnconditionalSuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single file", Justification = "The AOT case is handled at runtime")] private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) { IntPtr handle = IntPtr.Zero; @@ -102,7 +104,12 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor { // The libraries are located at 'runtimes//native/lib{libraryName}.so' // The ends with the processor architecture. e.g. fedora-x64. - string assemblyDirectory = Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location); + var directoryName = typeof(NativeMethods).Assembly.Location; + if (String.IsNullOrEmpty(directoryName)) // If AOT compiled, this will be true + { + directoryName = System.AppContext.BaseDirectory; + } + string assemblyDirectory = Path.GetDirectoryName(directoryName); string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); string runtimesDirectory = Path.Combine(assemblyDirectory, "runtimes"); diff --git a/LibGit2Sharp/EmptyCommitException.cs b/LibGit2Sharp/EmptyCommitException.cs index 8cd48e49f..ce24341ad 100644 --- a/LibGit2Sharp/EmptyCommitException.cs +++ b/LibGit2Sharp/EmptyCommitException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace LibGit2Sharp { @@ -7,7 +6,9 @@ namespace LibGit2Sharp /// The exception that is thrown when a commit would create an "empty" /// commit that is treesame to its parent without an explicit override. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class EmptyCommitException : LibGit2SharpException { /// @@ -42,6 +43,7 @@ public EmptyCommitException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -50,5 +52,6 @@ public EmptyCommitException(string message, Exception innerException) protected EmptyCommitException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } diff --git a/LibGit2Sharp/EntryExistsException.cs b/LibGit2Sharp/EntryExistsException.cs index 2c46e4acd..10ea60977 100644 --- a/LibGit2Sharp/EntryExistsException.cs +++ b/LibGit2Sharp/EntryExistsException.cs @@ -1,13 +1,14 @@ -using System; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { /// /// The exception that is thrown attempting to create a resource that already exists. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class EntryExistsException : LibGit2SharpException { /// @@ -42,6 +43,7 @@ public EntryExistsException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -50,6 +52,7 @@ public EntryExistsException(string message, Exception innerException) protected EntryExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal EntryExistsException(string message, GitErrorCode code, GitErrorCategory category) : base(message, code, category) diff --git a/LibGit2Sharp/InvalidSpecificationException.cs b/LibGit2Sharp/InvalidSpecificationException.cs index 3d34571a4..dcaf70e07 100644 --- a/LibGit2Sharp/InvalidSpecificationException.cs +++ b/LibGit2Sharp/InvalidSpecificationException.cs @@ -1,6 +1,5 @@ -using System; -using System.Runtime.Serialization; using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { @@ -10,7 +9,9 @@ namespace LibGit2Sharp /// if the spec refers to an object of an incorrect type (e.g. asking to /// create a branch from a blob, or peeling a blob to a commit). /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class InvalidSpecificationException : NativeException { /// @@ -45,6 +46,7 @@ public InvalidSpecificationException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -53,6 +55,7 @@ public InvalidSpecificationException(string message, Exception innerException) protected InvalidSpecificationException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal InvalidSpecificationException(string message, GitErrorCategory category) : base(message, category) diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 4d0876c4d..045efa768 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -1,7 +1,7 @@  - net472;net6.0 + net472;net6.0;net8.0 10.0 true LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET @@ -23,6 +23,11 @@ libgit2-$(libgit2_hash.Substring(0,7)) + + + true + + diff --git a/LibGit2Sharp/LibGit2SharpException.cs b/LibGit2Sharp/LibGit2SharpException.cs index 5d1c33f25..913b65816 100644 --- a/LibGit2Sharp/LibGit2SharpException.cs +++ b/LibGit2Sharp/LibGit2SharpException.cs @@ -1,14 +1,14 @@ using System; using System.Globalization; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; namespace LibGit2Sharp { /// /// The exception that is thrown when an error occurs during application execution. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class LibGit2SharpException : Exception { /// @@ -44,6 +44,7 @@ public LibGit2SharpException(string format, params object[] args) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -52,5 +53,6 @@ public LibGit2SharpException(string format, params object[] args) protected LibGit2SharpException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } diff --git a/LibGit2Sharp/LockedFileException.cs b/LibGit2Sharp/LockedFileException.cs index 44fd65b02..56a368c78 100644 --- a/LibGit2Sharp/LockedFileException.cs +++ b/LibGit2Sharp/LockedFileException.cs @@ -1,13 +1,14 @@ -using System; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { /// /// The exception that is thrown attempting to open a locked file. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class LockedFileException : NativeException { /// @@ -42,6 +43,7 @@ public LockedFileException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -50,6 +52,7 @@ public LockedFileException(string message, Exception innerException) protected LockedFileException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal LockedFileException(string message, GitErrorCategory category) : base(message, category) diff --git a/LibGit2Sharp/MergeFetchHeadNotFoundException.cs b/LibGit2Sharp/MergeFetchHeadNotFoundException.cs index a86bf5caf..0a74b2afa 100644 --- a/LibGit2Sharp/MergeFetchHeadNotFoundException.cs +++ b/LibGit2Sharp/MergeFetchHeadNotFoundException.cs @@ -1,12 +1,13 @@ using System; -using System.Runtime.Serialization; namespace LibGit2Sharp { /// /// The exception that is thrown when the ref to merge with was as part of a pull operation not fetched. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class MergeFetchHeadNotFoundException : NotFoundException { /// @@ -41,6 +42,7 @@ public MergeFetchHeadNotFoundException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -49,5 +51,6 @@ public MergeFetchHeadNotFoundException(string message, Exception innerException) protected MergeFetchHeadNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } diff --git a/LibGit2Sharp/NameConflictException.cs b/LibGit2Sharp/NameConflictException.cs index 0dcffc648..8b971a2ae 100644 --- a/LibGit2Sharp/NameConflictException.cs +++ b/LibGit2Sharp/NameConflictException.cs @@ -1,13 +1,14 @@ -using System; -using System.Runtime.Serialization; using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { /// /// The exception that is thrown when a reference, a remote, a submodule... with the same name already exists in the repository /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class NameConflictException : NativeException { /// @@ -42,6 +43,7 @@ public NameConflictException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -50,6 +52,7 @@ public NameConflictException(string message, Exception innerException) protected NameConflictException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal NameConflictException(string message, GitErrorCategory category) : base(message, category) diff --git a/LibGit2Sharp/NativeException.cs b/LibGit2Sharp/NativeException.cs index 292372db7..d89f01c5f 100644 --- a/LibGit2Sharp/NativeException.cs +++ b/LibGit2Sharp/NativeException.cs @@ -1,16 +1,14 @@ using LibGit2Sharp.Core; using System; -using System.Collections.Generic; -using System.Globalization; -using System.Runtime.Serialization; -using System.Text; namespace LibGit2Sharp { /// /// An exception thrown that corresponds to a libgit2 (native library) error. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public abstract class NativeException : LibGit2SharpException { /// @@ -32,9 +30,11 @@ internal NativeException(string format, params object[] args) { } +#if !NET8_0_OR_GREATER internal NativeException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal NativeException(string message, GitErrorCategory category) : this(message) { diff --git a/LibGit2Sharp/NonFastForwardException.cs b/LibGit2Sharp/NonFastForwardException.cs index b5a858f47..0c29db1b9 100644 --- a/LibGit2Sharp/NonFastForwardException.cs +++ b/LibGit2Sharp/NonFastForwardException.cs @@ -1,6 +1,5 @@ -using System; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { @@ -8,7 +7,9 @@ namespace LibGit2Sharp /// The exception that is thrown when push cannot be performed /// against the remote without losing commits. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class NonFastForwardException : NativeException { /// @@ -43,6 +44,7 @@ public NonFastForwardException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -51,7 +53,7 @@ public NonFastForwardException(string message, Exception innerException) protected NonFastForwardException(SerializationInfo info, StreamingContext context) : base(info, context) { } - +#endif internal NonFastForwardException(string message, GitErrorCategory category) : base(message, category) { } diff --git a/LibGit2Sharp/NotFoundException.cs b/LibGit2Sharp/NotFoundException.cs index f8c49cc91..f92de90bc 100644 --- a/LibGit2Sharp/NotFoundException.cs +++ b/LibGit2Sharp/NotFoundException.cs @@ -1,13 +1,14 @@ -using System; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { /// /// The exception that is thrown attempting to reference a resource that does not exist. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class NotFoundException : NativeException { /// @@ -42,6 +43,7 @@ public NotFoundException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -50,6 +52,7 @@ public NotFoundException(string message, Exception innerException) protected NotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal NotFoundException(string message, GitErrorCategory category) : base(message, category) diff --git a/LibGit2Sharp/PeelException.cs b/LibGit2Sharp/PeelException.cs index d7758d7c9..79a6320a3 100644 --- a/LibGit2Sharp/PeelException.cs +++ b/LibGit2Sharp/PeelException.cs @@ -1,6 +1,5 @@ -using System; -using System.Runtime.Serialization; using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { @@ -8,7 +7,9 @@ namespace LibGit2Sharp /// The exception that is thrown when a tag cannot be peeled to the /// target type due to the object model. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class PeelException : NativeException { /// @@ -43,6 +44,7 @@ public PeelException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -51,6 +53,7 @@ public PeelException(string message, Exception innerException) protected PeelException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal PeelException(string message, GitErrorCategory category) : base(message, category) diff --git a/LibGit2Sharp/RecurseSubmodulesException.cs b/LibGit2Sharp/RecurseSubmodulesException.cs index cf4479701..b7e84f2ba 100644 --- a/LibGit2Sharp/RecurseSubmodulesException.cs +++ b/LibGit2Sharp/RecurseSubmodulesException.cs @@ -8,7 +8,9 @@ namespace LibGit2Sharp /// through submodules. The inner exception contains the exception that was /// initially thrown while operating on the submodule. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class RecurseSubmodulesException : LibGit2SharpException { /// @@ -34,6 +36,7 @@ public RecurseSubmodulesException(string message, Exception innerException, stri InitialRepositoryPath = initialRepositoryPath; } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -42,5 +45,6 @@ public RecurseSubmodulesException(string message, Exception innerException, stri protected RecurseSubmodulesException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } diff --git a/LibGit2Sharp/ReferenceWrapper.cs b/LibGit2Sharp/ReferenceWrapper.cs index 3e4243a7e..34513cd61 100644 --- a/LibGit2Sharp/ReferenceWrapper.cs +++ b/LibGit2Sharp/ReferenceWrapper.cs @@ -1,7 +1,8 @@ -using System; +using LibGit2Sharp.Core; +using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; -using LibGit2Sharp.Core; namespace LibGit2Sharp { @@ -10,7 +11,7 @@ namespace LibGit2Sharp /// /// The type of the referenced Git object. [DebuggerDisplay("{DebuggerDisplay,nq}")] - public abstract class ReferenceWrapper : IEquatable>, IBelongToARepository where TObject : GitObject + public abstract class ReferenceWrapper<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TObject> : IEquatable>, IBelongToARepository where TObject : GitObject { /// /// The repository. diff --git a/LibGit2Sharp/RemoveFromIndexException.cs b/LibGit2Sharp/RemoveFromIndexException.cs index 6d9718c18..6a2fad16e 100644 --- a/LibGit2Sharp/RemoveFromIndexException.cs +++ b/LibGit2Sharp/RemoveFromIndexException.cs @@ -7,7 +7,9 @@ namespace LibGit2Sharp /// /// The exception that is thrown when a file cannot be removed from the index. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class RemoveFromIndexException : LibGit2SharpException { /// @@ -43,6 +45,7 @@ public RemoveFromIndexException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -51,5 +54,6 @@ public RemoveFromIndexException(string message, Exception innerException) protected RemoveFromIndexException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } diff --git a/LibGit2Sharp/RepositoryNotFoundException.cs b/LibGit2Sharp/RepositoryNotFoundException.cs index 2255c0891..6a8ad54b5 100644 --- a/LibGit2Sharp/RepositoryNotFoundException.cs +++ b/LibGit2Sharp/RepositoryNotFoundException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace LibGit2Sharp { @@ -7,7 +6,9 @@ namespace LibGit2Sharp /// The exception that is thrown when a is being built with /// a path that doesn't point at a valid Git repository or workdir. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class RepositoryNotFoundException : LibGit2SharpException { /// @@ -42,6 +43,7 @@ public RepositoryNotFoundException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -50,5 +52,6 @@ public RepositoryNotFoundException(string message, Exception innerException) protected RepositoryNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } diff --git a/LibGit2Sharp/UnbornBranchException.cs b/LibGit2Sharp/UnbornBranchException.cs index 34ef437cb..bdbd11627 100644 --- a/LibGit2Sharp/UnbornBranchException.cs +++ b/LibGit2Sharp/UnbornBranchException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace LibGit2Sharp { @@ -7,7 +6,9 @@ namespace LibGit2Sharp /// The exception that is thrown when a operation requiring an existing /// branch is performed against an unborn branch. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class UnbornBranchException : LibGit2SharpException { /// @@ -42,6 +43,7 @@ public UnbornBranchException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -50,5 +52,6 @@ public UnbornBranchException(string message, Exception innerException) protected UnbornBranchException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } diff --git a/LibGit2Sharp/UnmatchedPathException.cs b/LibGit2Sharp/UnmatchedPathException.cs index 7d118346d..c00035740 100644 --- a/LibGit2Sharp/UnmatchedPathException.cs +++ b/LibGit2Sharp/UnmatchedPathException.cs @@ -1,12 +1,13 @@ using System; -using System.Runtime.Serialization; namespace LibGit2Sharp { /// /// The exception that is thrown when an explicit path or a list of explicit paths could not be matched. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class UnmatchedPathException : LibGit2SharpException { /// @@ -41,6 +42,7 @@ public UnmatchedPathException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -49,5 +51,6 @@ public UnmatchedPathException(string message, Exception innerException) protected UnmatchedPathException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } diff --git a/LibGit2Sharp/UnmergedIndexEntriesException.cs b/LibGit2Sharp/UnmergedIndexEntriesException.cs index 7594049b1..608572e6f 100644 --- a/LibGit2Sharp/UnmergedIndexEntriesException.cs +++ b/LibGit2Sharp/UnmergedIndexEntriesException.cs @@ -1,6 +1,5 @@ -using System; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { @@ -8,7 +7,9 @@ namespace LibGit2Sharp /// The exception that is thrown when an operation that requires a fully merged index /// is performed against an index with unmerged entries /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class UnmergedIndexEntriesException : NativeException { /// @@ -43,6 +44,7 @@ public UnmergedIndexEntriesException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -51,6 +53,7 @@ public UnmergedIndexEntriesException(string message, Exception innerException) protected UnmergedIndexEntriesException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal UnmergedIndexEntriesException(string message, GitErrorCategory category) : base(message, category) diff --git a/LibGit2Sharp/UserCanceledException.cs b/LibGit2Sharp/UserCanceledException.cs index ba6458049..c643e7008 100644 --- a/LibGit2Sharp/UserCanceledException.cs +++ b/LibGit2Sharp/UserCanceledException.cs @@ -1,13 +1,14 @@ -using System; -using System.Runtime.Serialization; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { /// /// The exception that is thrown when an operation is canceled. /// +#if !NET8_0_OR_GREATER [Serializable] +#endif public class UserCancelledException : NativeException { /// @@ -42,6 +43,7 @@ public UserCancelledException(string message, Exception innerException) : base(message, innerException) { } +#if !NET8_0_OR_GREATER /// /// Initializes a new instance of the class with a serialized data. /// @@ -50,6 +52,7 @@ public UserCancelledException(string message, Exception innerException) protected UserCancelledException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif internal UserCancelledException(string message, GitErrorCategory category) : base(message, category)