I've found this issue and potential resolutions to this issue both here and on the MSDN forums but my problem is a little different. When I call the ctor on the Runtime class, I get this exception:
System.IO.FileNotFoundException: Could not load file or assembly 'INuiInstanceHelper, Version=1.0开发者_开发技巧.0.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
I do not get this error when constructing the Runtime in a simple scenario (e.g. a Loaded event in WPF. see my simple scenario code below).
In my real scenario, my Runtime's ctor is called when a user opens a file from an open file dialog. This is kicked off from a MenuItem command in a ViewModel, which uses a "service" that wraps the open file dialog. The ViewModel then initializes the Runtime after the file path is specified:
void ExecuteOpenCommand()
{
var path = this.openFileService.OpenFile();
if (!string.IsNullOrEmpty(path))
{
var model = ViewModelLoader.ReadMainModel(path);
var viewModel = ViewModelLoader.LoadViewModel(model);
this.MainViewModel = viewModel;
this.MainViewModel.NuiService = this.nuiService;
this.nuiService.Initialize();
}
}
The nuiService just constructs the Runtime if it has never been initialized before:
bool initialized;
public void Initialize()
{
if (initialized)
{
return;
}
try
{
this.runtime = new Runtime();
}
catch (FileNotFoundException ex)
{
Trace.WriteLine(ex.ToString());
}
// ...
initialized = true;
}
However, when I start a new WPF project from scratch and construct the runtime, I do not get this error:
// does not throw exception
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Runtime r = new Runtime();
r.Initialize(RuntimeOptions.UseSkeletalTracking);
r.Uninitialize();
}
When Googling this exception I've come across solutions that require updating DirectX, rebooting, updating Windows, or reinstalling INuiInstanceHelper to the GAC. I don't see how these solutions will help since I can construct the Runtime without error in a different way. I thought my problem must have something to do with it being user-initiated (e.g. from a Button Click), but when I moved the Runtime constructor to a method that gets executed near app startup (e.g. in the ctor of my ViewModel which is instantiated declaratively through data-binding) I still had the issue. Thoughts?
The answer was to change the Platform Target to x86. For some reason it got set to Any CPU. grrrr....
精彩评论