views:

162

answers:

4

Hello all,

I'm trying to rebuild zlib.net and create an assembly I can reference in future projects in Visual Studio.

However, after building from the supplied source code and moving the resulting zlib.net.dll to C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies, while I can indeed add the zlib.net reference to a new project, I do not have any access to the underlying objects.

I believe I'm missing some important configuration(s) in the zlib.net.dll project settings file so I can generate an assembly that can be referenced at design time by other projects. I'm just not sure which.

Could you please help?

UPDATE:
Note that I'm testing the resulting assembly by using zlib.net (link above) own supplied demos. When I use the supplied zlib.net.dll all works fine. When I use the one I build from source, it fails.

A: 

What do you mean, you have no access to underlying objects ? Do you mean that you cannot instantiate objects from classes that you have defined in that assembly ?

If so, are you sure that those classes are 'public' (have the public access modifier) ? It is possible that VS.NET doesn't add an access specifier to your class definition when you add a new class, hence the default access specifier will be used. In this case, that means the 'internal' access specifier is used. (Classes are internal by default). Then, this could explain why you cannot instantiate objects from those classes, since, 'internal' classes (or methods, or whatever), are only visible within the assembly in which they've been declared.

Solution: specify the 'public' access modifier on the classes that you want to be 'visible' outside that assembly.

Frederik Gheysels
The relevant classes are indeed public, Frederik. Neither I made any changes to the source code other than changing the target of the assembly to .Net 3.5 from 2.0 in the project configuration file.
Krugar
-1: I assume the assembly he's talking about already works for general use. He's asking about where to place the binary so multiple projects can reference it.
280Z28
+2  A: 

You shouldn't ever need to add something to the PublicAssemblies folder.

Place the assembly somewhere in your development folder hierarchy (perhaps C:\dev\Reference\zlib.net\zlib.net.dll). When you want to add a reference, click Browse and locate the assembly in your dev folders. Then click the reference in Solution Explorer and bring up the Properties pane. Make sure Copy Local is set to true.

If you have your solutions in source control, you'll want to copy the DLL to the current solution hierarchy and reference it from there - you don't want to force everyone to have some specific non-source-control folder to build a source controlled project.

280Z28
Thanks for the tip. I'll make sure to do that from now on (as I just did). But as you may suspect that didn't solve the problem.
Krugar
I would never have thought it wouldn't work after this, because from the limited information you posted above, this is only thing that makes sense to be the problem. What error messages are you receiving (you didn't mention them)?
280Z28
After adding the new zlib.net.dll, I'm getting "Error 1 The type or namespace name 'ZStream' could not be found (are you missing a using directive or an assembly reference?)". This doe not occur if I use the supplied dll instead of the one I build from the source code
Krugar
@Krugar: I just did the following and it worked fine. 1) Download the zlib.net source. 2) Open the project and build. 3) Copy the output zlib.net.dll to C:\dev. 4) In my project, Add Reference > Browse > Select zlib.net.dll. 5) In the file I want to use ZStream, add `using ComponentAce.Compression.Libs.zlib;` 6) Worked fine.
280Z28
Indeed it worked this time around. I can't understand it. Maybe I made some changes I'm not aware of. But repeating everything from the very beginning had it working now. Thanks.
Krugar
A: 

Frederik's suggestion is the first thing I'd check. You can't access classes or class members which are non-public in an external assembly.

If they are set to public already, make sure you have proper using statements for the namespaces of the classes you want to access. So if you want to access ZLib.SomeNameSpace.Archive class, ensure you either reference it by the full name, or by adding

using ZLib.SomeNameSpace;

to the code file first. Then you should be able to access the class, such as:

Archive myArchive = new Archive();
KP
I have the proper assignments in place., I know this because I'm actually not writting code for it, but instead reusing the supplied demo projects which fail when I replace the current zlib.net assembly reference for the one I just built. (Updating my question)
Krugar
A: 

Assuming that all your classes are indeed public, have you signed your assembly and added it to the GAC?

There are a few steps to go through, here is a short tutorial. There are a few niggly details but the example I link to should get you up and going.

Alex
I have done a release signed build and indeed added it to the GAC already. But the GAC is only concerned with runtime assemblies. This question is about design-time assemblies
Krugar