LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FileNotFoundException when loading a WPF control hosted in a WinForms UserControl

I have written a .net application using .Net 4.0.  The application comprises a collection of native, managed C++ and C# DLLs which provide a UI written in WPF.

 

I have been requested to make this available to LabView users which has raised a number of issues.  How to run .Net 4.0 and how to host WPF controls in Labview.  These have all now been resolved except for an exception when I try to access any WPF user control that references a particular collection of libraries.

 

Details

All DLLs exist in one folder and my test WinForms app will load all the WPF usercontrols which are hosted in WinForms controls using ElementHost.

 

However when I try to create the WinForms UserControl in Labview I get the exception

 

System.Xaml.XamlObjectWriterException occurred
  HResult=-2146233088
  Message=Set property 'System.Windows.ResourceDictionary.Source' threw an exception.
  Source=System.Xaml
  LineNumber=0
  LinePosition=0
  StackTrace:
       at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
  InnerException: System.IO.FileNotFoundException
       HResult=-2147024894
       Message=Could not load file or assembly 'ThorLabs.MotionControl.Tools.WPF.UI, Culture=neutral' or one of its dependencies. The system cannot find the file specified.
       Source=mscorlib
       FileName=ThorLabs.MotionControl.Tools.WPF.UI, Culture=neutral
       FusionLog=Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Program Files\National Instruments\LabVIEW 2012\LabVIEW.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = THORLABS\lbunnage
LOG: DisplayName = ThorLabs.MotionControl.Tools.WPF.UI, Culture=neutral
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: ThorLabs.MotionControl.Tools.WPF.UI, Culture=neutral | Domain ID: 6
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/lbunnage/Documents/LabVIEW Workspace
LOG: Initial PrivatePath = NULL
Calling assembly : PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/lbunnage/Documents/LabVIEW Workspace/ThorLabs.MotionControl.Tools.WPF.UI.DLL.
LOG: Attempting download of new URL file:///C:/Users/lbunnage/Documents/LabVIEW Workspace/ThorLabs.MotionControl.Tools.WPF.UI/ThorLabs.MotionControl.Tools.WPF.UI.DLL.
LOG: Attempting download of new URL file:///C:/Users/lbunnage/Documents/LabVIEW Workspace/ThorLabs.MotionControl.Tools.WPF.UI.EXE.
LOG: Attempting download of new URL file:///C:/Users/lbunnage/Documents/LabVIEW Workspace/ThorLabs.MotionControl.Tools.WPF.UI/ThorLabs.MotionControl.Tools.WPF.UI.EXE.

       StackTrace:
            at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
            at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
            at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
            at System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(String assemblyName, String assemblyVersion, String assemblyKey)
            at MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(Uri uri, String& partName, Boolean& isContentFile)
            at MS.Internal.AppModel.ResourceContainer.GetPartCore(Uri uri)
            at System.IO.Packaging.Package.GetPartHelper(Uri partUri)
            at System.IO.Packaging.Package.GetPart(Uri partUri)
            at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream()
            at System.IO.Packaging.PackWebResponse.GetResponseStream()
            at System.IO.Packaging.PackWebResponse.get_ContentType()
            at MS.Internal.WpfWebRequestHelper.GetContentType(WebResponse response)
            at MS.Internal.WpfWebRequestHelper.GetResponseStream(WebRequest request, ContentType& contentType)
            at System.Windows.ResourceDictionary.set_Source(Uri value)
            at System.Windows.Baml2006.WpfSharedBamlSchemaContext.<Create_BamlProperty_ResourceDictionary_Source>b__1c4(Object target, Object value)
            at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(Object instance, Object value)
            at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
            at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
       InnerException:

Looking at the .Net assemblies I can see that the assembly ThorLabs.MotionControl.Tools.WPF.UI is actually loaded.

 

Removing all references to this library enables the UserControl to be loaded but the UserControl with this library referenced works perectly in a WinForms app.

 

I am rapidly running out of hair, so urgent help is required before I go completely bald.

0 Kudos
Message 1 of 5
(5,802 Views)

Hi,

 

Have you tried the following?

 

http://digital.ni.com/public.nsf/allkb/32B0BA28A72AA87D8625782600737DE9

 

Tyler

Certified LabVIEW Architect
0 Kudos
Message 2 of 5
(5,797 Views)

I have already done this as I have previously been running the non UI elements of my project in LabView succesfully.

 

Thanks

0 Kudos
Message 3 of 5
(5,791 Views)

Hi Laurence,

 

Are you still experiencing this issue? From the error log, it all seems to be .NET problems.

Is LabVIEW itself giving you any error codes at all, that we could look into?

 

Best Regards,

Applications Engineer
0 Kudos
Message 4 of 5
(5,753 Views)

I am still having problems although I have a partial solution.

 

If I copy all my DLLs into the directory containing the VI then everything seems to work as expected.

 

However, this is not a customer facing solution.  I could try using the GAC, but this is a solution I would rather not go down as when the project is complete there are going to be in excss of a 100 DLLs, some .NET and some native.

 

I would like to try accessing the .NET components from a shared directory.  This works if I have no UI and create a Node to a .Net assembly in a shared folder, however it fails when I am using a .Net assembly with any UI.

 

The problem as far as I can see it is this:

I am wrapping some wpf controls in a WinForms UserControl (in a separate assembly) If I do not use any merged libraries everything still works OK.

When I try to use any styles from a common assemby (in the same folder) the ResourceManager complains that it cannot find the common assembly holding the style.

I guess you'll need to understand WPF to understand this.

 

I suspect that LabView is somehow redirecting the assembly manager to find the assemblies in the first place but does not know how to tell the ResourceManager where to look.

 

0 Kudos
Message 5 of 5
(5,749 Views)