Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7129821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:17:01+00:00 2026-05-28T11:17:01+00:00

At the moment, I have this code : var shellViewLibrary = Assembly.LoadFrom(Path.Combine(_DllsPath, _DllShellView)); IEnumerable<Type>

  • 0

At the moment, I have this code :

var shellViewLibrary = Assembly.LoadFrom(Path.Combine(_DllsPath, _DllShellView));
IEnumerable<Type> types = shellViewLibrary.GetTypes();

foreach (Type type in types)
{
    var typeIShellViewInterface = type.GetInterface(_NamespaceIShellView, false);
    if (typeIShellViewInterface != null)
    {
        //here
    }
}

The thing is that where I got //here I want to use Activator.CreateInstance to create an object whose type is type in a specific folder (that is outside the build folder)
I tried about 20 different things, most of them with this : http://msdn.microsoft.com/en-us/library/d133hta4.aspx
but none works…
The typical thing I tried is :

object MyObj = Activator.CreateInstance(shellViewLibrary.FullName, type.FullName);

or

object MyObj = Activator.CreateInstance(Path.Combine(_DllsPath, _DllShellView), type.FullName);

I always got different exception, the most common being :

XamlParseException

I feel like that I’m not using Activator.CreateInstance in the right way with 2 parameters. What should I do ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:17:02+00:00Added an answer on May 28, 2026 at 11:17 am

    Once you call this line

    var shellViewLibrary = Assembly.LoadFrom(Path.Combine(_DllsPath, _DllShellView)); 
    

    The assembly has been loaded in to memory. So long as you specify types correctly from this then you will be able to use Activator.CreateInstance to create the types. ie: It is not necessary to further specify where the type is.

    Regarding Activator, from MSDN the CreateInstance method can accept a System.Type. I would just use this method inside your if-statement:

    Activator.CreateInstance(Type type);
    

    What I would try to do to debug this is first create the type and then pass it in to CreateInstance. You may find that the Type creation itself is failing (due to unresolved assembly) or the instantiation of that type (due to exception in the constructor). At first glance your code here appears to be correct:

    foreach (Type type in types)      
    {          
        var typeIShellViewInterface = type.GetInterface(_NamespaceIShellView, false);          
        if (typeIShellViewInterface != null)          
        {              
            try
            {
                // I assume you are calling this line at the point marked 'here'. 
                // To debug the creation wrap in a try-catch and view the inner exceptions
                var result = Activator.CreateInstance(type);          
            }
            catch(Exception caught)
            {
                // When you hit this line, look at caught inner exceptions
                // I suspect you have a broken Xaml file inside WPF usercontrol
                // or Xaml resource dictionary used by type
                Debugger.Break();
            }
        }      
    }  
    

    In your question you specify that you are getting a XamlParseException. It sounds to me like the type in question is a UserControl (or otherwise refers to a WPF Xaml resource file) and there is an error in that Xaml file, i.e. nothing to do with your usage of Assembly.Load or Activator.CreateInstance.

    Could you try posting the inner exception(s) to get a better idea on what the problem is?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this at the moment, (I found the code on here). var exp
Let's say we have this code (forget about prototypes for a moment): function A(){
I have this code: ... function init() { getdata(); } var txt; function getdata()
I have this ajax call at the moment: $.ajax({ url: misc/sendPM.php, type: POST, data:
I have this script at the moment, which changes an image when a thumbnail
This is what I have at the moment. <h2>Information</h2>\n +<p>(.*)<br />|</p> ^ that is
I have two nested loop in XSL like this, at this moment I use
I have this code: function get_posts_tags($db, $start, $number_of_posts) { //query ); $sql -> bind_param('ii',$start,
I have the following code: public IDictionary<string, int> GetCountByDate(DateTime fromDate, DateTime toDate) { var
Let's say I have this code: class Score { public Update(int score) { update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.