Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 39 additions & 35 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
# Code quality rules
dotnet_code_quality_unused_parameters = all:suggestion

# Suppressed diagnostics
dotnet_diagnostic.CA1002.severity = none # Change 'List<string>' in '...' to use 'Collection<T>' ...
dotnet_diagnostic.CA1032.severity = none # Add the following constructor to ...Exception: public ...
dotnet_diagnostic.CA1034.severity = none # Do not nest type. Alternatively, change its accessibility so that it is not externally visible
dotnet_diagnostic.CA1062.severity = none # Disable null check, C# already does it for usdotnet_diagnostic.CA1416.severity = silent # Validate platform compatibility
dotnet_diagnostic.CA1062.severity = none # Disable null check, C# already does it for us
dotnet_diagnostic.CA1303.severity = none # Do not pass literals as localized parameters
dotnet_diagnostic.CS1591.severity = none # Missing XML comment for publicly visible type or member
dotnet_diagnostic.CA1805.severity = none # Member is explicitly initialized to its default value
Expand All @@ -113,8 +114,10 @@ dotnet_diagnostic.CA2253.severity = none # Named placeholders in the logging mes
# Diagnostics elevated as warnings
dotnet_diagnostic.CA1000.severity = warning # Do not declare static members on generic types
dotnet_diagnostic.CA1031.severity = warning # Do not catch general exception types
dotnet_diagnostic.CA1032.severity = warning # Add the following constructor to ...Exception: public ...
dotnet_diagnostic.CA1063.severity = warning # Implement IDisposable correctly
dotnet_diagnostic.CA1064.severity = warning # Exceptions should be public
dotnet_diagnostic.CA1416.severity = warning # Validate platform compatibility
dotnet_diagnostic.CA1508.severity = warning # Avoid dead conditional code
dotnet_diagnostic.CA2000.severity = warning # Call System.IDisposable.Dispose on object before all references to it are out of scope
dotnet_diagnostic.CA2201.severity = warning # Exception type System.Exception is not sufficiently specific
Expand All @@ -123,55 +126,56 @@ dotnet_diagnostic.CA2201.severity = warning # Exception type System.Exception is
###############################
# Naming Conventions #
###############################
# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = error
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
# Define the 'constant_fields' symbol group:
dotnet_naming_symbols.constant_fields.applicable_kinds = field

# Styles

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

dotnet_naming_style.static_underscored.capitalization = camel_case
dotnet_naming_style.static_underscored.required_prefix = s_

dotnet_naming_style.underscored.capitalization = camel_case
dotnet_naming_style.underscored.required_prefix = _

dotnet_naming_style.end_in_async.required_prefix =
dotnet_naming_style.end_in_async.required_suffix = Async
dotnet_naming_style.end_in_async.capitalization = pascal_case
dotnet_naming_style.end_in_async.word_separator =

# Symbols

dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_symbols.constant_fields.required_modifiers = const

# Define the 'private_static_fields' symbol group
dotnet_naming_symbols.private_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private
dotnet_naming_symbols.private_static_fields.required_modifiers = static
# Define the 'static_underscored' naming style
dotnet_naming_style.static_underscored.capitalization = camel_case
dotnet_naming_style.static_underscored.required_prefix = s_
# Define the 'private_static_fields_underscored' naming rule

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

dotnet_naming_symbols.any_async_methods.applicable_kinds = method
dotnet_naming_symbols.any_async_methods.applicable_accessibilities = *
dotnet_naming_symbols.any_async_methods.required_modifiers = async

# Rules

dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = error
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style

dotnet_naming_rule.private_static_fields_underscored.symbols = private_static_fields
dotnet_naming_rule.private_static_fields_underscored.style = static_underscored
dotnet_naming_rule.private_static_fields_underscored.severity = error

# Define the 'private_fields' symbol group:
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
# Define the 'underscored' naming style
dotnet_naming_style.underscored.capitalization = camel_case
dotnet_naming_style.underscored.required_prefix = _
# Define the 'private_fields_underscored' naming rule
dotnet_naming_rule.private_fields_underscored.symbols = private_fields
dotnet_naming_rule.private_fields_underscored.style = underscored
dotnet_naming_rule.private_fields_underscored.severity = error

