NLog.Web.AspNetCore 5.3.12 вызывает исключение System.UriFormatException с net9.0C#

Место общения программистов C#
Ответить
Anonymous
 NLog.Web.AspNetCore 5.3.12 вызывает исключение System.UriFormatException с net9.0

Сообщение Anonymous »

К сведению разработчиков NLog:
У меня есть решение VS 2022 ASP.NET Core, которое работает под .NET 8.0. Я обновил TargetFramework до net9.0, и все работает нормально. Затем я обновил все пакеты NLog.* до последней версии (включая NLog.Web.AspNetCore до 5.3.14), и приложение сломалось.
При запуске Я получаю исключение System.UriFormatException из этого кода:
logger = NLog.LogManager.Setup()
.LoadConfigurationFromAppSettings().GetCurrentClassLogger();

Я устранял неполадки, просматривая разные версии пакета, и в конце концов выяснилось, что поломка происходит при переходе NLog.Web.AspNetCore с 5.3.11 на 5.3.12.< /p>
На данный момент у меня все в порядке, так как я могу придерживаться версии 5.3.11, но имейте в виду, что здесь есть что-то скрытое, над чем вам придется разобраться.
ОБНОВЛЕНИЕ: добавлено содержимое nlog-internal.txt, сгенерированное версией 5.3.12, по запросу @RolfKristensen, под трассировкой стека. Когда я возвращаюсь к версии 5.3.11, аналогичный вывод не заканчивается там, где это происходит в .12:
2024-11-20 15:41:38.5470 Debug Skip loading NLogLoggingConfiguration from empty config section: NLog
2024-11-20 15:41:38.5834 Info Loading NLog config from XML file: Z:\rwells\very\special\NLog.config
...normal loading proceeds...

В .11 кажется, что после того, как NLog отказывается от UNC, казалось бы, без имени хоста, он переходит к Z:, который представляет собой букву диска, сопоставленную с UNC, где мои файлы расположены.
Возможно, в LoggingConfigurationFileLoader произошли некоторые изменения/регресс относительно обработки UNC и сопоставленных дисков с .11 до .12?
ОБНОВЛЕНИЕ 2 (2024.11.21): см. uri-hacking.ps1 и его выходные данные ниже всего остального.
С уважением,

Ричард
Stack Trace
System.UriFormatException
HResult=0x80131537
Message=Invalid URI: The hostname could not be parsed.
Source=System.Private.Uri

StackTrace:
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
at System.Uri..ctor(String uriString, UriKind uriKind)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver)
at System.Xml.XmlReader.Create(String inputUri)
at NLog.Internal.Fakeables.AppEnvironmentWrapper.LoadXmlFile(String path)
at NLog.Config.XmlLoggingConfiguration.CreateFileReader(String fileName)
at NLog.Config.XmlLoggingConfiguration.LoadFromXmlFile(String fileName)
at NLog.Config.XmlLoggingConfiguration..ctor(String fileName, LogFactory logFactory)
at NLog.Web.SetupBuilderExtensions.c__DisplayClass0_0.b__2(ISetupLoadConfigurationBuilder config)
at NLog.SetupBuilderExtensions.LoadConfiguration(ISetupBuilder setupBuilder, Action`1 configBuilder)
at NLog.Web.SetupBuilderExtensions.LoadConfigurationFromAppSettings(ISetupBuilder setupBuilder, String basePath, String environment, String nlogConfigSection, Boolean optional, Boolean reloadOnChange)
at Program.$(String[] args) in Z:\rwells\very\special\Program.cs:line 20

nlog-internal.txt
2024-11-20 15:28:06.7547 Debug No file exists at candidate config file location: \\?\UNC\rwells\very\special\bin\Development\net9.0\IDService.exe.nlog
2024-11-20 15:28:06.7547 Debug No file exists at candidate config file location: \\?\UNC\rwells\very\special\bin\Development\net9.0\IDService.dll.nlog
2024-11-20 15:28:06.7779 Debug Reading config from XML file: \\?\UNC\rwells\very\special\bin\Development\net9.0\NLog.config
2024-11-20 15:28:06.8262 Error Failed loading from config file location: \\?\UNC\rwells\very\special\bin\Development\net9.0\NLog.config Exception: System.UriFormatException: Invalid URI: The hostname could not be parsed.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
at System.Uri..ctor(String uriString, UriKind uriKind)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver)
at System.Xml.XmlReader.Create(String inputUri)
at NLog.Internal.Fakeables.AppEnvironmentWrapper.LoadXmlFile(String path)
at NLog.Config.LoggingConfigurationFileLoader.LoadXmlLoggingConfigurationFile(LogFactory logFactory, String configFile)
at NLog.Config.LoggingConfigurationFileLoader.TryLoadLoggingConfiguration(LogFactory logFactory, String configFile, LoggingConfiguration& config)
2024-11-20 15:28:06.8446 Debug No file exists at candidate config file location: \\?\UNC\rwells\very\special\bin\Development\net9.0\NLog.dll.nlog
2024-11-20 15:28:06.8465 Info NLog Configuration has not been loaded.
2024-11-20 15:28:07.3532 Debug No file exists at candidate config file location: \\?\UNC\rwells\very\special\bin\Development\net9.0\nlog.Development.config

uri-hacking.ps1
$paths = (
'\\sharepoint.business.com\DavWWWRoot\rs\project 1\document.txt',
'Z:\rwells\very\special\place',
'\\actual-hostname\actual-sharename\rwells\very\special\place',
'\\?\UNC\actual-hostname\actual-sharename\rwells\very\special\place'
)

foreach ($path in $paths) {

echo "$path ->"
$uri = [System.Uri]$path
echo " $($uri.AbsoluteUri) [is UNC = $($uri.IsUnc)]"

}

вывод на Windows Server 2022
\\sharepoint.business.com\DavWWWRoot\rs\project 1\document.txt ->
file://sharepoint.business.com/DavWWWRoot/rs/project%201/document.txt [is UNC = True]
Z:\rwells\very\special\place ->
file:///Z:/rwells/very/special/place [is UNC = False]
\\actual-hostname\actual-sharename\rwells\very\special\place ->
file://actual-hostname/actual-sharename/rwells/very/special/place [is UNC = True]
\\?\UNC\actual-hostname\actual-sharename\rwells\very\special\place ->
InvalidArgument: Z:\rwells\Temp\uri-hacking.ps1:11
Line |
11 | $uri = [System.Uri]$path
| ~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot convert value "\\?\UNC\actual-hostname\actual-sharename\rwells\very\special\place" to type "System.Uri". Error: "Invalid URI: The hostname could not be parsed."
file://actual-hostname/actual-sharename/rwells/very/special/place [is UNC = True]


Подробнее здесь: https://stackoverflow.com/questions/792 ... etframewor
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»