locked
[UWP]Navigating to a Page in a non-referenced dll RRS feed

  • Question

  • In a Windows 10 Universal app I am able to use Frame Navigate to navigate to a page in dll as long as that dll is referenced in the app. However, if I include a dll and other related files in the app package but it is not referenced in the app then when I try to navigate to that page I get the following exception.

    System.AccessViolationException was unhandled
      HResult=-2147467261
      Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
      Source=Windows.UI.Xaml
      StackTrace:
           at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType)
           at UwpModularityExperiment.MainPage.SelectionListBox_SelectionChanged(Object sender, SelectionChangedEventArgs e)

    The assembly containing the page can be loaded and an instance of the page can be created but the page cannot be navigated to by the Frame in the app.

    What am I missing to make this work?


    • Edited by Barry Wang Wednesday, December 9, 2015 11:44 AM title tag
    Tuesday, December 8, 2015 9:28 PM

Answers

  • Hello Terry,

    >> It seems like it should be possible.

    I agree. But I cannot find a documented way to know "what the reference is doing".

    Maybe we are missing AppDomin here? I'm also lack of document to do this here.

    Or I think you can consider this way:

    XamlReader.Load method

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Barry Wang Monday, December 21, 2015 8:46 AM
    • Marked as answer by Barry Wang Wednesday, December 23, 2015 2:47 AM
    Monday, December 14, 2015 3:07 AM

All replies

  • Hello TerryYoung,

    What have you done here? Use reflection? What about share me your code? Let me check whether I can reproduce this issue from my side. Sounds like it can work since you've already add the dll in the package.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 9, 2015 1:33 PM
  • Hi Barry,

    The app MainPage displays a list in a SplitView pane and the contents of the selected page from the list in the SplitView Content containing a Frame.

    The list is initialized as follows. The strings would normally be obtained from configuration but are hard coded for testing.

    AssemblyName dynamicAssemblyName = new AssemblyName(); dynamicAssemblyName.Name = "UwpModularityExperimentExternal2"; Assembly dynamicAssembly = Assembly.Load(dynamicAssemblyName); foreach (Type type in dynamicAssembly.ExportedTypes) { if (type.Name.Equals("SelectionX")) { selectionXType = type; break; } } Selections = new List<SelectionItem> { new SelectionItem() {Name="Selection A", Type=typeof(SelectionA) }, ... new SelectionItem() {Name="Selection X", Type=selectionXType } };

    When an item is selected in the list the corresponding page is displayed as follows.

    private void SelectionListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ListBox selectionListBox = sender as ListBox;
        SelectionItem item = selectionListBox.SelectedItem as SelectionItem;
        if (item != null)
                SelectionFrame.Navigate(item.Type);
    }
    
    Terry

    Wednesday, December 9, 2015 4:07 PM
  • Hello Terry,

    I use some simple code and I can reproduce this issue:

    It seems this is actually not able to be accessed from our side. Do you have any specific reason for this kind of requirement.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 11, 2015 9:19 AM
  • Some of our desktop products require the ability for our customer to configure an application from modules including modules the customer has created.

    I wanted to see if a UWP app could offer a similar capability. It seems like it should be possible.

    If a reference to the dll is added to the app then all works. Is there a way to accomplish what the reference is doing without having to add a reference?

    Terry

    Friday, December 11, 2015 2:15 PM
  • Hello Terry,

    >> It seems like it should be possible.

    I agree. But I cannot find a documented way to know "what the reference is doing".

    Maybe we are missing AppDomin here? I'm also lack of document to do this here.

    Or I think you can consider this way:

    XamlReader.Load method

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Barry Wang Monday, December 21, 2015 8:46 AM
    • Marked as answer by Barry Wang Wednesday, December 23, 2015 2:47 AM
    Monday, December 14, 2015 3:07 AM
  • I'm running into this (or a similar) issue as well. Using UAP10.

    Given Two Assemblies, the first contains the main application. The second Assembly contains a basic Page.

    The First Assembly does not directly reference the second assembly. Other objects from the second assembly are able to be created using Activator.CreateInstance.  However, using Frame.Navigate(TypeOfSecondAssemblyPage), produces the "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." error. 

    Friday, September 16, 2016 1:06 AM
  • This is what I found, which may be different.

    1. I create a UWP app (project1), add a UWP library (project2), and project1 reference project2.
    2. In the library add a page. In project1 app.xaml.cs, change rootFrame.Navigate(typeof(MainPage), e.Arguments) to rootFrame.Navigate(typeof(Project2.MainPage), e.Arguments) so that it navigate to the page in project2.
    3. Run and got the exception.

    Workaround:

    In project1 app.xaml, add the following to create an instance of the page (as a resource, which doesn't matter):

        xmlns:project2="using:project2"

        <Application.Resources>
            <ResourceDictionary>
                <project2:MainPage x:Key="MainPage"></view:MainPage>
            </ResourceDictionary>
        </Application.Resources>

    Run the app, it works.

    So looks like the reason for the exception was caused by the page in the other project is not instantiated yet. If you instantiate it in app.xaml, it works.

    • Proposed as answer by Med Ziane Thursday, January 12, 2017 3:05 PM
    Monday, October 17, 2016 5:37 PM
  • The page needs to be injected at runtime. The creator of project 2 will not have access to compile against project 1. 
    Monday, October 17, 2016 5:48 PM
  • The problem is that the developer does not have access to project1. There needs to be a way to instantiate the page from project 2, without being able to modify code in project 1. So project1 needs to be able to instantiate an arbitrary page at runtime using reflection. 
    Thursday, January 12, 2017 4:11 PM