views:

331

answers:

3

I have created an OpenGL control in C++ and wish to use this in a WPF application. I have successfully accomplished this and it works fine on Vista and XP machines but when I open my project on a windows 7 machine the WPF design window will not display. When I try to run the program I get the exception:

"Cannot create instance of 'Window1' defined in assembly 'LabUserInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9."

'LabUserInterface' is where my OpenGL stuff lives. Also I have this error in the WPF window:

"Type 'MS.Internal.Permissions.UserInitiatedNavigationPermission' in Assembly 'PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable."

A: 

I don't think your permission error has anything to do with OpenGL. Maybe it's generated trying to collect information on the real error (that would explain the attempt to use the serializer) Try to comment out all the insides of your custom control so it simply inherits from the base class, and try again (ok, you may need to leave some property definitions). If that fixes it, add implementation back slowly until you isolate what's causing the problem.

If it still fails, what you probably want to do is open one copy of Visual Studio and use it to debug a second copy of Visual Studio with your project open in the WPF designer. Then you can break on the exception, view variables up and down the call stack, and generally troubleshoot your problem.

Do you have the same version of Visual Studio and same patches on both working and non-working dev environments? Visual Studio patches are much more likely to produce this problem than the underlying OS. With OpenGL, the video driver could also be important, so post that information.

Ben Voigt
+2  A: 

Two possibilities:

1) UAC, pathing issue, dependency path issue, .NET security or some other permissions issue (maybe run as administrator) to test. Or make sure your assembly has visibility to all dependencies and correct permissions (i.e. private if in bin folders or next to app, public if in gac or outside of app space).

2) Also, make sure you can run OpenGL on the win7 box. Could be a video driver or something trying to enumerate the video profiles on the card. Update your video card drivers. If using a shared OpenGL version make sure it is present on the machine.

I know that when you make a C++ control in .NET security issues are a top problem. Be sure your C++ control has visibility into the opengl dlls (if shared) and that they are in the loading path (drop them all in C:\windows\system32 if all else fails to be sure they can be seen or local in the private assembly folder (bin)).

We had this same problem with a image toolkit for PVR and it turned out one dll was not in the dependency path. A good tool is DependencyWalker for checking: http://dependencywalker.com/

Ryan Christensen
A: 

Thanks Ryan, dependency walker was a great help. Turns out that I needed glut32.dll in the debug folder for the WPF project as well which is something I have not required on other machines.

paj777
It appears to depend on the particular visual studio development evnvironment setup a to where visual studio looks for the libraries that the solution depends upon.
paj777