Shared Assembly Problem
-
I am running into some probems using the shared assembly. I seem to be able to check it into the GAC, but I do not seem to able to find the file when I reference it. I think I have done everything the help files say to do, but when I go to build it, I get file not found error. This code works when the assembly is private. I put a detailed explaination of problem with screen shots and source code on the web at http://www.robertpeterson.ws/screenshots/GACproblem.htm Sorry for using large image sizes. I suspect that there may be some compiler option that I haven't set, but I can't imagine what else I should change. I will continue to research and hopefully correct the problem, but I hope you will look at the web page and let me know if you have any suggestions. I have looked at 4 books on Visual C++.NET. They all say how to make an assembly shared, but they don't say how to include it into a program (at least I haven't noticed an example yet.) The other thing I noticed is that they all show c://winnt/assembly as the example, but not C://WINDOWS/assembly where the gacutil puts it on the XP box. #include "stdafx.h" #using #using // File that is in the GAC #include #include using namespace ReformaterClassLibrary; using namespace System; // This is the entry point for this application int _tmain(void) { ParagraphReader * pReader = new ParagraphReader(); // Read the contents of the file pReader->FilePath = "a://paragraph.txt"; pReader->Read(); // Instantiate a Paragraph Rewriter class; ParagraphRewriter * pRewriter = new ParagraphRewriter(pReader->Data); pRewriter->MakeTriangle2(); // Reformat the paragraph // Instantiate a Paragraph Writer object to write the data to a disk ParagraphWriter * pWriter = new ParagraphWriter("a://triangle.txt"); pWriter->WriteParagraph(pRewriter->Output); cout << "System terminated normally." << endl; return 0; }
-
I am running into some probems using the shared assembly. I seem to be able to check it into the GAC, but I do not seem to able to find the file when I reference it. I think I have done everything the help files say to do, but when I go to build it, I get file not found error. This code works when the assembly is private. I put a detailed explaination of problem with screen shots and source code on the web at http://www.robertpeterson.ws/screenshots/GACproblem.htm Sorry for using large image sizes. I suspect that there may be some compiler option that I haven't set, but I can't imagine what else I should change. I will continue to research and hopefully correct the problem, but I hope you will look at the web page and let me know if you have any suggestions. I have looked at 4 books on Visual C++.NET. They all say how to make an assembly shared, but they don't say how to include it into a program (at least I haven't noticed an example yet.) The other thing I noticed is that they all show c://winnt/assembly as the example, but not C://WINDOWS/assembly where the gacutil puts it on the XP box. #include "stdafx.h" #using #using // File that is in the GAC #include #include using namespace ReformaterClassLibrary; using namespace System; // This is the entry point for this application int _tmain(void) { ParagraphReader * pReader = new ParagraphReader(); // Read the contents of the file pReader->FilePath = "a://paragraph.txt"; pReader->Read(); // Instantiate a Paragraph Rewriter class; ParagraphRewriter * pRewriter = new ParagraphRewriter(pReader->Data); pRewriter->MakeTriangle2(); // Reformat the paragraph // Instantiate a Paragraph Writer object to write the data to a disk ParagraphWriter * pWriter = new ParagraphWriter("a://triangle.txt"); pWriter->WriteParagraph(pRewriter->Output); cout << "System terminated normally." << endl; return 0; }
To my knowledge, none of the .NET compilers will compile with a reference to an assembly in the GAC, instead you need to reference an absolute location. When you run your program the framework will look in the GAC first for the assembly before it starts looking in the private directories. James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
-
I am running into some probems using the shared assembly. I seem to be able to check it into the GAC, but I do not seem to able to find the file when I reference it. I think I have done everything the help files say to do, but when I go to build it, I get file not found error. This code works when the assembly is private. I put a detailed explaination of problem with screen shots and source code on the web at http://www.robertpeterson.ws/screenshots/GACproblem.htm Sorry for using large image sizes. I suspect that there may be some compiler option that I haven't set, but I can't imagine what else I should change. I will continue to research and hopefully correct the problem, but I hope you will look at the web page and let me know if you have any suggestions. I have looked at 4 books on Visual C++.NET. They all say how to make an assembly shared, but they don't say how to include it into a program (at least I haven't noticed an example yet.) The other thing I noticed is that they all show c://winnt/assembly as the example, but not C://WINDOWS/assembly where the gacutil puts it on the XP box. #include "stdafx.h" #using #using // File that is in the GAC #include #include using namespace ReformaterClassLibrary; using namespace System; // This is the entry point for this application int _tmain(void) { ParagraphReader * pReader = new ParagraphReader(); // Read the contents of the file pReader->FilePath = "a://paragraph.txt"; pReader->Read(); // Instantiate a Paragraph Rewriter class; ParagraphRewriter * pRewriter = new ParagraphRewriter(pReader->Data); pRewriter->MakeTriangle2(); // Reformat the paragraph // Instantiate a Paragraph Writer object to write the data to a disk ParagraphWriter * pWriter = new ParagraphWriter("a://triangle.txt"); pWriter->WriteParagraph(pRewriter->Output); cout << "System terminated normally." << endl; return 0; }
I havent tried this myself :) , but I'll have a look in the morning.
-
To my knowledge, none of the .NET compilers will compile with a reference to an assembly in the GAC, instead you need to reference an absolute location. When you run your program the framework will look in the GAC first for the assembly before it starts looking in the private directories. James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
Perhaps your right. That would explain why I can't seem to do it. However, this raises two new questions. 1) How do I reference the absolute location programmatically or in visual studio.Net? 2) How can I compile code that uses classes in the assembly in the GAC? If I can't reference it at compile time I just get a bunch of undeclared identifier and namespace not found errors.
-
Perhaps your right. That would explain why I can't seem to do it. However, this raises two new questions. 1) How do I reference the absolute location programmatically or in visual studio.Net? 2) How can I compile code that uses classes in the assembly in the GAC? If I can't reference it at compile time I just get a bunch of undeclared identifier and namespace not found errors.
SuperGeek wrote: 1) How do I reference the absolute location programmatically or in visual studio.Net? In your #using statement you should be able to give the full path, or you can add the directory containing your assembly to the #using search path (in the project's properties go to C/C++ -> General and it should be right at the top. SuperGeek wrote: How can I compile code that uses classes in the assembly in the GAC? The assemblies should also exist somewhere else on your system; if they don't the vendor screwed up (IMHO). For instance, in C#/VB.NET the Add Reference dialog doesn't pull its assembly list from the GAC, instead there are is a key in the registry where vendors can add values. This key lists all of the places the Add Reference dialog should look for assemblies. That key could give you an idea of where to search to find the assemblies. HTH, James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
-
SuperGeek wrote: 1) How do I reference the absolute location programmatically or in visual studio.Net? In your #using statement you should be able to give the full path, or you can add the directory containing your assembly to the #using search path (in the project's properties go to C/C++ -> General and it should be right at the top. SuperGeek wrote: How can I compile code that uses classes in the assembly in the GAC? The assemblies should also exist somewhere else on your system; if they don't the vendor screwed up (IMHO). For instance, in C#/VB.NET the Add Reference dialog doesn't pull its assembly list from the GAC, instead there are is a key in the registry where vendors can add values. This key lists all of the places the Add Reference dialog should look for assemblies. That key could give you an idea of where to search to find the assemblies. HTH, James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
Ok, I compiled it by setting the search path to the assembly that I signed and checked into the GAC with sn.exe and gacutil.exe. I can see that the assembly is in the gac. However, when move the .exe that I just built to say the desktop, and try to run it, I get a runtime error. System.IO.FileNotFound error. I presume it is not really finding the dll in the GAC. Does it look in the GAC at runtime? I dont need to put the exe in the GAC too do I? I think I am not referencing the dll in the GAC. I guess I am not convinced that the CLR is finding my dll to which the GAC points to.
-
Ok, I compiled it by setting the search path to the assembly that I signed and checked into the GAC with sn.exe and gacutil.exe. I can see that the assembly is in the gac. However, when move the .exe that I just built to say the desktop, and try to run it, I get a runtime error. System.IO.FileNotFound error. I presume it is not really finding the dll in the GAC. Does it look in the GAC at runtime? I dont need to put the exe in the GAC too do I? I think I am not referencing the dll in the GAC. I guess I am not convinced that the CLR is finding my dll to which the GAC points to.
Are the assemby versions the same between the one in the GAC and the one not in the GAC? When you strongly-name an assembly the loading semantics change from just matching the assembly name to including public key token, version, and culture (for resource-only assemblys). If you are constantly updating the assembly you are trying to load, ensure that the AssemblyVersionAttribute doesn't use * as part of the version number, otherwise the number will change every time you do a build which will require you to recompile your exe and/or provide a publisher policy (see MSDN for more info) so that it loads the correct version on each build. James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
-
Are the assemby versions the same between the one in the GAC and the one not in the GAC? When you strongly-name an assembly the loading semantics change from just matching the assembly name to including public key token, version, and culture (for resource-only assemblys). If you are constantly updating the assembly you are trying to load, ensure that the AssemblyVersionAttribute doesn't use * as part of the version number, otherwise the number will change every time you do a build which will require you to recompile your exe and/or provide a publisher policy (see MSDN for more info) so that it loads the correct version on each build. James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
You are correct. The versions do not match. I will try deleting the one in the GAC and reapply gacutil and see how it goes. I have one little concern though. If I am using a using statement such as # using // in the GAC do I need to specify version numbers and keys in the using statement. If I have to specify version numbers, or more information (recall that I am doing this on Win XP). How or where do I indicate this? Thanks for all of your help.
-
You are correct. The versions do not match. I will try deleting the one in the GAC and reapply gacutil and see how it goes. I have one little concern though. If I am using a using statement such as # using // in the GAC do I need to specify version numbers and keys in the using statement. If I have to specify version numbers, or more information (recall that I am doing this on Win XP). How or where do I indicate this? Thanks for all of your help.
Well James I am happy to report that we did it and I could not have done it with out your help. There was a slight difference in the minor version number of the shared assembly in the GAC and the one that the GAC pointed to. I am not completely sure how I let that happen, but I did. Perhaps I did a rebuild that I forgot about. I don't know. Also, I put a copy of the same version of that assembly in the debug folder of the client application so I could compile with the same version as was pointed to by the GAC.:) The steps I followed... 1) To compile, I put a copy of my shared assembly in the same folder as my project. In the debug folder where my exe goes. 2) I removed the faulty version of the reference in the GAC 3) I readded my shared assembly to the GAC with the gacutil.exe and made absolute certain that the version numbers were exactly the same in the GAC, as assembly that the GAC pointed to and that this was the exact same version number that the client application was compiled with. I really appreciate your help.