Activator.CreateInstance: Failed to load type from assembly

I am trying to instantiate a class implemented in a .dll plugin in my project to open a type. I get this exception:

Failed to load the action type from the assembly 'SquidReports.DataCollector.Plugin.BES, Version = 1.0.0.0, Culture = Neutral, PublicKeyToken = null'.

This is the exact signature of the method I'm using: https://msdn.microsoft.com/en-us/library/d133hta4(v=vs.110).aspx

In other words, I'm trying to create an object based on the Assembly name and class name, for example:

object modelObject = Activator.CreateInstance((string)modelInfo.AssemblyName, (string)modelInfo.ModelName); 

It is important to note that I use the β€œshort” name of the assembly, not the β€œfull” name (including Version, Culture and PublicToken). However, MSDN clearly states:

'assemblyName' can be any of the following: The simple name of the assembly, without its path or file extension.

  • For example, you would specify TypeExtensions for the assembly, the path and name of which. \ Bin \ TypeExtensions.dll.

  • The full name of the signed assembly, which consists of the simple name, version, culture, and public key token; for example, "TypeExtensions, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 181869f2f7435b51."

In particular, I am trying to create an instance of the "Action" class defined in the assembly "SquidReports.DataCollector.Plugin.BES". I directly refer to this assembly as the using directive at the top of the same * .cs file where I am trying to create an instance.

I tried the following sentences from previous questions / answers:

Clear your solution, rebuild and try again. This is similar to some ASP.NET projects, but it is a simple console application.

Check the reference assemblies in the configuration file. Again, this is a simple console application that uses only the GAC and libraries in different projects of the same solution.

1. Verify that the assembly is in the correct working directory:

We are here...

It's right there !!!

2. Verify that the assembly is the same version on disk

Yeah ...

Looks the same

3. The latest recommendation was to use fuslogvw.exe.

I have no experience using this tool, but there is one thing that I found strange. After starting the debugging session, both the long and short named versions of my assembly appeared:

Hmmm ...

I looked at both magazines.

The short-named version seems to generate some warnings:

=== Prebinding Status Information ===

LOG: DisplayName = SquidReports.DataCollector.Plugin.BES Partial) WRN: Partial binding information was provided for assembly:

WRN: Build Name: SquidReports.DataCollector.Plugin.BES | Domain Id: 1

WRN: Partial binding occurs when only part of the display name of the assembly is provided.

WRN: This may cause the middleware to load the wrong assembly.

WRN: It is recommended that you provide a fully qualified textual identifier for the assembly,

WRN: consists of a simple name, version, culture, and public key token.

WRN: See the white paper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and general solutions to this problem.

... but it ends up loading successfully, and it clearly mentions my build in the right place:

LOG: attempt to load a new file URL: /// C: /Source/C#/SquidReports/SquidReports.DataCollector/bin/x86/Debug/SquidReports.DataCollector.Plugin.BES.DLL.

The log for the long-term version does not contain suspicious messages.

Any ideas?

EDIT . The following is a minimal definition of the Action class. This is a purely model class.

 public class Action : ICollectible { public Action() { // Empty constructor } public Action(int actionID, string siteID, string name) { this.ActionID = actionID; this.SiteID = siteID; this.Name = name; } public int ID { get; set; } // Identity ID assigned by DB [Key] public int ActionID { get; set; } // Identity ID assigned by API public string SiteID { get; set; } public string Name { get; set; } } 

The ICollectible interface and the [Key] attribute are part of another assembly. Not sure if this will affect?

EDIT 2: As Eric points out below, it’s obvious that I did exact checks on this other build as well.

+8
reflection c # .net-assembly
source share
1 answer

As you know, the assembly is loading, it simply cannot find the type ( Action ). You must specify the fully qualified name of the Namespace.Action type for .NET to find it.

+9
source share

All Articles