Exception when using silverlight toolkit 5 controls - silverlight

I'm working an application that is based on Silverlight 5.
It's framework is MVVM and implemented by Prism.
I'm using silverlight 5 toolkit too.
In one of my views I using wrapPanel and DateTimePicker from toolkit.
<navigation:Page x:Class="PIPM2.SupervisionSubSystem.Module.View.TestView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="TestView Page" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:my="clr-namespace:Silverlight.Controls;assembly=Silverlight.Controls" xmlns:my1="clr-namespace:Silverlight.Controls.Primitives;assembly=Silverlight.Controls">
<Grid>
<sdk:DatePicker />
<toolkit:WrapPanel >
</toolkit:WrapPanel>
</Grid>
</navigation:Page>
This sample buid successed but at runtime in InitializeComponent() method I got this Error =>
Could not load file or assembly 'System.Windows.Controls.Toolkit, Version=5.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest. (Exception from HRESULT: 0x80131053)
If I delete one of controls, wrapPanel or DatePicker the Error do not occur again.
How can I solve this problem.

What exact version of System.Windows.Controls.Toolkit are you currently referencing? Do you have multiple projects? If so, do different projects reference different versions of that same assembly?
If you want to know for sure which version of the DLL you are getting, just go to your .XAP file and rename it to .ZIP (XAP files are really ZIP files). Now look in the ZIP file and see exactly which DLL you have and what the version number is.

Related

Is it possible to include custom C++\WinRT UWP controls in WPF with XAML Islands and WindowsXamlHost?

I have a WPF application that is too onerous to rewrite wholesale in UWP. Some of the UWP controls would utilize SwapChainPanel and thus have C++/WinRT to manage DirectX. To determine the feasibility of implementing portions of the application in UWP and including them in WPF, I made a minimal sample app following Microsoft documentation that attempts to compose UWP controls in a WPF application targeting .NET Core 3.1.
<Window x:Class="WpfAppCore3._1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xh="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost"
Title="WPF App"
Height="500"
Width="800">
<StackPanel>
<xh:WindowsXamlHost InitialTypeName="UwpLib.ManagedGrid"
Height="225" />
<xh:WindowsXamlHost InitialTypeName="UwpLibNative.NativeGrid"
Height="225" />
</StackPanel>
</Window>
This works great for a managed control like UwpLib.ManagedGrid but UwpLibNative.NativeGrid does not load:
The debugger shows an exception:
System.BadImageFormatException: 'Bad IL format.'
That exception indicated to me a build configuration issue, but I think the application is set up correctly in that regard. Is this just not possible with XAML Islands today or have I made some configuration mistake in the sample app?
Update 1:
I discovered the "Windows Desktop Compatible" option and made sure that was set to "Yes". No change.

InitializeComponent not defined after converting from Windows phone 8 silverlight to universal apps

I have a Windows phone 8 Silverlight App that I'm trying to convert to Windows Universal Apps. I used a free tool from this website http://www.mobilize.net/silverlight which helps with the transition but I've encountered a weird error.
I've already searched through other posts and everyone seem to get this to work.. but those solutions aren't working for me... let me explain.
I have lots of Pages in my project and they all show the same error, different from the App.xaml.cs page.
In App.xaml.cs
In Main.xaml.cs
This is a link to another post with some solutions BlankPage constructor cannot initialize components
Now I checked my App.xaml and MainPage.xaml and they are correct according to the solution for everyone elese.
This is App.xaml first line:
<Application x:Class="StayMobileWP81.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="using:System" xmlns:local="using:StayMobileWP81">
And this is MainPage.xaml first line:
<Page x:Class="StayMobileWP81.Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" p2:SystemTray.BackgroundColor="#AF252B" p2:SystemTray.ForegroundColor="White" xmlns:p1="using:Microsoft.Phone.Shell" xmlns:p2="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
Both .cs files I use namespace StayMobileWP81.
Still having this error... And I tried to change Entrypoint in the Package.appxmanifest to point to "StayMobileWP81.App" and still nothing... It's currently pointing to Main.xaml
I also saw in another post that I had to change Build Action property to Page for InitializeComponet to work but, in my case, they were already set to Page in Main.xaml and ApplicationDefinition in App.xaml.
Does anyone know what am I missing here?

Why would loading a XAML file faile on a brand new, unaltered Silverlight project?

