Forms solution, InternalsVisibleTo attribute in AssemblyInfo.cs, still can't access in iOS project.

WinterCloudWinterCloud GBMember ✭✭✭
edited January 2017 in Xamarin.Forms

Endless weird things.

In Visual studio 2015, iOS project can not access internals in Forms portable project. Solution can not build.

Environment:
VS 2015,
Xamarin 4.2.2.6
Xamarin.iOS 10.3.1.7

Repro:
Visual Studio 2015, start a new Xamarin Forms solution.
In Portable project:
Create a static class with a static string field.
Create InternalsVisibleTo attribute in Assembly.cs.
In iOS project:
Simple call that static class just created, error showing "classname is inaccessible due to its protection level". Project can not build with the same error msg.

Anyone has the same issue? Any suggestions please? Thanks in advance.

Btw, I have tried restart VS multi times, delete recreate project multi times.

App1\App.cs

internal static class Helper
{
    internal const string name = "";
}
public class App : Application
{
    public App()
    {
        // The root page of your application
        MainPage = new ContentPage
        {
            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Children = {
                    new Label {
                        HorizontalTextAlignment = TextAlignment.Center,
                        Text = "Welcome to Xamarin Forms!"
                    }
                }
            }
        };
    }

    protected override void OnStart()
    {
        // Handle when your app starts
    }

    protected override void OnSleep()
    {
        // Handle when your app sleeps
    }

    protected override void OnResume()
    {
        // Handle when your app resumes
    }
}

App1\Properties\AssemblyInfo.cs

// Just in case I'm missing something.
[assembly: InternalsVisibleTo( "App1.iOS" )]
[assembly: InternalsVisibleTo( "App1" )]
[assembly: InternalsVisibleTo( "iOS" )]

App1.iOS\Main.cs

public class Application
{
    // This is the main entry point of the application.
    static void Main( string[] args )
    {
        // if you want to use a different Application Delegate class from "AppDelegate"
        // you can specify it here.
        UIApplication.Main( args, null, "AppDelegate" );

        var a = Helper.name;  // Error here.
    }
}
Tagged:

Best Answer

Answers

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @WinterCloud,

    That all seems right to me... I can't reproduce it when I add similar code here. Can you .zip up a project and attach it? Make sure to delete the /packages folder and any /bin and /obj directories first to reduce the size.

  • WinterCloudWinterCloud GBMember ✭✭✭

    @JohnMiller

    Sure, hang on pls.

  • WinterCloudWinterCloud GBMember ✭✭✭

    @JohnMiller

    Thanks for the quick reply. here is the solution.

    App1.7z 204.3K
Sign In or Register to comment.