Click to See Complete Forum and Search --> : .net searching wrong assembly


ianmills
November 13th, 2004, 06:18 PM
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.

ianmills
November 16th, 2004, 01:01 AM
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?

boudino
November 16th, 2004, 01:40 AM
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:

<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>

Andy Tacker
November 16th, 2004, 01:52 AM
other solution is using STRONG NAMED ASSEMBLIES