Comments (7)
Thanks for reporting, I will try to run the tests again and check if there's an exception
from my.extensions.localization.json.
Thanks for reporting, I will try to run the tests again and check if there's an exception
Thanks for replying, When I run my WebApplication in my Unit Test project. JsonStringLocalizerFactory create a JsonStringLocalizer with wrong Resources Path, the path should be in my WebApplication project,turns out the JsonStringLocalizer used my Unit Test project's path. But my Unit Test project doesn't have a directory named Resource, and I want my WebApplication project in unit test still using my Resources path under my WebApplication project, just like I'm using Microsoft's StringLocalization.I don't want to copy my Resources files from my WebApplication project to my Unit Test project.
Is that clear enough? Sorry, English is not my forte.
In my WebApplication project's Main method:
builder.Services.AddJsonLocalization(options => options.ResourcesPath = "Resources");
In my XUnit test project to create a Test for WebApplication project
App = new WebApplicationFactory<Program>().WithWebHostBuilder(builder => {});
Client = App.CreateClient();//Client is an instance of HttpClient
and then I used
Client.Get("route/to/controller/action")
After this, the WebApplication project throws an exception System.IO.DirectoryNotFoundException.
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.IO.DirectoryNotFoundException: Could not find a part of the path '/PathToSolution/TestProject/bin/Debug/net6.0/Resources'.
at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
at System.IO.Enumeration.FileSystemEnumerator`1.Init()
at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options)
at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options)
at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
at System.IO.Directory.EnumerateFiles(String path, String searchPattern)
at My.Extensions.Localization.Json.Internal.JsonResourceManager.TryLoadResourceSet(CultureInfo culture)
at My.Extensions.Localization.Json.Internal.JsonResourceManager.GetResourceSet(CultureInfo culture, Boolean tryParents)
at My.Extensions.Localization.Json.Internal.JsonResourceManager.GetString(String name)
at My.Extensions.Localization.Json.JsonStringLocalizer.GetStringSafely(String name, CultureInfo culture)
at My.Extensions.Localization.Json.JsonStringLocalizer.get_Item(String name)
at Microsoft.Extensions.Localization.StringLocalizer`1.get_Item(String name)
from my.extensions.localization.json.
Please create a PR showing your unit test which thrown the exception, then I can try to figure out why it's happening
from my.extensions.localization.json.
Sorry,I don't get it. What is PR? Pull Request? Demo? Or something others?I gonna Google it.Wait me back.Thks.
from my.extensions.localization.json.
Hi, hishamco. IWebHostEnvironment.Environment.ContentRootPath
this is what i want.
Is there a way to use IWebHostEnvironment.Environment.ContentRootPath
in class PathHelpers.GetApplicationRoot()
using System.IO;
using System.Reflection;
namespace My.Extensions.Localization.Json.Internal
{
public static class PathHelpers
{
public static string GetApplicationRoot() => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
}
Never mind!
After all this, I've made a mistake. I have a typo about my Resource directory name. I typed Recourse as my Resource directory name. so this exception was thrown.Sorry to bother you.
Now I just correct the resource directory name and modify my code in the Program.cs
builder.Services.AddJsonLocalization(options =>
{
options.ResourcesPath =
Path.Combine(GlobalServiceProvider.App!.Environment.ContentRootPath, "Resources");
//GlobalServiceProvider.App.Environment is type of IWebHostEnvironment
});
Thanks for reply.Thank you very much. By the way,PR => Pull request. got it!.
Please close this issue.
from my.extensions.localization.json.
Sorry,I don't get it. What is PR?
Pull Request, just to reproduce the issue
from my.extensions.localization.json.
Never mind!
After all this, I've made a mistake. I have a typo about my Resource directory name. I typed Recourse as my Resource directory name. so this exception was thrown.Sorry to bother you.
No problem at all, the important thing is everything works as expected ;)
from my.extensions.localization.json.
Related Issues (20)
- Add Benchmark HOT 16
- Missing Localization Behavior
- Remove internal contructor in JsonStringLocalizer HOT 1
- Ability to override methods in JsonStringLocalizer and JsonStringLocalizerFactory HOT 9
- Registering the service one should provide absolute path, otherwise exception is thrown HOT 31
- Localization FallBack Considerations
- Support ResourceLocationAttribute HOT 1
- Support RootNamespaceAttribute
- assign culture in runtime HOT 3
- Have one resource file for project HOT 13
- Any plan to switch the project to a .NET standard class library ? HOT 10
- How to use with DataAnnotation? HOT 17
- Regression Bug HOT 1
- LocalizationSample project is not working HOT 3
- About NET5.0 Blazor WebAssembly Uses My.Extensions.Localization.Json HOT 14
- System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. HOT 11
- Class based localisation only works when the class is in the root namespace HOT 5
- Can you provide an core api example with DataAnnotations? HOT 2
- JsonResourceManager does not dispose of (unix) File System Watches HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from my.extensions.localization.json.