Type namespace issue in C# - c#

I have third party .Net assembly lets say ThridParty.dll which uses type "dotnet-namespace.dotnet-type from .Net assembly dotnetassembly.dll.
Now in new version of dotnetassembly.dll "dotnet-type" which was earlier in dotnet-namespace has been moved to new namespace lets say new-dotnet-namespace. Fully qualified name of dotnet-type has become new-dotnet-namespace.dotnet-type.
Now my question is, Is there any way I can tell runtime to look for type dotnet-type in new namespace i.e. new-dotnet-namespace instead of old namespace i.e. dotnet-namespace?
I know we can do use assembly redirection when we want to point new version of assembly but is it possible to redirect types within same assembly but to different namespace?
I don't have option to get new version of thridparty.dll which uses type from new namespace.

No, there is nothing in .Net Framework to redirect one type to another.
Note that namespace is just syntactic sugar to makes names shorter in source code, for .Net itself namespace is just part of the type name - so your question is essentially "can I point on type to another".
Solutions:
recompile
build proxy assembly
rewrite IL to point to new types.

How about:
public Type FindType(string typeName, string assemblyName)
{
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(a => a.GetName().Name == assemblyName);
return assembly != null ? assembly.GetTypes().SingleOrDefault(t => t.Name == typeName) : null;
}
You would call this:
Type dotNetType = FindType("dotnet-type", "dotnetassembly");
This way you are independent of the type namespace.
As a side note, if you have two types with the same name in that assembly, this method will simply not work because it won't be able to know which type to return (in fact, it'll throw an exception). You can change SingleOrDefault to FirstOrDefault and make it return the first occurence.
Of course you'd lose all the compiler-time advantages, since you'll be looking up the type at runtime.

Related

Why does Type.GetType not return a Type when given an input the exact same as typof(X).GetFullName? [duplicate]

