I have this image in a XAML file of my project:
<Image Source="/my.namespace;component/Resources/document_plain.png" Margin="5" />
The image is in a directory /Resources/document_plain.png at the root of my project folder. The settings of the image are:
But, when running a debug instance, I immediately get an XamlParseException:
The string "/my.namespace;component/Resources/document_plain.png" in the attribute "Source" could not be converted to type "System.Windows.Media.ImageSource".
The file or assembly "my.namespace, Culture=neutral" or a dependency could not be found. The system cannot find the file. Error in object "System.Windows.HierarchicalDataTemplate" in markup file "MyProject;component/view/mainwindow.xaml", line 20, position 12.
Which strikes me as strange, because IMHO the project is correctly set up. What am I missing/doing wrong?
Cudos to dlev from the comments:
It looks like the assembly name is "MyProject", so your string should probably be Source="MyProject;component/Resources/document_plain.png"
Related
I know this is a recurring error but I can't seem to get around it.
Intellisense does recognize the name of my custom control and suggests to add the proper using: directives, but not only XAML designer doesn't find the name of the control but I can't get through compilation either.
The custom control is a public class defined as
namespace MyApp.CustomControls
{
public class CustomTextBox : TexBox
{
...
}
}
And in my MainPage.xaml
<Page ...
xmlns:customControls="using:MyApp.CustomControls">
...
<customControls:CustomTextBox/>
...
</Page>
This does not render in design nor compile.
This answer and the ones below are not working for me.
The error message:
Error XDG0008 The name "CustomTextBox" does not exist in the namespace "using:MyApp.CustomControls".
Your code should works well after you build the project, and it works well in my side using your above code. Try to clean your solution or delete the bin and obj folders in your project then rebuild your app again. Also try to restart your Visual Studio. If it still happens, you can provide a reproducible sample to help me look into this issue.
I've seen quite a lot solutions saying that you should rebuild the project, restart Visual Studio or restart the machine.
What worked for me was specifying the assembly in the namespace reference, that is:
xmlns:the_namespace="clr-namespace:the_namespace" - produces the above error.
xmlns:the_namespace="clr-namespace:the_namespace;assembly=the_assembly" - works well.
I got a version of this error in my embedded UserControl when I tried to use the Name property in my XAML instead of using x:Name. In other words, when my XAML code looked like this:
myUserControls="using:MyUserControls"
<myUserControls:GraphCanvas Name="GraphCanvas" />
I got an error that 'The name "GraphCanvas" does not exist in the namespace "using:MyUserControls"'. When I changed one line of code to this:
<myUserControls:GraphCanvas x:Name="GraphCanvas" />
Everything built just fine.
I'm dropping this solution here because it took me about a day and a half to figure out this problem and this was the only stackoverflow page I found when I searched the error string. Hopefully I will save someone else the hassle I went through.
<Window x:Class="AFIC.View.WizardDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:view="clr-namespace:AFIC_Controller.View"
xmlns:res="clr-namespace:AFIC_Controller.Resources"
Title="{x:Static res:Strings.WizardWelcomeWindow_Title}"
ShowInTaskbar="True"
Width="800"
Height="600"
WindowStartupLocation="CenterScreen"
WindowStyle="SingleBorderWindow"
BorderBrush="#003B7B"
BorderThickness="0"
ResizeMode="NoResize"
Icon="/AFIC_Controller;component/Resources/Images/att_icon.ico"
>
<view:WizardView Loaded="WizardView_Loaded_1"/>
</Window>
I am giving path for my icon file as Icon="/AFIC_Controller;component/Resources/Images/att_icon.ico"
but after debugging it shows an error "Error 1 Could not find a part of the path 'C:\AFIC_Controller;component\Resources\Images\att_icon.ico'
Make sure the Icon file is included in your project and also change the Build Action of that icon file as Resources. For Build Action, go to the properties of that file.
Looking at your code, I have noticed something:
<Window x:Class="AFIC.View.WizardDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:view="clr-namespace:AFIC_Controller.View"
xmlns:res="clr-namespace:AFIC_Controller.Resources"
Title="{x:Static res:Strings.WizardWelcomeWindow_Title}"
ShowInTaskbar="True"
Width="800"
Height="600"
WindowStartupLocation="CenterScreen"
WindowStyle="SingleBorderWindow"
BorderBrush="#003B7B"
BorderThickness="0"
ResizeMode="NoResize"
Icon="/AFIC_Controller;component/Resources/Images/att_icon.ico"
>
This class seems to be in a namespace named AFIC.View, but you're trying to access an image from the AFIC_Controller namespace. When trying to access a content file from a referenced assembly, you need to use the following syntax:
Referenced Assembly Resource File
The pack URI for a resource file that is compiled into a referenced assembly uses the following authority and path:
• Authority: application:///.
• Path: The name of a resource file that is compiled into a referenced assembly. The path must conform to the following format:
AssemblyShortName[;Version][;PublicKey];component/Path
◦ AssemblyShortName: the short name for the referenced assembly.
◦ ;Version [optional]: the version of the referenced assembly that contains the resource file. This is used when two or more referenced assemblies with the same short name are loaded.
◦ ;PublicKey [optional]: the public key that was used to sign the referenced assembly. This is used when two or more referenced assemblies with the same short name are loaded.
◦ ;component: specifies that the assembly being referred to is referenced from the local assembly.
◦ /Path: the name of the resource file, including its path, relative to the root of the referenced assembly's project folder.
So having a guess at your correct path, you could try this:
pack://application:,,,/AFIC_Controller;component/Resources/Images/att_icon.ico
If that still doesn't work, then please take a look at the many examples in the Pack URIs in WPF page on MSDN... one of them must fit your situation.
Add att_icon.ico in to Images folder through visual studio or any IDE you use. Copy and paste does not work.
I'm getting designer error on code:
The Component i'm willing to define a List of properties for:
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace TestProjectForProperty.Test
{
public class MyTreeView : TreeView
{
private List<TypeDescriptorBase> _descriptorsAvailable = new List<TypeDescriptorBase>();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<TypeDescriptorBase> DescriptorsAvailable
{
get { return _descriptorsAvailable; }
set { _descriptorsAvailable = value; }
}
}
}
The Descriptor itself:
using System;
namespace TestProjectForProperty.Test
{
[Serializable]
public class TypeDescriptorBase
{
public string Name { get; set; }
public override string ToString()
{
return Name;
}
}
}
I am getting the following error if i try to use the component for example on a form and add any items on the property sheet or in the component's constructor to the DescriptorsAvailable property
Error 1 Invalid Resx file. Could not load type
System.Collections.Generic.List`1[[TestProjectForProperty.Test.TypeDescriptorBase,
TestProjectForProperty, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 which is used in the .RESX file.
Ensure that the necessary references have been added to your project.
Line 134, position 5. ...\visual studio
2010\Projects\TestProjectForProperty\TestProjectForProperty\Form1.resx 134 5 TestProjectForProperty
In the Resx file there is data field with base64 encoded stuff inside when this error is present.
I have been searching for an answer, but the best i got is to restart everything, it didn't help me, do you guys have any suggestions? I'm using .net 4 client and visual studio 2010
In my experience, this is due to a change of version of a referenced library, or a change of the lib itself, which contains the backing type of a property you have defined in your user control. The solution is to "force" the visual studio designer to re-initialize it's designer code for that type, and not expect to retrieve a "canned" version of it from the .resx file of the control.
1) Delete the offending data section in the .resx file of your control. This will be a section in the xml of the .resx file associated with your user control, which has a node: <data></data> - the name attribute will be set to whatever you've named that object in the properties of whatever you added this type to. The <data>/data> section contains a base64 encoded string that is the encoded form of the name and version of the library the type comes from. This is where the problem ism, because it now contains an encoded version of the library and/or version number you are no longer referencing in order to include the type. Delete the entire <data>/data> section, from opening to closing tag, save the change and close the file. Now the "artifact" is gone.
2) Now find the place in the designer file for your control, where the type is instantiated; this is initialization code generated for you by visual studio, and it is the place that is expecting to load a "canned" definition of the type from the base64 encoded string contained within the .resx file. The line will look something like this:
this.myCtrlFoo.MyPropertyFroo = ((MyNamespaceFoo.MyTypeFoo)(resources.GetObject("myCtrlFoo.MyPropertyFroo")));
...now just replace the resources.GetObjec call with the instantiation of a new instance of the appropriate type like so:
this.myCtrlFoo.MyPropertyFroo = ((MyNamespaceFoo.MyTypeFoo)(new MyNamespaceFoo.MyTypeFoo()));
...now save the change to the file, close it, rebuild, and everything should now build & run OK.
Put the MyTreeView and TypeDescriptorBase classes into another project and reference it from your GUI project will resolve the issues.
I'm not sure why exactly the problem occurs - I guess it has something to do with the way the serializing process is generating the base64 string for the DescriptorsAvailable Property. Maybe somebody else can give us some insight.
I've struggled quite a bit with this; I have three user controls that all expose the same non-designer property, but for some reason, any change to two of the three would instantly cause the next build to fail with this same issue. This is in VS 2015.
I wound up having to add the following two attributes to the property that kept expanding in the resx file, and it hasn't occurred since. It works for me because they're not available in the designer anyway.
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
For me, this error occured when I used a custom class as a property for the user control. When I switched from property to traditional get- and set- methods, the error disappeared. I guess this is because properties are already compiled at design-time, so when you build the whole project, a new version of the custom class is compiled which is separate from the one of the control, and the reference is broken.
For me, with the custom class Inventory, all I had to do was to switch from this property-based approach:
public Inventory Resources {get;set;}
to this method-based approach:
private Inventory resources;
public Inventory getResources() { return resources; }
public void setResources(Inventory newResources) { resources = newResources; }
I hope this helps someone, as I've been spending some hours on figuring it out.
In my case I've got the error : "error MSB3103: Invalid Resx file. The specified module could not be found" executed in a light windows container based on mcr.microsoft.com/powershell instead of mcr.microsoft.com/windows:1909 (was working fine on 1909).
The error was on a ressource icon that was compressed with PNG inside.
It can be checked by opening the ressource on visual studio : Project > Properties > Ressources.resx, select icons, double click on the icon, check the end of the title that is either "..,BMP]" or "...,PNG]").
Updating the icon with an uncompressed format solve the "Invalid Resx file" issue.
I stumbled across this question today whilst looking for the solution to a similar issue.
Unfortunately none of the above worked for me, however my issue turned out to be that I had different versions of the .NET Framework for different projects. For example;
Project A - .NET Framework 4.7.2
Project B - .NET Framework 4
Where Project B was referencing Project A. Solution was simply to change the .NET Framework version of Project B to 4.7.2 (in my case) and hey presto the issue was resolved.
A shame Visual Studio doesn't provide a more helpful error message in this case, but something to look out for!
I am starting a new project and oriented my projectstructure on the structure recommended in this question.
Now I am seeing strange behaviour. When I am setting the datacontext in the View-XAML, it isn't found at runtime (getting a XamlParseException). When I set it in the constructor in the codebehind-file, everything is working just fine.
Is this official (documented) behaviour when using different assemblies, or am I doing something wrong?
The code:
Not Working:
MainView.xaml:
<UserControl x:Class="ViewsRoot.Views.MainView"
xmlns:baseControls="clr-namespace:BaseControls;assembly=BaseControls"
xmlns:viewModels="clr-namespace:ViewModelsRoot;assembly=ViewModelsRoot">
<UserControl.DataContext>
<viewModels:ShellViewModel />
</UserControl.DataContext>
MainView.xaml.cs
public MainView()
{
InitializeComponent();
// No DataContext set in codebehind-file
}
Working:
MainView.xaml:
<UserControl x:Class="ViewsRoot.Views.MainView"
xmlns:baseControls="clr-namespace:BaseControls;assembly=BaseControls"
xmlns:viewModels="clr-namespace:ViewModelsRoot;assembly=ViewModelsRoot">
<!--<UserControl.DataContext>
<viewModels:ShellViewModel />
</UserControl.DataContext> -->
MainView.xaml.cs:
public MainView()
{
InitializeComponent();
DataContext = new ViewModelsRoot.ShellViewModel();
}
Update:
The Exception-Text is:
{"The file or assembly \" ViewModelsRoot, PublicKeyToken = null \ "or one of its dependencies was not found. The system can not find the file specified."}
And the only inner Exception I can see is a System.IO.FileNotFoundException.
Update 2:
Thanks for the comments, but I haven't forgotten a namespace. I shortened it here for showing the code, but I double- and triplechecked (again). The DataContexts namespace is also filled in by intellisense. The whole <viewModels:ShellViewModel /> is written by intelli-sense. So it is found at designtime... ...so any more ideas?
Update 3:
The xaml is "correctly" parsed as I am able to bind the DataContext to a class in the same assembly.
I have reproduced this error using a three project solution, with the specified dependencies between them:
StartupProject → ViewsRoot
ViewsRoot → ViewModelsRoot
ViewModelsRoot
"StartupProject" has "exe" output type, while the other two have "dll".
In my case, I solved the problem by adding "ViewModelsRoot" to the References list of "StartupProject". It is not a coding problem, but rather a runtime problem, because "ViewModelsRoot.dll" is not copied to "StartupProject" output folder.
When you specify the DataContext in code-behind, Visual Studio notices the need for that "dll" and adds it to the output after compilation. This doesn't happen when setting the DataContext from XAML. It is tricky because "ViewModelsRoot" code is used from XAML with Reflection. Adding it to References list forces Visual Studio to copy the "dll" in both cases.
You can also copy "ViewModelsRoot.dll" to the output folder directly, but it will not be updated when you change the code.
I've often found this error when the project target framework was set to "Client Profile" (this was set by default on VS2010, IIRC), if this is the case, try changing it to 3.5 or 4.0.
I need to resolve an assembly and type at runtime and I need to find the fully qualified type name. For some reason I cannot get it right, as I keep get an exception saying it cannot find the type specified.
The app.config file, in which the assembly to look for is defined, looks like this:
<configSections>
<section name="modules" type="Microsoft.Practices.Composite.Modularity.ModulesConfigurationSection, Microsoft.Practices.Composite"/>
</configSections>
<modules>
<module assemblyFile="G:\Data\Visual Studio 2008\Projects\Race Management System.Shell\ConfigurationModularity\bin\Debug\Modules\Driver.Data.Module.dll" moduleType="Driver.Data.Module.DriverDataModule, DriverDataModule" moduleName="Driver.Data.Module.DriverDataModule"></module>
</modules>
The assembly is called: Driver.Data.Module
Namespace in assembly is: Driver.Data.Module
and type name is: DriverDataModule, and this is also the name of the .cs file.
I cannot seem to find how to specify the name correctly in the xml file. Can somebody help me with the fully qualified type name?
This is for a Composite WPF application.
Thanx!
Try Driver.Data.Module.DriverDataModule, Driver.Data.Module.
You can also find the full assembly-qualified name of your type by instantiating an object of that type and examining the AssemblyQualifiedName property of its Type:
DriverDataModule module = new DriverDataModule();
string fullyQualifiedName = module.GetType().AssemblyQualifiedName;
What error do you get? If you're having a hard time getting a full error message out of the app, and you think your app is having problems loading the assembly itself, you can use the fuslogvw tool to log full details to disk.
It's worth also opening the assembly in Reflector to double-check the assembly's full name (displayed on the bottom-left of the window when you open Reflector), and to check that the type is in fact defined in the namespace you think it is.