简体   繁体   中英

Error attempting to use “extern alias” to reference two different DLLs with the same namespace (Visual Studio 2010)

I've read a couple of articles which lead me to believe that it's possible to reference two DLLs with the same namespace in the same project - see http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx .

However, when I attempt to do this, I run into a couple of issues that I have been unable to resolve.

Here's what I have done:

  1. Create a project for a class library, called V1.Model which has class Model.MyClass. Sign this assembly.
  2. Create another project for a class library, called Model, which also has class Model.MyClass. Sign the assemply.
  3. Copy the DLLs created from the above two projects into a folder, say Versions, and rename them (V1.Model -> V1.Model.dll, Model -> V2.Model.dll).
  4. Create a console application project, called Test, which references V1.Model.dll and V2.Model.dll.
  5. Change the "Aliases" property of the reference to V1.Model to "V1".
  6. Change the "Aliases" property of the reference to V2.Model to "V2".
  7. Create the following code which references both assemplies:

    extern alias V1;
    extern alias V2;

    static void Main(string[] args)
    {
    var v1 = new V1::Model.MyClass();
    var v2 = new V2::Model.MyClass();
    }

  8. Build and run Test

When I do this, there are a couple of issues.

One, the V1.Model.dll is not copied to the bin directory. (In fact, if I include many versions of the same namespace, it appears that only the DLL with the most recent version is copied). Of course, I can workaround this issue by manually copying the dll to the bin directory, but I am curious why this is necessary. Also, note that I have changed the "Copy Local" property to true for both references.

Two, when I run the application, I get the following error:

Could not load file or assembly 'Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d89c4561a79dd027' or one of its dependencies. The system cannot find the file specified.

Any ideas what I am doing wrong?

Thanks, Eric

When the system tries to locate an assembly called "Model", it will look for a file called "Model.dll". I think this can be resolved by GAC-ing the assemblies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM