Runtime doesn't recognize <codebase> entry in app.config

blockp

New member
Joined
Feb 10, 2006
Messages
1
Programming Experience
10+
Hi All,
I have an assembly that needs to be shared with multiple windows services running on multiple servers. For company political reasons, I can not register the shared assembly in the GAC. I don’t want to distribute the assy to every applications directory (or sub directory of) that needs to reference it. I would like to put it in a common location that all services can reference it from.

On MS’s site and many others I have read that I can accomplish this by adding an entry to my services app.config files that looks something like the following. Where TestClass is my assy to share:
VB.NET:
[/FONT][/COLOR][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=#333333][COLOR=#333333][FONT=Courier New]  <runtime>[/FONT][/COLOR][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=#333333][COLOR=#333333][FONT=Courier New]  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">[/FONT][/COLOR][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=#333333][COLOR=#333333][FONT=Courier New]    <dependentAassembly>[/FONT][/COLOR][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=#333333][COLOR=#333333][FONT=Courier New]      <assemblyIdentity name="TestClass" publicKeyToken="e2b2de5a1382b348" culture="neutral"/>[/FONT][/COLOR][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=#333333][COLOR=#333333][FONT=Courier New]      <codeBase version="1.0.0.0" href="file:///c:/TestClass.dll"/>[/FONT][/COLOR][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=#333333][COLOR=#333333][FONT=Courier New]    </dependentAassembly>[/FONT][/COLOR][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=#333333][COLOR=#333333][FONT=Courier New]  </assemblyBinding>[/FONT][/COLOR][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=#333333][COLOR=#333333]</runtime>[/COLOR][/COLOR][/SIZE][/FONT]
[FONT=Courier New][SIZE=1][COLOR=#333333]


My trouble is that when I run my application with this entry in the app.config, it seems to be ignoring the entry entirely. The application starts fine, but when the application tries to reference the assy in a sub, I get the error “Could not load file or assembly ‘TestClass, Version= … …The system cannot find the file specified.”.

If I use the <probing privatepath=”DirTest”> entry in the config file and put the shared assy in DirTest which is a sub dir of the application , the service picks up the assy and works just fine.

When I go to the Assembly Binding Log Viewer and view the log for the binding of TestClass, I see the first message of ‘Bind result: hr = 0x80070002. The system cannot find the file specified.’ I see a message stating that it’s using the application.config file (and it’s the correct app config file), then it goes to “using machine config file”, then right to probing the application directory. The “Post Policy Reference” entry has the name and version of the TestClass that I referenced in references, not the name or version of the entry in the app.config file. I found this out by entering a bogus version in the config file.

My current setup is this:
I have created the assembly with VS 2005 and using the “Signing” tab on the “My Project” page, I checked the box to “Sign the Assembly”, which I understand gives the assembly a strong name. At the command prompt I ran sn.exe –T TestClass.dll and it game me the public key token that I entered into the app.config.

In my test application, on the references tab, I referenced TestClass from my shared location (for this test, c:\) and the properties list it with Strong Name = True. I set the Copy Local property = False. In my code, I have “Imports TestClass.Class1”, and in my button on the form, MsgBox(TestFunc). I did a build on my application which created an exe. The application directory does not have TestClass.dll in it. I ran the exe from windows explorer. The log entry for the invalid bind doesn’t show up until I click the button on the form.

As many people as there are saying that this works, I expect that I’m missing something simple. Am I referencing TestClass incorrectly? Is my entry on the app.config in the wrong place? Should I not be doing the import in my code?

I want to be able to do early binding to make the developers lives easier, but at runtime, I need for the exe to look somewhere else for the shared dll.

Any help making this work would be greatly appreciated. Thanks,
Paul
 
Back
Top