none
[UWP][C#] AccessViolationException when navigating froma another assembly

    Question

  • Hello,

    in my app I have some a different assembly which is loaded with Assembly.Load (I've got my reasons to do this). However, the problem is that I defined a page inside of that assembly and when I try to navigate to the Page defined by that assembly (I got a type reference so I don't have to know the exact type) then a AccessViolationException is thrown. I wonder why I get this exeption and searching in the internet does not really help to solve that problem.

    Does anyone know why the exception occurs and how to get rid of it? Is it not possible to define pages in a class library and navigate to them? If yes, then which use has Assembly.Load because I want to use it for some kind of plugin system where some assemblies on should get loaded when a special condition is fulfilled (that's why I cannot reference the type directly as don't know it from my main app)

    Thanks for help

    Friday, September 25, 2015 2:39 PM

All replies

  • Hello internetfreak,

    According to MSDN document:

    Usually, this exception would be caused by an access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been allocated, or to which it does not have access, and consider you are using C#, it also may be caused by the common language runtime are not handled by the catch statement in a structured exception handler if the exception occurs outside of the memory reserved by the common language runtime.

    >>Does anyone know why the exception occurs and how to get rid of it? Is it not possible to define pages in a class library and navigate to them?

    Personally, I do not have a try with such a scenario. Could you please share a demo project with us? We could help check it to see if we could identity the reason. Also, as it suggests in the document, to apply the HandleProcessCorruptedStateExceptionsAttribute attribute to the method in which the exception is thrown to handle such an AccessViolationException exception.

    Regards.


    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.

    Monday, September 28, 2015 9:17 AM
  • Hello Fred,

    unfortunately it seems that my plan will not work as WinRT does load the assemblies into an protected memory area from where I cannot give the command to my frame to navigate. I will provide a sample project in the next few days where you can see what I want to try, maybe you can still help me otherwise I need to find another way to achieve my plans
    Tuesday, September 29, 2015 8:51 PM
  • After some more search I think this is not really possible. I will only include extra classes in my plugins, for all other stuff I will find some workaround, maybe I will create a dynamic page which could be extended with my plugins.
    Sunday, October 4, 2015 9:25 PM
  • This is the exact issue I'm having as well.  As an example:

    So I have two assemblies ProjectA that contains my Application. And ProjectB that contains Pages and other classes.

    When attempting to navigate to a page in Project B. Like:

    // Earlier
    RootFrame = new Frame();
    Window.Current.Content = RootFrame;
    
    //Relevant Code
    RootFrame.Navigate(Type.GetType("ProjectB.MyDisplay,ProjectB"));

    Doing this gives me the following error:

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    Tuesday, September 20, 2016 3:03 PM
  • i ran into the same problem, but this blogpost helped me out. It mentioned that this problem can occur if you have no other XAML page in the main assembly. Just add a DummyPage.xaml or another name you choose. No need to reference or use it, but it will make the exception disappear. There must be a good reason for it, but I have no clue what it is at the moment.

    Martin

    Saturday, May 12, 2018 8:35 PM