locked
How to eliminate erroneous error messages RRS feed

  • Question

  • I have a number of converters in my app but as you can see from the image below (see the converters I've highlighted in yellow), VS doesn't think they exist.  The app compiles and runs but throws an exception whenever one of the converters is used.

    Any suggestions on what I'm doing wrong.



    • Edited by SezMe Thursday, July 5, 2018 7:22 AM
    Thursday, July 5, 2018 6:48 AM

Answers

  • Well, I figured out how to solve the problem but I don't know why the solution words.  I changed the "Target CPU" property on the Project property pages from "x64" to "Any CPU" then did a build.  That resolved the error.  Then I changed it back to "x64' and did another build and still had no error messages.

    I guess it's true: Visual Studio works in mysterious ways.

    • Marked as answer by SezMe Saturday, July 7, 2018 5:21 PM
    Saturday, July 7, 2018 5:21 PM

All replies

  • I'm guessing you are referring to those converters in XAML?

    Have you checked the namespaces of the converters and ensured you have pulled in those namespaces into the XAML?

    E.g (This example stolen from https://www.wpftutorial.net/valueconverters.html):

    <Window x:Class="VirtualControlDemo.Window1"
        ...
        xmlns:l="clr-namespace:VirtualControlDemo"
        ...>
        <Window.Resources>
            <l:BoolToVisibilityConverter x:Key="converter" />
        </Window.Resources>
        <Grid>
            <Button Visibility="{Binding HasFunction, 
                Converter={StaticResource converter}}" />
        </Grid>
    </Window>

    Thursday, July 5, 2018 8:06 AM
  • Yes, I refer to them in XAML and I believe I do that correctly.  For example, I have the following in my XAML:

    <Window.Resources>
        xmlns:self="clr-namespace:HIPPO"
        .....
        <self:DateConverter x:Key="conDate" />
        <self:EmailConverter x:Key="conEmail" />
        <self:HardCopyConverter x:Key="conHardCopy" />
        <self:PhoneConverter x:Key="conPhone" /> 
        <self:ZipCodeConverter x:Key="conZip" />
        .......
    </Window.Resources>
    and all of the lines after the self declaration have the squiggly underline that shows they are wrong but, as I indicated, the app compiles and runs until any of the converters are used.
    Thursday, July 5, 2018 7:23 PM
  • Hi SezMe,

    According to your description and your code, you refer these converter to Window.Resource, I think you need to refer this namespace to Window, and add this to Window.resource, then you can use this resource by key in other component.

     

    When you are writing your wpf code corrrectly, but VS still tell that "The name ABCDE does not exist in the namespace clr-namespace:ABC". you can totally build your project successfully, there is only a small inconvenience because you can not see the UI designing. You can rebuild your application, It can solve your problem.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, July 6, 2018 3:36 AM
  • As Cherry Bu has pointed out, you have the xmlns in the wrong part.

    This is an attribute and so needs to go inside a tag. And since namespaces are usually referred to all over a Window they are normally placed inside the top level <Window> tag. See my previous example or Cherry Bu's example code.

    Friday, July 6, 2018 8:22 AM
  • I goofed.  My apologizes.  I did not write my example correctly.  The definition of "self" is set along with the other namespace definitions, NOT within the Windows Resources.  (I actually have this:

     .....
    xmlns:self="clr-namespace:HIPPO"
     .....
    <Window.Resources>
        <self:DateConverter x:Key="conDate" />
        <self:EmailConverter x:Key="conEmail" />
        <self:HardCopyConverter x:Key="conHardCopy" />
        <self:PhoneConverter x:Key="conPhone" /> 
        <self:ZipCodeConverter x:Key="conZip" />
        .......
    </Window.Resources>
     .....

    Again, I'm sorry for the misleading snippet.  If it was as I originally wrote, it wouldn't compile or run.

    Friday, July 6, 2018 4:32 PM
  • Well, I figured out how to solve the problem but I don't know why the solution words.  I changed the "Target CPU" property on the Project property pages from "x64" to "Any CPU" then did a build.  That resolved the error.  Then I changed it back to "x64' and did another build and still had no error messages.

    I guess it's true: Visual Studio works in mysterious ways.

    • Marked as answer by SezMe Saturday, July 7, 2018 5:21 PM
    Saturday, July 7, 2018 5:21 PM