# Define the 'any_async_methods' symbol group
dotnet_naming_symbols.any_async_methods.applicable_kinds = method
dotnet_naming_symbols.any_async_methods.applicable_accessibilities = *
dotnet_naming_symbols.any_async_methods.required_modifiers = async
# Define the 'end_in_async' naming style
dotnet_naming_style.end_in_async.required_prefix =
dotnet_naming_style.end_in_async.required_suffix = Async
dotnet_naming_style.end_in_async.capitalization = pascal_case
dotnet_naming_style.end_in_async.word_separator =
# Define the 'async_methods_end_in_async' naming rule
dotnet_naming_rule.async_methods_end_in_async.symbols = any_async_methods
dotnet_naming_rule.async_methods_end_in_async.style = end_in_async
dotnet_naming_rule.async_methods_end_in_async.severity = error
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion

###############################
# C# Coding Conventions #
Expand Down
6 changes: 6 additions & 0 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@
<PackageVersion Include="Microsoft.Data.Sqlite" Version="7.0.3" />
<PackageVersion Include="Microsoft.Graph" Version="4.51.0" />
<PackageVersion Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.25.3" />

<!-- Analyzers -->
<!-- <PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.5.22"> -->
<!-- <PrivateAssets>all</PrivateAssets> -->
<!-- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> -->
<!-- </PackageReference> -->
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions dotnet/SK-dotnet.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public void It$SOMENAME$()
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=DEC4D140B393B04F8A18C0913BDE0592/Shortcut/@EntryValue">copy</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=DEC4D140B393B04F8A18C0913BDE0592/Text/@EntryValue">// Copyright (c) Microsoft. All rights reserved.
</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=awaiters/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=davinci/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Joinable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mergeresults/@EntryIndexedValue">True</s:Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- NuGet Package Settings -->
<PackageId>Microsoft.SemanticKernel.Skills.Document</PackageId>
<Title>Semantic Kernel - OpenXml Connector</Title>
<Version>0.7</Version>
<Version>0.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- NuGet Package Settings -->
<PackageId>Microsoft.SemanticKernel.Skills.Memory.Sqlite</PackageId>
<Title>Semantic Kernel - SQLite Connector</Title>
<Version>0.7</Version>
<Version>0.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public LocalUserMSALCredentialManager()
attribute2: new KeyValuePair<string, string>("Product", "SemanticKernel"))
.Build();

// TODO: remove sync wait, may cause deadlock, use await or JoinableTaskFactory.Run
// TODO: remove sync wait, may cause deadlock
#pragma warning disable VSTHRD002 // Synchronously waiting on tasks or awaiters may cause deadlocks. Use await or JoinableTaskFactory.Run instead.
this._cacheHelper = MsalCacheHelper.CreateAsync(this._storageProperties)
.GetAwaiter()
.GetResult();
#pragma warning restore VSTHRD002

this._cacheHelper.VerifyPersistence();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public MsGraphConnectorException(string message) : base(message)
public MsGraphConnectorException(string message, Exception innerException) : base(message, innerException)
{
}

