Srivastava
Srivastava

Reputation: 3578

Type or namespace name could not be found

I am working on a desktop application for which I need to load the assembly and execute it in different appdomain.

For loading the assembly I have written as:

public static DataTable GetAllPluginNames(string[] args)
{
        SqlConnection sConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

        //ToDo: create a table of one column - only name of the plugin and return that.
        //ToDo: refer the code from MFAssemblyValidator from MFPluggerService.

        DataTable dt = null;
        List<string> assemblyNames = new List<string>();
        Assembly[] oAssemblies = new Assembly[args.Length];

        for (int assemblyCount = 0; assemblyCount < args.Length; assemblyCount++)
        {
            oAssemblies[assemblyCount] = Assembly.LoadFile(args[assemblyCount]);

            try
            {
                foreach (Type oType in oAssemblies[assemblyCount].GetTypes())
                {
                    // Check whether class is inheriting from IMFDBAnalyserPlugin.
                    if (oType.GetInterface("IMFDBAnalyserPlugin") == typeof(IMFDBAnalyserPlugin))
                    {
                        assemblyNames.Add(args[assemblyCount].Substring(args[assemblyCount].LastIndexOf("\\") + 1));
                    }
                }
                 return dt;
            }
            catch (Exception ex) 
            {
                lblError.Text = "ERROR";
            }


        // Passing data one application domain to another.
        AppDomain.CurrentDomain.SetData("AssemblyNames", assemblyNames.ToArray());
      }
}

but typeof(IMFDBAnalyserPlugin)) is showing a namespace error.

IMFDBAnalyserPlugin is the interface class in my program as:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MFDBAnalyser
{
    public interface IMFDBAnalyserPlugin
    {
        void ExecutePlugin();
    }
}

What might be the problem?? Can anyone help me out!!

Upvotes: 1

Views: 9363

Answers (4)

Mutation Person
Mutation Person

Reputation: 30488

This utterly baffled me for some time. I added the references and code then when I tried to compile the project, it inexplicably lost knowledge of the references, whilst still displaying them in the solution explorer.

In the end, I navigated to the project properties and changed theb 'Target Framework' field from '.Net Framework 4 Client Profile' to '.Net Framework 4'

This fixed the isse.

Upvotes: 1

user557951
user557951

Reputation: 41

Quick Solution I: In the project properties, change the Dotnet framework from 2.0,3.0 or 3.5 to 4, compile and run!

Quick Solution II: Check the .cs properties – change from content to compile.

More details can be found here.

Upvotes: 4

Cody Gray
Cody Gray

Reputation: 244682

Is the GetAllPluginNames method located under the same namespace as the interface IMFDBAnalyserPlugin?

If not, you either need to add a using directive to the top of the code file that contains the GetAllPluginNames method, or fully qualify the interface reference with its namespace, i.e.

if (oType.GetInterface("MFDBAnalyser.IMFDBAnalyserPlugin") == typeof(MFDBAnalyser.IMFDBAnalyserPlugin))

Upvotes: 1

Dialecticus
Dialecticus

Reputation: 16761

try typeof(MFDBAnalyser.IMFDBAnalyserPlugin)

Upvotes: 0

Related Questions