How to create a strong-named assembly? - asp.net

I have a web site project in which my architecture is an N-layered architecture. I am using Micorsoft Enterprise library's validation DLL file. As of now this DLL file is not strongly named. I need to make that assembly strongly named. How can I do this?
I saw some articles which depicts how to create a strong-named assembly by taking the Visual Studio 2008 command prompt and type:
sn -k publickey.snk
Then add the assembly tag to the assemblyinfo.cs file. I tried to do that, but my website project dosen't have any assemblyinfo.cs file.

Since ASP.NET web site projects are compiled dynamically, you can't assign a strong name to the assembly since it does not exist (yet). If you want to assign a strong name your ASP.NET code, you'll have to use a ASP.NET web application project instead.
As for assigning a strong name to a third-party DLL, you can't unless it's been delay signed. There is another way, but it will probably contravene the license agreement.

Related

C# .net, how to deploy class library dll when using 3rd party component references

This is my first post so here goes...
I have a c# .net class library I've build and been using in production for some time now. The project (using .net framework 3.5, output type Class Library, strongly named) didn't have any non-framework/standard references. It's set to be used as a COM component and we're using it against classic ASP websites. To deploy I'm setting the Build -> Configuration Manager to Release, building, copying the bin/release/PrintJob.dll file to our web servers. I then use regasm "c:\path info\PrintJob.dll" /tlb /codebase to register this on the server. At that point our classic ASP sites can successfully create an instance of the object and use it's functionality.
Today I've been tasked with implementing a new piece of functionality (encryption/decryption) using a 3rd party .net component. I'm used to working with ASP.NET applications more so that class libraries and COM components. So I update my existing project like I would a web project. I have the new dll on my computer, I first had to give it a strong name itself so my class library would accept it, I add the reference to the customCrypto.dll file in my application, reference the namespace in my class file(s), test it, build it, and it works fine locally.
I'm attempting to deploy it using the same method as previously. I go to the bin/release/ folder, copy the PrintJob.dll file to my web servers, register it the same, and when my sites attempt to use it now, it's throwing an exception that it can't find my customCrypto.dll file (the exceptions displays the full strong name assemply attributes).
So my question is am I doing this correctly? In a web project, the customCrypto.dll file is going to be moved along with my site automatically during the publish. So the dll automatically ends up with the project no problem. But with this class library, do I need to also copy the customCrypto.dll file to the other servers? When the build happened, how come my PrintJob.dll assembly didn't include this functionality internally. How do I get the COM component PrintJob.dll to be able to use the customCrypto.dll when deployed? Since the 3rd party customCrypto.dll component is a .net component, should I somehow be adding this to the machine and using it with my application another way?
I've spent the entire day trying to find references to this but all I can find are more direct issues like how to strongly name an assembly, add it as a reference, etc. Any help is greatly appreciated.

Debugging ASP.NET web service, C++/CLI DLL, and native DLL in Visual Studio 2008