private MsGraphConnectorException()
{
// Do not use, error message is required
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- NuGet Package Settings -->
<PackageId>Microsoft.SemanticKernel.Skills.MsGraph</PackageId>
<Title>Semantic Kernel - Microsoft Graph Connector</Title>
<Version>0.7</Version>
<Version>0.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- NuGet Package Settings -->
<PackageId>Microsoft.SemanticKernel.Skills.Web</PackageId>
<Title>Semantic Kernel - Microsoft Bing Connector</Title>
<Version>0.7</Version>
<Version>0.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 20 additions & 1 deletion dotnet/src/SemanticKernel/AI/AIException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public enum ErrorCodes
/// </summary>
/// <param name="errCode">Error code of the exception.</param>
/// <param name="message">Message of the exception</param>
public AIException(ErrorCodes errCode, string message) : base(errCode, message)
public AIException(ErrorCodes errCode, string? message = null) : base(errCode, message)
{
this.ErrorCode = errCode;
}
Expand All @@ -96,4 +96,23 @@ public AIException(ErrorCodes errCode, string message, Exception e) : base(errCo
{
this.ErrorCode = errCode;
}

#region private ================================================================================

private AIException()
{
// Not allowed, error code is required
}

private AIException(string message) : base(message)
{
// Not allowed, error code is required
}

private AIException(string message, Exception innerException) : base(message, innerException)
{
// Not allowed, error code is required
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ private async Task<T> ExecutePostRequestAsync<T>(string url, string requestBody)
}
}

// C# finalizer
/// <summary>
/// C# finalizer
/// </summary>
~OpenAIClientAbstract()
{
this.Dispose(false);
Expand Down
4 changes: 4 additions & 0 deletions dotnet/src/SemanticKernel/CoreSkills/HttpSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public void Dispose()
GC.SuppressFinalize(this);
}

/// <summary>
/// Dispose internal resources
/// </summary>
/// <param name="disposing">Whether the method is explicitly called by the public Dispose method</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
Expand Down
29 changes: 26 additions & 3 deletions dotnet/src/SemanticKernel/Diagnostics/Exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,35 @@ protected Exception(TErrorCode errCode, string? message, Exception? innerExcepti
{
}

#region private ================================================================================
/// <summary>
/// Parameterless ctor, do not use
/// </summary>
protected Exception()
{
// Not allowed, error code is required
}

/// <summary>
/// Standard ctor, do not use
/// </summary>
/// <param name="message">Exception message</param>
protected Exception(string message) : base(message)
{
// Not allowed, error code is required
}

/// <summary>
/// Standard ctor, do not use
/// </summary>
/// <param name="message">Exception message</param>
/// <param name="innerException">Internal exception</param>
protected Exception(string message, Exception innerException) : base(message, innerException)
{
// Not allowed, error code is required
}

private static string BuildMessage(TErrorCode errorType, string? message)
{
return message != null ? $"{errorType.ToString("G")}: {message}" : errorType.ToString("G");
}

#endregion
}
21 changes: 20 additions & 1 deletion dotnet/src/SemanticKernel/Diagnostics/ValidationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public enum ErrorCodes
/// </summary>
/// <param name="errCode">The error code.</param>
/// <param name="message">The message.</param>
public ValidationException(ErrorCodes errCode, string message) : base(errCode, message)
public ValidationException(ErrorCodes errCode, string? message = null) : base(errCode, message)
{
this.ErrorCode = errCode;
}
Expand All @@ -70,4 +70,23 @@ public ValidationException(ErrorCodes errCode, string message, Exception e) : ba
{
this.ErrorCode = errCode;
}

#region private ================================================================================

private ValidationException()
{
// Not allowed, error code is required
}

private ValidationException(string message) : base(message)
{
// Not allowed, error code is required
}

private ValidationException(string message, Exception innerException) : base(message, innerException)
{
// Not allowed, error code is required
}

#endregion
}
21 changes: 20 additions & 1 deletion dotnet/src/SemanticKernel/KernelException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public enum ErrorCodes
/// </summary>
/// <param name="errCode">Error code to put in KernelException.</param>
/// <param name="message">Message to put in KernelException.</param>
public KernelException(ErrorCodes errCode, string message) : base(errCode, message)
public KernelException(ErrorCodes errCode, string? message = null) : base(errCode, message)
{
this.ErrorCode = errCode;
}
Expand All @@ -86,4 +86,23 @@ public KernelException(ErrorCodes errCode, string message, Exception e) : base(e
{
this.ErrorCode = errCode;
}

#region private ================================================================================

private KernelException()
{
// Not allowed, error code is required
}

private KernelException(string message) : base(message)
{
// Not allowed, error code is required
}

private KernelException(string message, Exception innerException) : base(message, innerException)
{
// Not allowed, error code is required
}

#endregion
}
5 changes: 4 additions & 1 deletion dotnet/src/SemanticKernel/Memory/NullMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ namespace Microsoft.SemanticKernel.Memory;
/// </summary>
public sealed class NullMemory : ISemanticTextMemory
{
public static NullMemory Instance { get; } = new NullMemory();
/// <summary>
/// Singleton instance
/// </summary>
public static NullMemory Instance { get; } = new();

/// <inheritdoc/>
public Task SaveInformationAsync(
Expand Down
Loading