This code:
Type.GetType("namespace.a.b.ClassName")
returns null.
I have in the usings:
using namespace.a.b;
The type exists, it's in a different class library, and I need to get it by it's name given as string.
Type.GetType("namespace.qualified.TypeName") only works when the type is found in either mscorlib.dll or the currently executing assembly.
If neither of those things are true, you'll need an assembly-qualified name:
Type.GetType("namespace.qualified.TypeName, Assembly.Name")
You can also get the type without assembly qualified name but with the dll name also, for example:
Type myClassType = Type.GetType("TypeName,DllName");
I had the same situation and it worked for me. I needed an object of type "DataModel.QueueObject" and had a reference to "DataModel" so I got the type as follows:
Type type = Type.GetType("DataModel.QueueObject,DataModel");
The second string after the comma is the reference name (dll name).
Try this method.
public static Type GetType(string typeName)
{
var type = Type.GetType(typeName);
if (type != null) return type;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
type = a.GetType(typeName);
if (type != null)
return type;
}
return null;
}
If the assembly is part of the build of an ASP.NET application, you can use the BuildManager class:
using System.Web.Compilation
...
BuildManager.GetType(typeName, false);
Dictionary<string, Type> typeCache;
...
public static bool TryFindType(string typeName, out Type t) {
lock (typeCache) {
if (!typeCache.TryGetValue(typeName, out t)) {
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) {
t = a.GetType(typeName);
if (t != null)
break;
}
typeCache[typeName] = t; // perhaps null
}
}
return t != null;
}
if your class is not in current assambly you must give qualifiedName and this code shows how to get qualifiedname of class
string qualifiedName = typeof(YourClass).AssemblyQualifiedName;
and then you can get type with qualifiedName
Type elementType = Type.GetType(qualifiedName);
As Type.GetType(String) need the Type.AssemblyQualifiedName you should use Assembly.CreateQualifiedName(String, String).
string typeName = "MyNamespace.MyClass"; // Type.FullName
string assemblyName = "MyAssemblyName"; // MyAssembly.FullName or MyAssembly.GetName().Name
string assemblyQualifiedName = Assembly.CreateQualifiedName(assemblyName , typeName);
Type myClassType = Type.GetType(assemblyQualifiedName);
The Version, Culture and PublicKeyToken are not required for assemblyName that's why you can use MyAssembly.GetName().Name.
About Type.GetType(String) :
If the type is in the currently executing
assembly or in Mscorlib.dll, it is sufficient to supply the type name
qualified by its namespace.
When I have only the class name I use this:
Type obj = AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes()).Where(t => String.Equals(t.Name, _viewModelName, StringComparison.Ordinal)).First();
If it's a nested Type, you might be forgetting to transform a . to a +
Regardless, typeof( T).FullName will tell you what you should be saying
EDIT: BTW the usings (as I'm sure you know) are only directives to the compiler at compile time and cannot thus have any impact on the API call's success. (If you had project or assembly references, that could potentially have had influence - hence the information isnt useless, it just takes some filtering...)
I am opening user controls depending on what user controls the user have access to specified in a database. So I used this method to get the TypeName...
Dim strType As String = GetType(Namespace.ClassName).AssemblyQualifiedName.ToString
Dim obj As UserControl = Activator.CreateInstance(Type.GetType(strType))
So now one can use the value returned in strType to create an instance of that object.
If the assembly is referenced and the Class visible :
typeof(namespace.a.b.ClassName)
GetType returns null because the type is not found, with typeof, the compiler may help you to find out the error.
Try using the full type name that includes the assembly info, for example:
string typeName = #"MyCompany.MyApp.MyDomain.MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
Type myClassType = Type.GetType(typeName);
I had the same situation when I was using only the the namesspace.classname to get the type of a class in a different assembly and it would not work. Only worked when I included the assembly info in my type string as shown above.
Make sure that the comma is directly after the fully qualified name
typeof(namespace.a.b.ClassName, AssemblyName)
As this wont work
typeof(namespace.a.b.ClassName ,AssemblyName)
I was stumped for a few days on this one
For me, a "+" was the key!
This is my class(it is a nested one) :
namespace PortalServices
{
public class PortalManagement : WebService
{
public class Merchant
{}
}
}
and this line of code worked:
Type type = Type.GetType("PortalServices.PortalManagement+Merchant");
This solution above seems to be the best to me, but it didn't work for me, so I did it as follows:
AssemblyName assemblyName = AssemblyName.GetAssemblyName(HttpContext.Current.Server.MapPath("~\\Bin\\AnotherAssembly.dll"));
string typeAssemblyQualifiedName = string.Join(", ", "MyNamespace.MyType", assemblyName.FullName);
Type myType = Type.GetType(typeAssemblyQualifiedName);
The precondition is that you know the path of the assembly. In my case I know it because this is an assembly built from another internal project and its included in our project's bin folder.
In case it matters I am using Visual Studio 2013, my target .NET is 4.0. This is an ASP.NET project, so I am getting absolute path via HttpContext. However, absolute path is not a requirement as it seems from MSDN on AssemblyQualifiedNames
I cheated. Since the types I want to create (by name) are all in In a dll I control, I just put a static method in the dll in the assembly that takes a simple name, and calls type.GetType from that context and returns the result.
The original purpose was so that the type could be specified by name in configuration data. I've since change the code so that the user specified a format to process. The format handler classes implement a interface that determines if the type can parse the specified format. I then use reflection to find types that implement the interface, and find one that handles the format. So now the configuration specifies a format name, a not a specific type. The reflection code can look at adjacent dlls and load, them so I have a sort poor man's plug-in architecture.
Very late reply, but if anyone is dealing with this a decade later:
There is a very, very small chance that your class in Visual Studio has a Build Action set to "Content" instead of "Compile".
Click on your class in Solution Explorer, then look at the properties.
Check that Build Action is "Compile", not "Content".

Are two classes in same namespace & project also in the same executing assembly?

I am asking the question in the title because this works:
FooBar fooBar = new FooBar();
It hits the constructor in FooBar, etc. But this returns null:
Type type = Type.GetType("FooBar");
Both FooBar and the class from which I am trying to do this are in the same namespace, the same project, etc.
I've looked over this thread:
Type.GetType("namespace.a.b.ClassName") returns null
According to that accepted answer (and some others), this "only works when the type is found in either mscorlib.dll or the currently executing assembly."
If the two classes are in the same namespace and the same project (ie: same .dll) would that not make the same executing assembly?
What am I doing wrong?
Even though it's in the same assembly and namespace, you still need to provide the namespace. It's just the assembly qualified name you can skip.
Type type = Type.GetType("YourNamespace.FooBar");
From the documentation:
typeName. The assembly-qualified name of the type to get. See AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace.
So you still need to provide the namespace, e.g.
var type = Type.GetType("MyNamespace.FooBar");
If you really don't want to provide the namespace for some reason, as an alternative, you could just as easily do something like this:
var type = System.Reflection.Assembly.GetExecutingAssembly()
.GetTypes()
.Where(a => a.Name == "FooBar");

Type.GetInterface returning null

My issue is that I am getting different results to our older DLLs from history, when very little has changed and I don't under how the changes are relevant to the error shown.
This is part of a method, in our SecurityPluginServices.dll module, which essentially added plugins to a list so they can be utilised by the main program.
It gets all the DLLs in a set folder, then for each it runs through the code below.
private void AddPlugin(string FileName, LoggingUtilities.Source source)
{
//Create a new assembly from the plugin file we're adding..
Assembly pluginAssembly = Assembly.LoadFrom(FileName);
try
{
//Next we'll loop through all the Types found in the assembly
foreach (Type pluginType in pluginAssembly.GetTypes())
{
if (pluginType.IsPublic) //Only look at public types
{
if (!pluginType.IsAbstract) //Only look at non-abstract types
{
//Gets a type object of the interface we need the plugins to match
Type typeInterface = pluginType.GetInterface("SecurityInterface.ISecurityPlugin", true);
//Make sure the interface we want to use actually exists
if (typeInterface != null)
{
// Do work here
}
typeInterface = null; //Mr. Clean
}
}
}
pluginAssembly = null; //more cleanup
}
catch (ReflectionTypeLoadException ex1)
{
Console.WriteLine(ex1.Message);
}
catch (Exception ex2)
{
Console.WriteLine(ex2.Message);
}
}
The issue I am having is that everytime it gets to Type typeInterface = pluginType.GetInterface("SecurityInterface.ISecurityPlugin", true); it always returns null.
The plugins I need to load are for NTLM and LDAP and they have changed very little in many versions and only a couple of extra properties and methods have been added, nothing to do with interfaces that the implement.
I've opened up a copy of the newer plugin DLL and one of the older ones in ILDASM and they both seem to contain the same information regarding the SecurityInterface.ISecurityPlugin that the .GetInterface method is seeking.
Newer LdapSecurity
Older LdapSecurity
Suggestion:
Type typeInterface = pluginType.GetInterface("SecurityInterface.ISecurityPlugin", true);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Change this to a fully-qualified type name, i.e. one that includes the assembly containing your interface type.
(If you're now saying that you've got two different types by the same name, in two different assemblies, and therefore cannot include one definite assembly name, this may well be the likely cause of your issue.)
Explanation:
My other answer led me to a suspicion of what could cause your issue. Generally speaking, typeof(T) would force you to add an assembly reference to your project for the assembly that contains T. Otherwise, compilation will fail. On the other hand, textual mentions of type names such as Type.GetType("T") do not enforce a compile-time assembly reference... but they still have to be resolved to a type instance at run-time. So if you omit the assembly name, you need to keep in mind how .NET will map T to a specific assembly.
Back to your issue. First, let's note that you are not using a fully-qualified type name:
Type typeInterface = pluginType.GetInterface("SecurityInterface.ISecurityPlugin", true);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You specify only the namespace and the type name, but not the assembly containing your interface type. Could it be that the interface type is defined more than once, i.e. in different assemblies, and your mention of that type name is resolved to type in the wrong assembly?
Let's briefly look at the MSDN documentation for Type.GetType(string) method, which describes the string parameter as follows:
"The assembly-qualified name of the type to get. […] If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace."
What if the same applies to the Type.GetInterface(string, bool) method which you're using? And what if your currently executing assembly does contain a type of that name? Then that is the type that pluginType will be checked against... but it might be a different ISecurityPlugin interface type (albeit equal in name) than the one your plug-in class actually implements.
Update: Please see my other answer first, which is likely more relevant.
If you want to check whether pluginType implements the ISecurityPlugin interface, you could instead perform this check:
typeof(SecurityInterface.ISecurityPlugin).IsAssignableFrom(pluginType)
If you don't reference the assembly containing ISecurityPlugin, you can replace the first part by Type.GetType("SecurityInterface.ISecurityPlugin").

Reflection C# - GetType() Returns Null [duplicate]

This code:
Type.GetType("namespace.a.b.ClassName")
returns null.
I have in the usings:
using namespace.a.b;
The type exists, it's in a different class library, and I need to get it by it's name given as string.
Type.GetType("namespace.qualified.TypeName") only works when the type is found in either mscorlib.dll or the currently executing assembly.
If neither of those things are true, you'll need an assembly-qualified name:
Type.GetType("namespace.qualified.TypeName, Assembly.Name")
You can also get the type without assembly qualified name but with the dll name also, for example:
Type myClassType = Type.GetType("TypeName,DllName");
I had the same situation and it worked for me. I needed an object of type "DataModel.QueueObject" and had a reference to "DataModel" so I got the type as follows:
Type type = Type.GetType("DataModel.QueueObject,DataModel");
The second string after the comma is the reference name (dll name).
Try this method.
public static Type GetType(string typeName)
{
var type = Type.GetType(typeName);
if (type != null) return type;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
type = a.GetType(typeName);
if (type != null)
return type;
}
return null;
}
If the assembly is part of the build of an ASP.NET application, you can use the BuildManager class:
using System.Web.Compilation
...
BuildManager.GetType(typeName, false);
Dictionary<string, Type> typeCache;
...
public static bool TryFindType(string typeName, out Type t) {
lock (typeCache) {
if (!typeCache.TryGetValue(typeName, out t)) {
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) {
t = a.GetType(typeName);
if (t != null)
break;
}
typeCache[typeName] = t; // perhaps null
}
}
return t != null;
}
if your class is not in current assambly you must give qualifiedName and this code shows how to get qualifiedname of class
string qualifiedName = typeof(YourClass).AssemblyQualifiedName;
and then you can get type with qualifiedName
Type elementType = Type.GetType(qualifiedName);
As Type.GetType(String) need the Type.AssemblyQualifiedName you should use Assembly.CreateQualifiedName(String, String).
string typeName = "MyNamespace.MyClass"; // Type.FullName
string assemblyName = "MyAssemblyName"; // MyAssembly.FullName or MyAssembly.GetName().Name
string assemblyQualifiedName = Assembly.CreateQualifiedName(assemblyName , typeName);
Type myClassType = Type.GetType(assemblyQualifiedName);
The Version, Culture and PublicKeyToken are not required for assemblyName that's why you can use MyAssembly.GetName().Name.
About Type.GetType(String) :
If the type is in the currently executing
assembly or in Mscorlib.dll, it is sufficient to supply the type name
qualified by its namespace.
When I have only the class name I use this:
Type obj = AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes()).Where(t => String.Equals(t.Name, _viewModelName, StringComparison.Ordinal)).First();
If it's a nested Type, you might be forgetting to transform a . to a +
Regardless, typeof( T).FullName will tell you what you should be saying
EDIT: BTW the usings (as I'm sure you know) are only directives to the compiler at compile time and cannot thus have any impact on the API call's success. (If you had project or assembly references, that could potentially have had influence - hence the information isnt useless, it just takes some filtering...)
I am opening user controls depending on what user controls the user have access to specified in a database. So I used this method to get the TypeName...
Dim strType As String = GetType(Namespace.ClassName).AssemblyQualifiedName.ToString
Dim obj As UserControl = Activator.CreateInstance(Type.GetType(strType))
So now one can use the value returned in strType to create an instance of that object.
If the assembly is referenced and the Class visible :
typeof(namespace.a.b.ClassName)
GetType returns null because the type is not found, with typeof, the compiler may help you to find out the error.
Try using the full type name that includes the assembly info, for example:
string typeName = #"MyCompany.MyApp.MyDomain.MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
Type myClassType = Type.GetType(typeName);
I had the same situation when I was using only the the namesspace.classname to get the type of a class in a different assembly and it would not work. Only worked when I included the assembly info in my type string as shown above.
Make sure that the comma is directly after the fully qualified name
typeof(namespace.a.b.ClassName, AssemblyName)
As this wont work
typeof(namespace.a.b.ClassName ,AssemblyName)
I was stumped for a few days on this one
For me, a "+" was the key!
This is my class(it is a nested one) :
namespace PortalServices
{
public class PortalManagement : WebService
{
public class Merchant
{}
}
}
and this line of code worked:
Type type = Type.GetType("PortalServices.PortalManagement+Merchant");
This solution above seems to be the best to me, but it didn't work for me, so I did it as follows:
AssemblyName assemblyName = AssemblyName.GetAssemblyName(HttpContext.Current.Server.MapPath("~\\Bin\\AnotherAssembly.dll"));
string typeAssemblyQualifiedName = string.Join(", ", "MyNamespace.MyType", assemblyName.FullName);
Type myType = Type.GetType(typeAssemblyQualifiedName);
The precondition is that you know the path of the assembly. In my case I know it because this is an assembly built from another internal project and its included in our project's bin folder.
In case it matters I am using Visual Studio 2013, my target .NET is 4.0. This is an ASP.NET project, so I am getting absolute path via HttpContext. However, absolute path is not a requirement as it seems from MSDN on AssemblyQualifiedNames
I cheated. Since the types I want to create (by name) are all in In a dll I control, I just put a static method in the dll in the assembly that takes a simple name, and calls type.GetType from that context and returns the result.
The original purpose was so that the type could be specified by name in configuration data. I've since change the code so that the user specified a format to process. The format handler classes implement a interface that determines if the type can parse the specified format. I then use reflection to find types that implement the interface, and find one that handles the format. So now the configuration specifies a format name, a not a specific type. The reflection code can look at adjacent dlls and load, them so I have a sort poor man's plug-in architecture.
Very late reply, but if anyone is dealing with this a decade later:
There is a very, very small chance that your class in Visual Studio has a Build Action set to "Content" instead of "Compile".
Click on your class in Solution Explorer, then look at the properties.
Check that Build Action is "Compile", not "Content".

Type.GetType("namespace.a.b.ClassName") returns null

This code:
Type.GetType("namespace.a.b.ClassName")
returns null.
I have in the usings:
using namespace.a.b;
The type exists, it's in a different class library, and I need to get it by it's name given as string.
Type.GetType("namespace.qualified.TypeName") only works when the type is found in either mscorlib.dll or the currently executing assembly.
If neither of those things are true, you'll need an assembly-qualified name:
Type.GetType("namespace.qualified.TypeName, Assembly.Name")
You can also get the type without assembly qualified name but with the dll name also, for example:
Type myClassType = Type.GetType("TypeName,DllName");
I had the same situation and it worked for me. I needed an object of type "DataModel.QueueObject" and had a reference to "DataModel" so I got the type as follows:
Type type = Type.GetType("DataModel.QueueObject,DataModel");
The second string after the comma is the reference name (dll name).
Try this method.
public static Type GetType(string typeName)
{
var type = Type.GetType(typeName);
if (type != null) return type;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
type = a.GetType(typeName);
if (type != null)
return type;
}
return null;
}
If the assembly is part of the build of an ASP.NET application, you can use the BuildManager class:
using System.Web.Compilation
...
BuildManager.GetType(typeName, false);
Dictionary<string, Type> typeCache;
...
public static bool TryFindType(string typeName, out Type t) {
lock (typeCache) {
if (!typeCache.TryGetValue(typeName, out t)) {
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) {
t = a.GetType(typeName);
if (t != null)
break;
}
typeCache[typeName] = t; // perhaps null
}
}
return t != null;
}
if your class is not in current assambly you must give qualifiedName and this code shows how to get qualifiedname of class
string qualifiedName = typeof(YourClass).AssemblyQualifiedName;
and then you can get type with qualifiedName
Type elementType = Type.GetType(qualifiedName);
As Type.GetType(String) need the Type.AssemblyQualifiedName you should use Assembly.CreateQualifiedName(String, String).
string typeName = "MyNamespace.MyClass"; // Type.FullName
string assemblyName = "MyAssemblyName"; // MyAssembly.FullName or MyAssembly.GetName().Name
string assemblyQualifiedName = Assembly.CreateQualifiedName(assemblyName , typeName);
Type myClassType = Type.GetType(assemblyQualifiedName);
The Version, Culture and PublicKeyToken are not required for assemblyName that's why you can use MyAssembly.GetName().Name.
About Type.GetType(String) :
If the type is in the currently executing
assembly or in Mscorlib.dll, it is sufficient to supply the type name
qualified by its namespace.
When I have only the class name I use this:
Type obj = AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes()).Where(t => String.Equals(t.Name, _viewModelName, StringComparison.Ordinal)).First();
If it's a nested Type, you might be forgetting to transform a . to a +
Regardless, typeof( T).FullName will tell you what you should be saying
EDIT: BTW the usings (as I'm sure you know) are only directives to the compiler at compile time and cannot thus have any impact on the API call's success. (If you had project or assembly references, that could potentially have had influence - hence the information isnt useless, it just takes some filtering...)
I am opening user controls depending on what user controls the user have access to specified in a database. So I used this method to get the TypeName...
Dim strType As String = GetType(Namespace.ClassName).AssemblyQualifiedName.ToString
Dim obj As UserControl = Activator.CreateInstance(Type.GetType(strType))
So now one can use the value returned in strType to create an instance of that object.
If the assembly is referenced and the Class visible :
typeof(namespace.a.b.ClassName)
GetType returns null because the type is not found, with typeof, the compiler may help you to find out the error.
Try using the full type name that includes the assembly info, for example:
string typeName = #"MyCompany.MyApp.MyDomain.MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
Type myClassType = Type.GetType(typeName);
I had the same situation when I was using only the the namesspace.classname to get the type of a class in a different assembly and it would not work. Only worked when I included the assembly info in my type string as shown above.
Make sure that the comma is directly after the fully qualified name
typeof(namespace.a.b.ClassName, AssemblyName)
As this wont work
typeof(namespace.a.b.ClassName ,AssemblyName)
I was stumped for a few days on this one
For me, a "+" was the key!
This is my class(it is a nested one) :
namespace PortalServices
{
public class PortalManagement : WebService
{
public class Merchant
{}
}
}
and this line of code worked:
Type type = Type.GetType("PortalServices.PortalManagement+Merchant");
This solution above seems to be the best to me, but it didn't work for me, so I did it as follows:
AssemblyName assemblyName = AssemblyName.GetAssemblyName(HttpContext.Current.Server.MapPath("~\\Bin\\AnotherAssembly.dll"));
string typeAssemblyQualifiedName = string.Join(", ", "MyNamespace.MyType", assemblyName.FullName);
Type myType = Type.GetType(typeAssemblyQualifiedName);
The precondition is that you know the path of the assembly. In my case I know it because this is an assembly built from another internal project and its included in our project's bin folder.
In case it matters I am using Visual Studio 2013, my target .NET is 4.0. This is an ASP.NET project, so I am getting absolute path via HttpContext. However, absolute path is not a requirement as it seems from MSDN on AssemblyQualifiedNames
I cheated. Since the types I want to create (by name) are all in In a dll I control, I just put a static method in the dll in the assembly that takes a simple name, and calls type.GetType from that context and returns the result.
The original purpose was so that the type could be specified by name in configuration data. I've since change the code so that the user specified a format to process. The format handler classes implement a interface that determines if the type can parse the specified format. I then use reflection to find types that implement the interface, and find one that handles the format. So now the configuration specifies a format name, a not a specific type. The reflection code can look at adjacent dlls and load, them so I have a sort poor man's plug-in architecture.
Very late reply, but if anyone is dealing with this a decade later:
There is a very, very small chance that your class in Visual Studio has a Build Action set to "Content" instead of "Compile".
Click on your class in Solution Explorer, then look at the properties.
Check that Build Action is "Compile", not "Content".

Categories

Resources