开发者

can't load assembly with typeof(UserType).AssemblyQualifiedName

I created a class Address in an Assembly MyUserType.dll. I want to load it in a console application. I tried the code below, but it failed:

 //cfg.AddAssembly(typeof(Address).AssemblyQualifiedNam开发者_如何学Ce);

But when i try to use one of the other load assembly methods, it succeeds.

cfg.AddAssembly(Assembly.GetAssembly(typeof(Address)));
cfg.AddAssembly("MyUserType");

The failed msg is:

Message = "Could not load file or assembly 'Ordering.Data.Address, Ordering.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)"

Why?


The class Ordering.Data.Address has a reference to an assembly not located in the same directory as the library, MyUserType.dll. Ensure that all referenced assemblies are in the System32 folder, the GAC or the same directory as the library.


Type.AssemblyQualifiedName returns the qualified name for the type, as in it returns the FullName of the type concatenated with the FullName of the containing assembly. You seem to be passing that into Assembly.Load or similar so it obviously fails as that is not a valid assembly name.

To use AssemblyQualifiedName you need to pass it to something like the static Type.GetType(string) method which will parse it correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