I have a VS2008 solution with three projects: C# ASP.NET web service, which is using C++/CLI DLL, which in turn is calling functions of native C++ DLL. All references are properly set. In web service bin folder there are all three DLL's. Problem is when I hit F5 the page in my browser informs me about FileNotFoundException from HRESULT 0x8007007E, The specified module could not be found.
The missing module is my native DLL. ASP.NET Development Server copies (and uses) my C++/CLI DLL somewhere in %USERPROFILE%\AppData\Local\Temp\Temporary ASP.NET Files\root, but not the native one. If I manually copy native DLL to the same folder with C++/CLI DLL then I can debug my web service. However, this copying does not seem right.
Copying native DLL somewhere on PATH does not feel right either, because other developers need to remember it.
There is a similar question here, and a blog post linked in one answer. The given solution requires that I change DLL's to be delay-loaded, which again seems to much of a half-baked workaround, because it requires to change the end product due to development hurdles.
Is there a proper way to debug a combination of web service, C++CLI DLL, and native DLL?
The issue is simply that the compiler can't figure out where the native c++ library is.
So, there are a couple ways to fix that.
Use DLLImport to load the dll using a relative or absolute path at runtime.
Set the path environment variable to it's location.
Get really complicated in how the project is built (see link below, which you've obviously already read).
http://blogs.msdn.com/b/jorman/archive/2007/08/31/loading-c-assemblies-in-asp-net.aspx
There's no real answer beyond those.

ASP.NET - Share code

I have a web application that contains a bunch of classes in the App_Code folder. I compile the project and publish it to the IIS server.
I want to share some of the code in the app_code folder with another application on the server and therefore I think I need to register an assembly in the GAC.
What is the best way to do this? I have read this article: http://msdn.microsoft.com/en-us/library/Aa479044, which suggests a number of options?
Put the code in a class library, and add the library as a project reference to both applications.
Side Note:
If you need to access the request or response, etc. import the Sysyem.Web library and use the HttpContext object. This will give you most, if not all the information available to the page.
You'll have to move the code into a separate project, which will output a library.
If you have any references to dlls related to the ASP .Net or web in general, you can reference them from that library.
The code might not compile in the first, but you can refactor it, it really depends on how tight is with what is in App_Code.
You can then reference that library on the Web Site (you'll have to refactor here too some things). The library, once is signed, can be added to GAC also.
The solution for me was to expose the shared functionality in a web service.

Resources in ASP.NET (VB)

I have added a resource file in App_GlobalResources called FileList.resx.
Now I access the contents within the code by using
My.Resources.FileList.astro1 etc.
It works fine if I set the Build Action of resource file to Embedded. However in this case the resource file is not available after compile and I can't change it later.
If I set the Build Action to Content I get an error : Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "WAP.FileList.resources" was correctly embedded or linked into assembly "WAP" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Please advice me.
Are you using a Visual Studio Web Application? Or a Web Site?
In the latter case, you should be able to change the Resource file after deploying the site, and it should get automatically recompiled on the server. In the former case, it's a built-in that can't be changed after the site is compiled before deployment.
If that's a problem for you, there are of course alternatives to Resource files....
In any way of compiling and deploying your application all resource files will compiled in related to each resource file assemblies. In all cases, resource assemblies are ultimately created for each directory in the site, and satellite assemblies are generated beneath their respective culture-specific directories. Even when the site is JIT-compiled, the outcome is equivalent.
So, you must use Build Action of resource file to Embedded, but as possible solution for dynamic resource definition you can place you resources in a database. And even provide a Resource provider. In that case your database solution would have all the benefits that suggested by resource management aka dynamic culture definition, using resource binding to control, etc.
Here you can find some tutorials how to implement Resource-Provider Model in your application:
Extending the ASP.NET 2.0 Resource-Provider Model
Creating a Data Driven ASP.NET Localization
Resource Provider and Editor

How do I specify the name of the assembly created when publishing an ASP.NET Web Site Project?

The title pretty much says it all.
Given a web site project in VS2008 named FooDLL, I would like to be able to specify the name of the assembly that VS2008 spits out when I click "Publish Web Site". I am using the "use fixed naming and single page assemblies" option, so the resulting DLL is consistently named.
However, I would much rather be able to specify that the DLL is named something like FooDLL.dll (or just Foo.dll, whatever) than be stuck with the ugliness of App_Web_foo.ascx.cdcab7d2.dll.
Am I stuck since Web Sites don't have .project files (e.g. aren't projects)?
Not to continue the pattern of answering my own questions, but here it is anyway:
All I had to do was add a Web Deployment Project for the web site containing my user control. Though you can't specify the assembly name when building/publishing a web site, you can do this through the web deployment project. It's basically just a nice GUI for an msbuild project file... for a web site. Hooray for hacking a .project file onto a web site!
You could just compile your code as a class library project, then drop it into the Bin directory of your website.
I believe you are.
I am unaware of any benefits to using a web site project and while the benefits of using a web application project are minor, they exist. Create web application projects from now on.
ASP.NET Merge Tool (Aspnet_merge.exe) is your way to go.
It merge your web assemblies into one assembly for the whole Web site.
more information:
http://msdn.microsoft.com/en-us/library/bb397866.aspx

Resources