I'm trying to open the sample Solution for the Microsoft Ribbon for WPF, but I get this error about being unable to load metadata. The solution on that site, and the one linked in the error, is How to: Use an Assembly from the Web in Visual Studio. However, I don't see any 'Unblock' option when I check the Properties dialog for RibbonControlsLibrary.dll in C:\Program Files (x86)\Microsoft Ribbon for WPF\v3.5.40729.1. This may be because when I downloaded the Ribbon stuff, it wasn't the library directly, but rather an installer for the library. How can I get rid of this error so I can actually see the design view of the sample XAML files for the Ribbon WPF?
Here is the full error message:
Unable to load the metadata for assembly 'RibbonWindowSample'. This assembly may have been downloaded from the web. See http://go.microsoft.com/fwlink/?LinkId=179545. The following error was encountered during load: Could not load file or assembly 'RibbonWindowSample' or one of its dependencies. The system cannot find the file specified.
According to the error message, it's not RibbonControlsLibrary.dll that's at fault, it's RibbonWindowSample. Have you unbolocked the solution file and files that form the project? If RibbonWindowSample came pre-compiled, you may need to re-build the solution to generate compiled assemblies that don't have the "web mark" on them.
Did you download a zip file? You need to unblock the zip before unzipping it. Once it's unzipped you won't be able to unblock the individual files that were in it.
Here's what to look for at the bottom of the properties dialog.
I was seeing the metadata error before building the Solution--it shows up when I first load the Solution. I tried building it just now and it built fine, plus the design view shows the XAML window. I don't know why I see the metadata error when it first loads but it goes away upon building.
Related
I am trying to use Nish Nishant's classes to extend the system menu of a WPF window. Nish's project is in Code Project as An MVVM friendly approach to adding system menu entries in a WPF application
I have included Nish's source files in my project and defined some menu commands for the system menu.
This was easy and as far as I can tell it is working correctly. I am not getting a runtime error.
However, the XAML designer is showing me the error
'System.Windows.FreezableCollection`1[NS.MVVM.SystemMenuItem]' is not a valid value for property 'MenuItems'.
This error only appears after compiling the project. I do not get the error in Nish's sample project. I am using Visual Studio 2019 version 16.8.3. What might be causing this error message?
EDIT
I now know what is causing the error message, in the sense that I know what the difference is between my project and Nish's sample project.
Nish's project targets the x86 platform, whereas my project targeted Any CPU.
This is understandable, because the code uses Win32 API functions. I have changed the target platform for my project to x86 and the error has gone.
However, I still don't really understand why the error occurs and how it relates to the underlying issue of target platform.
This seems like it should be pretty simple but I can't seem to make it happen. Lets say I have an existing project with a user control named uc1. I would like to use this user control in another project. I right-click the project name in the solution explorer and select add>existing item, change the drop down to all files and select the files uc1.xaml and uc1.xaml.vb. This of course adds the files to the project but there is no correlation between the xaml and the code behind file and there is no way to use the control. What is the proper way of doing this?
Reed's answer is a good architectural one. If you plan on creating a control that you will reuse in many projects then it's best to use a control library.
Your original question is valid in some situations though. Say you have some source code from the Internet that you've unzipped to your drive. This project contains a .XAML file and its linked .vb file that you want to add to a project.
As you seen, the Visual Studio Solution Explorer doesn't link the files when adding with the "Add Item" dialog. I think this is a bug. I find that if I reload the project, the affiliation is added.
Here's a workaround I use. I drag the files from Windows Explorer /File Explorer onto the project in Solution Explorer. That works correctly the first time.
This of course adds the files to the project but there is no correlation between the xaml and the code behind file and there is no way to use the control. What is the proper way of doing this?
Normally, you'd add a reference to the other project, and use the UserControl directly.
This allows you to build a single project with your UserControl, and use the resulting assembly (DLL) in multiple projects without duplicating the code.
If you want to reuse your user controls you need to create a new project and choose "Class Library" from the list of available projects. When compiled this class library can easily be used by any number of other projects and solutions simply by adding a reference to compiled DLL created when you build this class library.
Edit: As mentioned in other answer it's "WPF UserControl Library", not simple "Class Library"...
You just need to add the .xaml file and VS should auto add the code behind(nested). I've seen this not work a few times and as #Walt Ritscher said this is probably a bug.
I found simply restarting Visual Studio and reloading my solution worked.
We use a custom audit assembly (C#) for logging several kinds of actions within SSIS in script tasks.
We post build the custom assembly in the GAC (for runtime) and to the public assemblies area of the IDE (VS2008) for design time file referencing. After the postbuild is done the custom assembly is available for use in runtime and for designtime in the .NET tab of the file reference popup.
However, after re-opening the script task, the file reference is gone in the list and the script doesn't compile.
How's that possible ?
Seems liks a bug in SSIS, but I have a workaround here:
Just click Save All instead of just closing the popped up IDE C# editor.
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.
I need to display an image, which I've done without problems before, but today I decided to be tricky and use "add as link" instead. Well, now I get:
The file Images/hello.png is not part of the project or its 'Build Action' property is not set to 'Resource'.
Wait... its Build Action is set to Resource. I've seen a Silverlight solution that involves the usage of Merged Dictionaries to share files between Silverlight and WPF projects, but it's not clear to me that this would even apply to my WPF + Image issue.
Has anyone solved this problem before? I could make copies of all of the images, but that seems a little silly if I have a shared repository with clip art and the like.
Dave,
I've just tried to add image as a link to plain WPF application. Build action is "Resource" (don't confuse with "Embedded Resource"). I've added it to the root, and refer to it as <Image Source="/file_name.jpg"/> - all works fine.
The message you have is it compile or runtime? If it's a runtime, how do you refer to the image? Do you see it in Reflector, when you open your assembly (it should be under Resources folder)?
I have images in one assembly which I want to share into another. I've used Add as Link in my second assembly. In the project where the actual image files are located they are in a Resources\Images folder. In the project which links to those files the links are also in a Resources\Images folder. At runtime a XamlParseException claiming "cannot locate resource" is thrown.
My xaml which is referencing the image is in a UserControls folder.
In the project which actually contains the images the path ..\Resources\Images\Blah.png works fine as expected.
Opening the DLLs in Reflector makes it obvious that in the assembly with the linked images holds the images at the root level - the compiler is not respecting the folder location. So in the project with the linked files I have to use ..\Blah.png to find the resource.
Surely a bug in the compiler?