Including UWP project in WPF project raises runtime errors - wpf

Project I work on need to show UWP control from UWP library inside of WPF window.
Here is the document page on which I had based my work (check section for adding custom UWP control):
https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/windowsxamlhost#add-a-custom-uwp-control
Had setup WPF window and it shows standard UWP controls (like button) at the runtime just fine. However, when I include UWP project, WPF window throws exception at start (at the moment of context initialization of EF).
Could not load file or assembly 'Windows.Foundation.UniversalApiContract, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
Sqlite version I'm using is 1.0.88.0 and EF is 5. But it doesn't make any sense that it clashes with these libraries?

Ffixed an issue on startup by updating SQLite package to 1.0.111.0 and EF to version 6.2.0.

Including UWP project in WPF project raises runtime errors
Derive from official document, I create sample project. When build the project, it throw many errors that lost assembly. After add the Windows.winmd file every thing work well. You could try to add the Windows.winmd file where in the C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd to WPF app reference.
Detail steps
Right click project References -> Add References -> Browse(file type all file)-> select Windows.winmd
And this sample project that you could refer this.

Related

How do I add XAML windows to a .Net Core "WPF Application"?

In Visual Studio 2019, if I create a new "WPF Application" using .Net Core (top in the screenshot below) it will create a project for me that does in fact include a working XAML setup. However, there is no way that I can find to add a new XAML window through the VS interface. Right-clicking on a folder, choosing Add and then Window (WPF) just gives you the codebehind, no XAML anywhere.
If instead I create a new "WPF App (.NET Framework)" (bottom in the screenshot) It creates a similar project but I can in fact add XAML windows via right-click and selecting Add as above, including the relevant codebehind.
What gives? If we want to use .Net Core do we have to create the XAML files manually? Am I missing something? XAML is explicitly not listed under the .Net Core option, but the project creation process does indeed create XAML files in the project as expected.
With suggestions above, I was able to get this working in VS2019. To condense the answer:
In the project properties, ensure the "Output Type" is "Windows Application".
Ensure the target framework is ".Net 5.0"
Then directly edit the .csproj file by adding <UseWPF>true</UseWPF> to the first <PropertyGroup>.
Right-click on the project, select: Add > Window
I seem to have answered my own question but it seems useful so I will leave it up here. When you create your .Net Core WPF Application, if you choose .NetCore 3.1 (Long-term support) you get the behavior I describe above (no ability to add XAML windows). If you choose .NET 5.0 (Current) it works as expected and you can add XAML windows.

Failed to load toolbox item in VIsual Studio in WinForms C++

I am creating a windows form application in managed C++. To add a custom user control either one can create a new project or add CLR User control to same project. When I add a user control to same project it builds and shows control in toolbar. When I drag and drop it onto my main UI it throws up error.
"Failed to load toolbox item, It will be removed from Toolbox".
There is no error if I create a separate project under same solution and compile control as a DLL. Is there a way I can add a custom user control to same project and use it.
Also I looked up similar question on the topc but none of them has helped me. I have checked the files and I am building the project as Win32 and there is no way control being separately built as x64.
Had same problem after one or both of renaming project or/and changing platform, most posted "solutions" provided to other people asking the same question didn't seem to work.
What did work for me was to go into the project folder and delete the obj folder, and just to be safe the bin folder too, then build again. (Seems the so called Build->Clean menu item only does half of the required work.)

Could not load file or assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'

