Я создал приложение Function Azure. В этом приложении я стараюсь прочитать файл JSON из текущего решения. Он отлично работает в моей местной среде разработки, но после развертывания файл не может быть прочитал. < /P>
public async Task GetFiles([HttpTrigger(AuthorizationLevel.Function, nameof(HttpMethod.Get), Route = "Files/GetFilePath")] FilePathRequest request)
{
try
{
return await _bundleOrchestrator.GetFileData(request);
}
catch (F9ApiException ex)
{
return new BadRequestErrorMessageResult(ex.ExceptionMessage) { StatusCode = ex.SourceStatusCode };
}
}
public async Task GetFileData()
{
try
{
// Get the current working directory
string currentDirectory = Directory.GetCurrentDirectory();
// Construct the path to the configuration folder and file
string configFolder = "Configuration"; // Adjust as needed
string configFileName = "NCPMobile_BundleConfig.json"; // Adjust as needed
string filePath = Path.Combine(currentDirectory, configFolder, configFileName);
// Check if the configuration file exists
if (!File.Exists(filePath))
{
throw new FileNotFoundException($"Configuration file not found at: {filePath}");
}
// Define JSON serializer settings
var jsonSettings = new Newtonsoft.Json.JsonSerializerSettings
{
MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore,
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
MetadataPropertyHandling = Newtonsoft.Json.MetadataPropertyHandling.Ignore
};
// Read the JSON content asynchronously
string jsonBundlesData = await File.ReadAllTextAsync(filePath);
return jsonBundlesData; //Sample response
// Proceed with processing jsonBundlesData as needed
}
catch (Exception ex)
{
// Handle exceptions appropriately
throw new ApplicationException("Error occurred while retrieving bundle configuration.", ex);
}
}
< /code>
Язык кодирования - csharp
[исходный файл для чтения данных json] [1] < /p>
[постоянный файл для поиска пути] [2] < /p>
Ошибка: < /p>
только ошибка < /p>
< /p> .>
Подробнее здесь: https://stackoverflow.com/questions/797 ... in-local-e
Функция Azure: невозможно прочитать файл JSON после развертывания во время работы в локальной среде ⇐ C#
Место общения программистов C#
1757804266
Anonymous
Я создал приложение Function Azure. В этом приложении я стараюсь прочитать файл JSON из текущего решения. Он отлично работает в моей местной среде разработки, но после развертывания файл не может быть прочитал. < /P>
public async Task GetFiles([HttpTrigger(AuthorizationLevel.Function, nameof(HttpMethod.Get), Route = "Files/GetFilePath")] FilePathRequest request)
{
try
{
return await _bundleOrchestrator.GetFileData(request);
}
catch (F9ApiException ex)
{
return new BadRequestErrorMessageResult(ex.ExceptionMessage) { StatusCode = ex.SourceStatusCode };
}
}
public async Task GetFileData()
{
try
{
// Get the current working directory
string currentDirectory = Directory.GetCurrentDirectory();
// Construct the path to the configuration folder and file
string configFolder = "Configuration"; // Adjust as needed
string configFileName = "NCPMobile_BundleConfig.json"; // Adjust as needed
string filePath = Path.Combine(currentDirectory, configFolder, configFileName);
// Check if the configuration file exists
if (!File.Exists(filePath))
{
throw new FileNotFoundException($"Configuration file not found at: {filePath}");
}
// Define JSON serializer settings
var jsonSettings = new Newtonsoft.Json.JsonSerializerSettings
{
MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore,
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
MetadataPropertyHandling = Newtonsoft.Json.MetadataPropertyHandling.Ignore
};
// Read the JSON content asynchronously
string jsonBundlesData = await File.ReadAllTextAsync(filePath);
return jsonBundlesData; //Sample response
// Proceed with processing jsonBundlesData as needed
}
catch (Exception ex)
{
// Handle exceptions appropriately
throw new ApplicationException("Error occurred while retrieving bundle configuration.", ex);
}
}
< /code>
Язык кодирования - csharp
[исходный файл для чтения данных json] [1] < /p>
[постоянный файл для поиска пути] [2] < /p>
Ошибка: < /p>
только ошибка < /p>
< /p> .>
Подробнее здесь: [url]https://stackoverflow.com/questions/79740847/azure-function-unable-to-read-json-file-after-deployment-while-works-in-local-e[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия