CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    12

    .net searching wrong assembly

    hi, I am creating a unit testing utility. Basically, what it does is look
    for all the "private" and "protected" keywords in a source file from the
    ORIGINAL project and replace them with the "public" keyword. It also
    changes the namespace name to avoid naming collisions and puts these
    files in a DIFFERENT project, and then compiles this new project to
    provide an assembly

    So both projects (the original and the generated one) produce assemblies
    that have the same filename (but have a different version).
    From the original project, I reference the generated project. Everything
    is fine. Intellisense and object browser work on the reference. It
    compiles fine.
    But when I try to run the project I get:

    _____________________________________________________________
    An unhandled exception of type 'System.TypeLoadException' occurred in
    Unknown Module.
    Additional information: Could not load type sf.PTTest.SimpleVandFAccess
    from assembly SimpleVariableAndFunctionAccessibility,
    Version=1.0.1778.28574, Culture=neutral, PublicKeyToken=null.
    _____________________________________________________________


    For this project, there are 2 "SimpleVariableAndFunctionAccessibility
    "
    assemblies.
    One is:
    SimpleVariableAndFunctionAccessibility.exe --> the assembly of the
    project being compiled and run

    SimpleVariableAndFunctionAccessibility.dll --> a linked assembly (the
    generated assembly)



    I am not sure why I am getting the System.TypeLoadException, but the
    version mentioned in the error is of the WRONG ASSEMBLY.

    Visual Studio is looking in SimpleVariableAndFunctionAccessibility.EXE
    (I know this because of the version number) for the class -BUT- it should
    be looking in SimpleVariableAndFunctionAccessibility.DLL
    SimpleVariableAndFunctionAccessibility.DLL has a TOTALLY DIFFERENT
    version number than that mentioned in the error... so it is obvious VS is
    not looking for it in the right place...

    I have been working on this for a few days trying to come up with a
    solution... but so far nothing. Any insight or help would be greatly
    appreciated

    Note: I've attached the projects. The post-build event won't work, since the file is missing, but its not neccessary so it should be ok.
    Attached Files Attached Files
    • File Type: zip 2.zip (73.1 KB, 56 views)

  2. #2
    Join Date
    Jan 2004
    Posts
    12

    Re: .net searching wrong assembly

    I was able to fix this by giving the assemblies different names.

    Correct me if i'm wrong... but doesn't .Net allow you to have 2 different assemblies with the same name (with different innards) included in the same project?

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: .net searching wrong assembly

    I think it is possible, but you have to play with runtime configuration.

    You can have one referenced assembly and other assemblies (with same name, but dfferent versions) in application directory.

    Than you could try using dependentAssembly element in your application's .config file. Like this snipset from MSDN:

    Code:
    <configuration>
       <runtime>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
             <dependentAssembly>
                <assemblyIdentity name="myAssembly"
                                  publicKeyToken="32ab4ba45e0a69a1"
                                  culture="neutral" />
                <!--Redirection and codeBase policy for myAssembly.-->
             </dependentAssembly>
             <dependentAssembly>
                <assemblyIdentity name="mySecondAssembly"
                                  publicKeyToken="32ab4ba45e0a69a1"
                                  culture="neutral" />
                <!--Redirection and codeBase policy for mySecondAssembly.-->
             </dependentAssembly>
          </assemblyBinding>
       </runtime>
    </configuration>
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  4. #4
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    55°50' N 37°39' E
    Posts
    1,503

    Re: .net searching wrong assembly

    other solution is using STRONG NAMED ASSEMBLIES
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured