Sharpnado.Shadows icon indicating copy to clipboard operation
Sharpnado.Shadows copied to clipboard

Error XFC0000: Cannot resolve type "shades:Shadows"

Open byme8 opened this issue 4 years ago • 14 comments

  • Sdk version: iOS 11/Android SDK 21
  • Xamarin.Forms: 4.8+

I installed the NuGet and added a shadow to a label, but got the next compilation error on build:

Error XFC0000: Cannot resolve type "shades:Shadows"

Steps to reproduce the behavior:

  1. Install nuget
  2. Add shadow namespace inside xaml
  3. Add shadow
  4. Try to build
  5. See error

Source of the page:


<?xml version="1.0" encoding="utf-8"?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:shades="http://sharpnado.com"
    x:Class="FailsInShadowsNuget.MainPage">
        <shades:Shadows>

            <Label FontSize="16" Padding="30,24,30,0">
                <Label.FormattedText>
                    <FormattedString>
                        <FormattedString.Spans>
                            <Span Text="Learn more at " />
                            <Span Text="https://aka.ms/xamarin-quickstart" FontAttributes="Bold" />
                        </FormattedString.Spans>
                    </FormattedString>
                </Label.FormattedText>
            </Label>
        </shades:Shadows>
</ContentPage>


byme8 avatar Oct 23 '20 08:10 byme8

Cannot replicate your issue

roubachof avatar Oct 23 '20 09:10 roubachof

@byme8 xmlns:shades="http://sharpnado.com" - change this to xmlns:shades="clr-namespace:Sharpnado.Shades;assembly=Sharpnado.Shadows"

themronion avatar Oct 23 '20 14:10 themronion

@themronion @byme8 how do you end up with this issue ? what IDE are you using (including precise version number) ?

roubachof avatar Oct 23 '20 18:10 roubachof

@roubachof I didn't even try to reproduce this issue, i just recommended the way i declare your plugin in xamls)

themronion avatar Oct 23 '20 18:10 themronion

it's the new namespace attribute, it should work this way in the latest version

roubachof avatar Oct 23 '20 18:10 roubachof

@themronion, with xmlns:shades="clr-namespace:Sharpnado.Shades;assembly=Sharpnado.Shadows" everything works as expected. Thanks!

@roubachof, I am using Microsoft Visual Studio Community 2019 Version 16.7.6. Also tested on VS For Mac 8.7.8.4 and got the same compilation error.

byme8 avatar Oct 23 '20 22:10 byme8

@roubachof

how do you end up with this issue?

I just installed the package and VS resolved namespace as xmlns:shades="http://sharpnado.com". That's all.

byme8 avatar Oct 23 '20 23:10 byme8

Which version of XF please ?

roubachof avatar Oct 26 '20 09:10 roubachof

Same for me on version XF 4.8.0.1451 the syntax only shows xmlns:shades="http://sharpnado.com" when implementing in XAML

conor-codes avatar Oct 26 '20 15:10 conor-codes

@dansiegel do you have an idea what is causing this. I could replicate it also. If you add as a nuget package and you add a Shadows, it is fine with the intellisense but you end up with a compile error...

roubachof avatar Oct 26 '20 15:10 roubachof

I'm not sure what's causing this, I know that you have your preferred prefix as sho but I tried changing the xmlns to sho and got the same result. It seems very similar to xamarin/xamarin.forms#8451 but I believe that has to do with a project not having been compiled yet which wouldn't quite be the same issue when you're working with a nuget...

Perhaps someone on the Forms team can provide some input here... to me it looks like a problem with XamlC @redth @StephaneDelcroix @pureween

dansiegel avatar Oct 26 '20 15:10 dansiegel

thanks to @pictos here is the deal:

To consume types from the custom namespace schema, the XAML compiler requires that there's a code reference from the assembly that consumes the types, to the assembly that defines the types. This can be accomplished by adding a class containing an Init method to the assembly that defines the types that will be consumed through XAML:

from: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/custom-namespace-schemas#consuming-a-custom-namespace-schema

So for the namespace schema to work, you need to call initializer from App.xaml.cs like this:

        public App()
        {
            InitializeComponent();

            Sharpnado.Shades.Initializer.Initialize(false);
            Sharpnado.Tabs.Initializer.Initialize(true, true);
        }

roubachof avatar Oct 29 '20 13:10 roubachof

Giving the control a name solved it for me, "x:name" to the shadow control

givod avatar Nov 03 '20 11:11 givod

Yup cause it generates a code reference to the assembly.

roubachof avatar Nov 03 '20 12:11 roubachof