After installing vs2012 and updating my vs2010 WPF project I get the following error in WPF designer:
Could not load file or assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
This happens for every xaml page in the project.
<dx:DXWindow.DataContext>
<vm:MyViewModel/>
</dx:DXWindow.DataContext>
VS marks vm:MyViewModel as the problem line. If I comment it out the designer windows shows a blank page. This same projects works fine in VS2010. The target framework is set to 4 in both versions of visual studio.
This is a bug in Entity Framework (EF5) when used with Visual Studio 2012 or in a project that references a winmd assembly.
EF tries to load all referenced assemblies to check if they contain pre-compiled views. During this process EF5 fails when it tries to load a winmd assembly. Trying to load winmd assemblies with Assembly.Load causes a System.IO.FileLoadException which is not handled in EF5.
NOTE: Although your application might not have a reference to any .winmd assembly, VS2012 WPF Designer's host process (xdesproc.exe) has a reference to the Windows.winmd assembly. This explains why the projects work fine in VS2010 and during runtime. You can use .NET Reflector to confirm this.
This issue has been fixed in EF6.
A bug was filed for this http://entityframework.codeplex.com/workitem/609
and fixed in changeset 50c1e5a2c46d http://entityframework.codeplex.com/SourceControl/changeset/50c1e5a2c46d

Could not load assembly, Exception from HRESULT: 0x80131040

Exception:
Could not load file or assembly 'WPFVisifire.Charts, Version=4.1.0.0, Culture=neutral, PublicKeyToken=99d724542e4db593' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
We are working with our stock exchange charting application using Visifire. We have two app versions. Online Silverlight version and desktop WPF version. I already created Silverlight application and its working well. Same code I copied in WPF application but WPF chart application throws exception.
I’m very new to dot net development. Please help.
Are you using Windows7 OS?
I suggest you to follow the steps below.
Remove reference of WPFVisifire.Charts.dll and WPFToolkit.dll (if
used) from your project.
Clean your project.
Close the application.
Right click no WPFVisifire.Charts.dll and WPFToolkit.dll(if used) then click on properties.
Go to General Tab.
Click on Unblock button.
Now open your project in Visual Studio.
Add new reference to unblocked WPFVisifire.Charts.dll and
WPFToolkit.dll(if used).
Compile your project and run.

The tag "xxx" does not exist in XML namespace"yyy" / Reference could not be found

I have a winform usercontrol than I want to add to wpf project.
I added the relevant references (WindowsFormsIntegration, SystemWindowsForms and my user control dll) and added this row in my XAML:
xmlns:MyControl="clr-namespace:xx.xx.xx;assembly=xx.xx"
And then this:
<WindowsFormsHost><MyControl:control></MyControl:control></WindowsFormsHost>
When I write "MyControl:" the "control" is automated show up that mean VS recognize the control and all references added ok... but when I compile the project this give me the error in the title.
Edit
Its very strange when I'm compile the all project i've got error "The type or namespace name "xx' could not be found..."
but I added all the refernces and the VS recognize the namespace so why the compiler don't found them? If this problem will be solved I beleive the other problem also will disappear.
The solution is: Go to your project properties and change the Target Framework from Client Profile to the full version of the .Net you are using, see the image below. This problem happens if your DLL targets the full .NET Framework, and your WPF Application (main project) targets .Net Client Profile.
This happened to me when I included the assembly name in the namespace definition, but both controls were in the same assembly. Just removing the assembly part of the namespace declaration solved it.
Visual Studio will load the reference only for reflection so it will show correct intellisense correctly. But in order to compile, compiler will need all the dlls that your referenced dll is dependent on. So visual studio will show intellisense for mycontrol as it can find it in reference. But your myontrol may reference other dlls which you may not have added. You will have to add dependent references of mycontrol in your project too.
It could also be that the target framework is different between your projects. We host a class library dll with the WPF pages, and it was targeted to 'Any CPU', but the host application was targeted to 'x86'. Once they matched, the problem went away.
I ran into the same "The type or namespace name 'xx' could not be found..." issue.
It disappears when I moved my Visual Studio files on a local drive. They were stored on a shared network directory before. I dont know the root cause of this, but at least I can have my designer running now.
I've encountered this problem before and replacing <MyControl:control></MyControl:control> with just <MyControl:control/> fixed it for me.
No idea why though. It seems like the first form is only for controls which can contain other controls.

Resources