Quantcast
Channel: WPF Localization Extension
Viewing all articles
Browse latest Browse all 286

Closed Issue: "key: " in designer [9314]

$
0
0
Since it made this new version completely useless, I did some checking myself and found the problem of this issue. It isn't that hard to fix actually.

In the ResxLocalizationProviderBase there is a function GetResourceManager that is not working correctly.

There is this line (line 248):
```
var dir = Path.GetDirectoryName(process.Modules[0].FileName);
```

This doesn't work for x64 processes when the host process is x86 (and the other way around).
This is easily solved through WMI (the only way that works afaik):

Create a function in the same file:
```
/// <summary>
/// Get the executable path for both x86 and x64 processes.
/// </summary>
/// <param name="processId">The process id.</param>
/// <returns>The path if found; otherwise, null.</returns>
private static string GetExecutablePath(int processId)
{
const string wmiQueryString = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process";
using (var searcher = new ManagementObjectSearcher(wmiQueryString))
using (var results = searcher.Get())
{
var query = from p in Process.GetProcesses()
join mo in results.Cast<ManagementObject>()
on p.Id equals (int)(uint)mo["ProcessId"]
where p.Id == processId
select new
{
Process = p,
Path = (string)mo["ExecutablePath"],
CommandLine = (string)mo["CommandLine"],
};
foreach (var item in query)
{
return item.Path;
}
}
return null;
}
```

Then, change line 248 from above to:
```
var dir = Path.GetDirectoryName(GetExecutablePath(process.Id));
if (String.IsNullOrWhiteSpace(dir))
continue;
```

However, there is other major issue in this same function.

Let's start with the first. There are foreach loops over the files:
```
foreach (var f in files)
```

There are a couple of issues I'm having with both these lines. The first being that it copies everything from every subdirectory. I have a subdirectory that stores temp files (a total of 12GB of small files). It takes 35 minutes to fully copy the folder that is of zero interest to this library. After all, it only needs two different file types, and the exe's and dll's of the assembly. So, the first change I made for both foreach loops is this:

```
foreach (var f in files.Where(x => !String.IsNullOrWhiteSpace(x)))
{
if (!(f.EndsWith(".resx", StringComparison.OrdinalIgnoreCase) ||
f.EndsWith(".resources", StringComparison.OrdinalIgnoreCase)) &&
!dir.Equals(Path.GetDirectoryName(f), StringComparison.OrdinalIgnoreCase)) // We aren't bothered with other files
continue;

// The other code
```

Then, there is this bit of code (283-288):
```
var dst = Path.Combine(assemblyDir, f.Replace(dir + "\\", ""));

var dstDir = Path.GetDirectoryName(dst);
if (!Directory.Exists(dstDir))
Directory.CreateDirectory(dstDir);
File.Copy(f, dst, true);
```

Since the generated cache folder is already quite long (C:\Users\UserName\AppData\Local\Microsoft\VisualStudio\11.0\Designer\ShadowCache\gx43qkl1.wag\fdty5ini.grk\tmp), it easily goes over the max file path length (250). This caused the function to crash. Honestly, I don't care about one or two files that aren't able to be copied and thus disabling the whole preview so I made some changes too for this bit:
```
try
{
var dst = Path.Combine(assemblyDir, f.Replace(dir + "\\", ""));

var dstDir = Path.GetDirectoryName(dst);
if (String.IsNullOrWhiteSpace(dstDir))
continue;

if (!Directory.Exists(dstDir))
Directory.CreateDirectory(dstDir);
File.Copy(f, dst, true);
}
// ReSharper disable once EmptyGeneralCatchClause
catch { } // Ignore exceptions so the designer can continue to work.
```

So, here is the request to the author to fix this in the version on NuGet so I can continue to use that one. I don't mind editing code but it would be nice if it worked out of the box.

Thanks for all your hard work on this, we've been using it for a while now, but in my opinion it's current state is worse than what it is a year ago.
I also don't understand the reason why you want to put LocTextUpper etc on obsolete. Using converters isn't always an option when you need multiple converters (and I don't like chaining converters).

There are also some data errors now:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.FrameworkElement', AncestorLevel='1''. BindingExpression:Path=Parent; DataItem=null; target element is 'ContextMenu' (Name='MainContextMenu'); target property is 'Parent' (type 'DependencyObject')


Viewing all articles
Browse latest Browse all 286

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>