Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Signed Assemby - Help

Status
Not open for further replies.

cporter71

Programmer
Jul 20, 2005
3
US
Task: Create an executable that works with a signed assembly (dll)

For openers, I am a dot net (csharp) newbie.

This is where I am at:

1) Created/compiled a dll. The name of the dll is UnixCrypt.dll (wraps a c# impl of unix crypt (i am not the author)).
2) Created/compiled/tested a test-driver executable that references UnixCrypt.dll. All functionality works.
3) Using the sn.exe tool created a public/private key file. In the UnixCrypt assembly manifest I have added the following line:
[assembly: AssemblyKeyFile(@"C:\public_private")]
... where "public_private" is the key-pair file generated from sn.exe.
4) Re-build the UnixCrypt assembly and verify that the assembly is signed using "sn -v" - it returns:
Assembly 'UnixCrypt.dll' is valid
Presumably all is well.
5) Not sure where to go next - this is my question! I want to build the test driver so that is works with (and only with) the signed version of UnixCrypt.dll. The outcome I am attempting to achieve is to create 2 versions of UnixCrypt.dll, one signed and one not signed and have the executable bomb when the non-signed version is substituted for the signed version. I am not sure how to build this dependency into the executable. I tried the following:
csc /t:exe TestUnixCrypt.cs /lib:<path_to_lib> /reference:UnixCrypt.dll

This builds fine, but it bombs at runtime (BTW - in the line above, the dll referenced is the signed version).

The stack trace probably tells me everything I need to know but I am not experienced enough with dot net to make sense of it all. I have put the stack trace at the bottom of this post.

I have spent some time looking through the sdk docs as well as msdn - I found some good answers on some points, some good confusion on others.

Any help here is appreciated. I need some help figuring out how to build the executable such that is depends on the signed assembly and only works with the signed assembly.

Thanks.
cporter

##########################################################

Unhandled Exception: System.IO.FileNotFoundException: File or assembly name UnixCrypt, or one of its depe
ndencies, was not found.
File name: "UnixCrypt"
at SomeCo.TestUnixCrypt.Main(String[] args)

=== Pre-bind state information ===
LOG: DisplayName = UnixCrypt, Version=1.0.931.34461, Culture=neutral, PublicKeyToken=7734614b473eaaae
(Fully-specified)
LOG: Appbase = C:\old_computer\d_drive\dev\Visual_Studio_Projects\TestUnixCrypt\TestUnixCrypt\
LOG: Initial PrivatePath = NULL
Calling assembly : TestUnixCrypt, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
===

LOG: Application configuration file does not exist.
LOG: Publisher policy file is not found.
LOG: Host configuration file not found.
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\config\machine.co
nfig.
LOG: Post-policy reference: UnixCrypt, Version=1.0.931.34461, Culture=neutral, PublicKeyToken=7734614b473
eaaae
LOG: Attempting download of new URL file:///C:/old_computer/d_drive/dev/Visual_Studio_Projects/TestUnixCr
ypt/TestUnixCrypt/UnixCrypt.DLL.
LOG: Attempting download of new URL file:///C:/old_computer/d_drive/dev/Visual_Studio_Projects/TestUnixCr
ypt/TestUnixCrypt/UnixCrypt/UnixCrypt.DLL.
LOG: Attempting download of new URL file:///C:/old_computer/d_drive/dev/Visual_Studio_Projects/TestUnixCr
ypt/TestUnixCrypt/UnixCrypt.EXE.
LOG: Attempting download of new URL file:///C:/old_computer/d_drive/dev/Visual_Studio_Projects/TestUnixCr
ypt/TestUnixCrypt/UnixCrypt/UnixCrypt.EXE.
 
make sure your dll files (UnixCrypt, etc) are in the debug folder of you app.

windowsApplication1/bin/debug/

Make sure the files that are being read/written are where they are supposed to be.

It's a file I/O error so it's not finding a file somewhere.

 
Thanks for taking the time to replay JurkMonkey. I understand it is a path issue, however, and with due respect to you, your reply and your time to do so, I am not sure that is the problem I am trying to solve here. Perhaps I should have left the trace out altogether. What I am looking for is some guidance/direction on "howto" accomplish the following:

"How to build an executable such that is depends on the signed assembly (dll) and that the executable works with (and only with) the signed assembly it was built against."

If implicitly you are saying that I am on the right track with my csc line and that all I need to do is fix by path issues then OK - thanks. Otherwise, any sort of howto, step by step input would be appreciated.

Thanks.
cporter
 
cporter71,

Well in asnwer to your intial quesiton about having your executable work with only and depend on your signed version of that dll, that happens at compile time.

In other words when you set a reference to an assembly at compile time that assemblies version is written into the meta data of the assembly you are comipling. If that version of the assembly is then replaced by another without recompiling the calling dll the framework will throw and exception. Similar to the one you are getting now.

So there is nothing really "special" you need to do to create that dependency.

As for the error at hand, where is the UnixCrypt.dll located that you are referencing? You need to provide the full path to the dll when you compile.

I would strongly suggest that you compile your apps using the IDE since it will resolve a lot of the dependencies for you and make life easier for you. You can also control many of the compile switches from within the IDE.

Hope that helps.
 
OK - So know I get it. It was a path issue along with a some lack of knowledge on my part. So what I did not catch is that when you build the *.exe VSDN copies over the *.dll into the 'bin' dir (as JurkMonkey mentioned) - I assumed it reference the library from its original location. So instead of trading out the dll in the same dir as my exe, I was trading out the dll in its original location. I traded out the dll in my exe's bin dir and voila, my exe puked at runtime - love it!

"So there is nothing really 'special' you need to do to create [the] dependency" as Dewalt stated.

Thanks you folks for helping me through my fuzziness.

Cheers,
cporter
 
One other thing to note cporter71 is that the dll is copied to the output directory of the calling app by default.

You can tell the compiler to reference the dll in the location it is in and not copy it to the output directory if you want.

In the IDE look at the properties for the reference and you will see the Copy Local property. If you set that to False then the dll will be referenced where it sits and will not be copied. In that case the dll will have to be in the same place on the target machine when you move the code.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top