Why would loading a XAML file faile on a brand new, unaltered Silverlight project?
This is the first time I have started a silverlight project on the current machine I am on with Visual Studio 2010. Until now, I have been programing ni ASP.NET.
When I first tried to start a new Silverlight project, I was told I needed to install a fresh copy of Silverlight. I had to uninstall Silverlight as well as my versions of the Silverlight SDK. After uninstalling and reinstalling (now I have Microsoft Silverlight 5.1.20513.0 and Silverlight 4 SDK 4.0.50826.0) I was finally able to create a Silverlight Project. But the XAML code instantly failed to load in the IDE
http://i67.photobucket.com/albums/h292/Athono/ASP_DOT_NET%20and%20CSS/outofthegate02_zps0bd33d95.png
<UserControl x:Class="SilverlightApplication4.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
</Grid>
http://i67.photobucket.com/albums/h292/Athono/ASP_DOT_NET%20and%20CSS/outofthegate01_zpse0f20845.png
System.NullReferenceException
Object reference not set to an instance of an object.
at Microsoft.Windows.Design.Platform.SilverlightMetadataContext.SilverlightXamlExtensionImplementations.d__8.MoveNext()
at MS.Internal.Design.Metadata.ReflectionProjectNode.BuildSubsumption()
at MS.Internal.Design.Metadata.ReflectionProjectNode.SubsumingNamespace(Identifier identifier)
at MS.Internal.Design.Markup.XmlElement.BuildScope(PrefixScope parentScope, IParseContext context)
at MS.Internal.Design.Markup.XmlElement.ConvertToXaml(XamlElement parent, PrefixScope parentScope, IParseContext context, IMarkupSourceProvider provider)
at MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlSourceDocument.FullParse(Boolean convertToXamlWithErrors)
at MS.Internal.Design.DocumentModel.DocumentTrees.Markup.XamlSourceDocument.get_RootItem()
at Microsoft.Windows.Design.DocumentModel.Trees.ModifiableDocumentTree.get_ModifiableRootItem()
at Microsoft.Windows.Design.DocumentModel.MarkupDocumentManagerBase.get_LoadState()
at MS.Internal.Host.PersistenceSubsystem.Load()
at MS.Internal.Host.Designer.Load()
at MS.Internal.Designer.VSDesigner.Load()
at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedView.Load()
at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedDesignerFactory.Load(IsolatedView view)
at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view)
at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view)
at MS.Internal.Host.Isolation.IsolatedDesigner.Load()
at MS.Internal.Designer.DesignerPane.LoadDesignerView()
Any suggestions?

WPF merged resource dictionaries in every user control - bad idea?

I keep my app's resources in a separate DLL and reference them in my main EXE using something like this in App.xaml:-
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyThemesAssembly;component/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
When I edit a window that's in the main EXE project, the VS2010 designer doesn't recognise any resources from the other assembly, so I don't see any styling applied (not really an issue as I always work in the XAML view). However Resharper doesn't recognise these external resource names either, resulting in lots of squiggles under resource names when I'm editing XAML.
I've found that I can fix both the VS designer and Resharper by including the above XAML in each window and user control, but is this going to have an adverse effect on memory and/or performance? Will each window get a separate copy of the resources?
We had a problem in our application with the use of ResourceDictionaries referenced in each UserControl / View. I advise against that. We managed to reduce our application's memory footprint by like 300 mb by the use of SharedResourceDictionaries. I looks like you will end up with the ResourceDictionary being instantiated once for every single UserControl in your application. Don't do that just to fix VS designer.
Try using VS2012.
I have a test project which I was using which I was doing resource dictionary merging from an external assembly and in my app.xaml I have this:
<Application x:Class="WpfPackDictionaries.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WPFCommonLibrary;component/Vectors/Vectors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Then in my mainwindow.xaml I have this where the path pulls in a style ModifiablePathStyle:
<Window xmlns:Control="clr-namespace:WPF.Common.Control;assembly=WPFCommonLibrary" x:Class="WpfPackDictionaries.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Path Style="{StaticResource ModifiablePathStyle}" Fill="Red"/>
<Control:Jabberwocky />
</Grid>
</Window>
Intellisense/Resharper (V7.1 10/31 (Early Access Build)) recognizes the style and I have no squigglies:
Hence have you tried to work in VS2012?
VS2012 is able to 'see' resources since VS XAML designer loads and executes your code in design-time, so VS can inspect what resources will be available at runtime. ReSharper never uses design-time code execution (since this requires your code always be in compilable state) so XAML support became a bit more complex task.
ReSharper 8.0 implemented support for BAML decompilation and do extracts the list of XAML files and resolves XAML resources from referenced binary assemblies.

Wpf Assembly Reference failing for Mef powered application that has executing assembly and mef modules physically separated

We have an application as well as a Visual Studio add-in that both load their (modular) functionality from Mef assemblies located elsewhere on a users machine than the application is installed itself.
Now one of our developers used Wpf (using Prism/System.Windows.Interactivity) to create the UI component for a new module but unfortunately now the module / Xaml Parser throws a XamlParseException saying that it cannot load System.Windows.Interactivity.dll and looking at the fusion log basically shows that the paths its looking for / in is the one the hosting .exe runs from, not where the Mef module (containing the wpf / xaml ui) resides in.
The System.Windows.Interactivity.dll does in fact reside in the Mef's module/assembly directory (referenced in that mef module / assembly and copy local set to true) so I was wondering how we would specify the namespace for System.Windows.Interactivity properly below so the assembly loading does in fact look in the assembly's directory aswell?
<UserControl x:Class="TestExplorer.Modules.DocumentChecks.DocumentChecksMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:Converter="clr-namespace:TestExplorer.Modules.DocumentChecks.Converter"
xmlns:TreeView="clr-namespace:TestExplorer.Modules.DocumentChecks.TreeView" mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="500">
There is one entry here at SO that has the exact same problem (see Prism assembly reference failure: System.Windows.Interactivity), however the solution to add prism/system.windows.interactivity as reference to the hosting application is only a workaround, at best - it basically defeats the applications' modular purpose (leave alone that we cannot deploy the system.windows.interactivity into the devenv.exe's location in case users use our Visual Studio Addin.. and devenv.exe being the hosting process there).

Resources