I have been following Scott Gutheries Blog on how to auto start an ASP.Net application and have an issue with assembly names.
Firstly the web site that I have been following is:
http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx
I have added the following code to my applicationHost config file, and as you may have guessed it does not work because of the type definition.
<serviceAutoStartProviders>
<add name="PreWarmMyCache" type="MyWebSiteName.PreWarmCache, MyWebSiteName" />
</serviceAutoStartProviders>
I have hunted around for a solution and came across this neat code.
Dim _a as New MyApp.PreWarmCache()
_a.GetType().AssemblyQualifiedName
This produces the following result.
"MyApp.PreWarmCache, App_Code.<#########>, Version=0.0.0.0, Culture=neutral, PublickKeyToken=null"
My problem comes from the ######### in the above assembly name as it is unique each time it is run and therefore I cannot use it in the applicationHost file above.
Is there a way to get that value fixed, so the value becomes fixed and does not change?
If you want control over the assembly name and version number that is generated for the site you should use a Web Application Projects instead of a Web Site Projects in Visual Studio.
You could read about the two types of projects on msdn : Web Application Projects versus Web Site Projects in Visual Studio.
With an application project the assembly name doesn't change for each build and you can easily reference the assembly.
To migrate from one type of project to another you will find advices here : Converting a Web Site Project to a Web Application Project
Add a new Class Library project to your ASP.NET website solution and call it Startup.
Create a new class in this library called "ApplicationPreload" that implements IProcessHostPreloadClient.
Add your new Startup class library as a Reference in your ASP.NET Website
Compile your Solution which will add Startup.dll to your website's Bin directory
Add the following to your applicationHost.config file right under the </sites> section
<serviceAutoStartProviders>
<add name="ApplicationPreload" type="Startup.ApplicationPreload, Startup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /
</serviceAutoStartProviders>
Related
My (C# Asp.net) website works locally, but when I publish it to Azure, it is missing a dll (OpenXML SDK).
After extensive googling, I found that I should set the Copy Local property to True. The thing is though, there is no references node in my solution explorer. Even if I create a new project, and add a few references, there is no references node there. (MS Visual Studio Express 2013 for Web)
Here is the error:
Parser Error Message: Could not load file or assembly [...] The
system cannot find the file specified.
The error is caused by this line (in my Web.config file):
<add assembly="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Please help me to either:
display the references node
or manually upload the needed dll (feels odd)
or add some magic command to my Web.config to make it automatically upload the used dll-s.
The references node was missing from my Solution Explorer because I chose to create a Web Site, not a Web Application. For Web Sites, the actual physical folder structure is what gets synced to the server. It doesn't have a References node (and, by the looks of it, many other things are missing, since the basic idea is bit different - see this discussion for more details).
There were two solutions for the problem:
Converting my Web Site project into a Web Application project (instructions here)
Adding a Bin folder in my project folder (that is the folder with the project name, the on that has my .aspx files in it), and including the necessary dll in that folder
I chose the latter. After publishing the site again, Visual Studio automatically uploaded the Bin folder with the dll inside it, and it worked like a charm.
I developed an ASP.NET MVC 3 web application and it's working correctly locally, but not on the server:
Line 18:<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
How do I fix the fact that the server can't find this assembly?
It's looking for a GAC'd assembly reference to that assembly. Do you have that assembly installed on the server? If not, you need to set it to bin deploy.
Here's how you do that:
To set the Copy Local property to True
In Solution Explorer, double-click the My Project node for the project.
In the Project Designer, select the References tab.
Select a referenced component in the References list.
The properties associated with that reference appear in a list in the Properties window.
Select Copy Local from the left-hand column, and then click the arrow in the right-hand column to change the value to True. (Source)
To set up your project to bin deploy, follow these instructions laid out by Scott Hanselman.
right click on project in solution exploret.
select Add diployable dependencies
checked Asp.net MVC and click ok
I'm a using the repository pattern and Unity to manage the dependency to my concrete repository objects. In itself this is not an issue however I am running into a problem when using publish website in both VS and the TFS build process.
I believe the problem is being caused by the fact that although the project which contains the concrete repository objects is referenced in my application, the classes that it contains are never used directly. This is because I am using Unity to create instances of the concrete objects at runtime using the Unity config held in my web.config.
The repository project is being compiled when and included in the output when built but when publish website is used in either VS of TFS the repository assembly is missing. Therefore when the web application is deployed to the web server it is not possible to use it as you are greeted with the error:
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
This is because Unity cannot find the missing assembly as you would expect.
So my specific question is; Is there a way to ensure that repository assembly is copied to the output directly when publishing the website in VS and TFS without directly using one of the concrete classes in the project?
So with some digging around I have found a solution to my problem. This soltuion only fixes the problm when building with TFS but to be honest with continuos integration I'm not bothered about publishing from VS.
My inspiration came from an answer given by Mike Hadlow
What's the best way to get TFS to output each project to its own directory?
Basically the solution is to modify the build script for web project so that it copies the missing assembly to the publish website output folder.
Here is what I did:
I right clicked on my web project in the solution explorer and clicked 'Unload Project'.
I then right clicked on the unloaded project and clicked 'Edit [Project Name]'
Scrolling right down to the bottom of the file I found the following commented out build target:
<Target Name="AfterBuild">
</Target>
I modified this adding the command to copy the missing assembly:
<Target Name="AfterBuild">
<Copy SourceFiles="$(OutDir)[Missing Assembly Name]" DestinationFolder="$(OutDir)_PublishedWebsites\$(MSBuildProjectName)\bin" SkipUnchangedFiles="true" />
</Target>
Now when building the solution in TFS the missing assembly is included in the bin folder of the published website output.
This solution could be used to copy any other missing content to the published website output. As the files that you want to copy are likely to be different for each project doing it in this way is probably the best option. I am however thinking about creating a custom version of Microsoft.WebApplication.targets which copies minified CSS and script files.
I have a solution which contains multiple WAPs (Web Application projects).
Every WAP has it's own Web Deploy project in order to be able to precompile these sites.
On one of the web app we are created a new WCF file with
AspNetCompatibilityRequirementsMode.Allowed
In debug mode it is working ok, but if i switch to release it crashes:
(we are using msbuild to create the deployable versions)
Could not load file or assembly 'App_Web_*****, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.
I found some explanation in this link: WCF service
WCF stores the list of referenced assemblies into the customString
attribute in the build result (service.svc.cdcab7d2.compiled),
including App_Global. It seems there is an incorrect assumption here
that those assemblies will always be there, which is not necessarily
the case in Web Deployment Projects (aspnet_merge) where assemblies
will be merged. After the merge step, the assemblies are actually all
merged into a single assembly (let us say MyWebSite.dll) as we
selected that option in WDP. ASP.NET only updates the .compiled files
it knows about, so App_Global.asax.compiled actually has a correct
reference to MyWebSite_Deploy.dll instead of App_Global.dll. Original
assemblies are removed after the merge step. WCF reads the list of
assemblies previously stored, and throws when it cannot find
App_Global
List of solutions i've tried:
1.Check 'Allow this precompiled site to be updatable' - not worked
2.Remove manualy the App_* reference from service.compile file
(It worked but it should be another solution)
3.Add fully qualified name for the service/factory in .svc
The service has a fully qualified name.
4.tried to set this key:
<SourceWebPhysicalPath>..\..\ProjectName</SourceWebPhysicalPath>
following these instructions
5.<compilation debug="false" batch="false">
Tried this to set to web.config using these instructions
6."Merge All outputs to a single assembly"
i haven't tried this because it requires to register all the used assemblies to GAC and means we need to change the deployment logic.
I don't want to delete the asp.net temporary folder because it stops the application and it is inacceptable
I also found Scott Gutthrie link but it's from '07 it should made it's way to asp.net 4.0
Additional Info
The service is placed: ProjectName\WebResorce\Service.svc ,
<%# ServiceHost ... Factory="SolutionName.SharedWeb.WadoLabsServiceHostFactory" %>
where the SharedWeb is a Shared Web project
Do you have any other ideas?
Thanks in advance
The following setup worked for me:
In the svc file, specify a qualified name of the service, as <%# ServiceHost ... Service="<Namespace>.<ServiceContractClass>, <AssemblyName>" CodeBehind="ServiceContractClass.svc.vb" %>
(Can't remember why it was required, but) I made sure that the Namespace and the AssemblyName are different.
The trick is to specify the qualified name, including the AsseblyName.(The assembly name that is specified in the project containing the service, not the Web Deploy Project).
Also note that there is a space between the comma after the class name, and the AssemblyName.
Why don't you implement the WCF services in a separate library project inside the same solution, and simply reference that project from your web app(s)? That way they would stay out of the pre-compilation process, and you could work with predictable type names inside the *.svc files. Plus, this would probably also give you a cleaner solution structure.
Where are assembly refernces stored for a web application?
In a Web Site, I see assembly tags written to the assembly node in the web.config when you add a reference. I am just curious as to how the Web Application Project makes the connection to get the correct local dll?
I manually add the reference and the application builds, but the dll is not imported into the BIN folder, and the assembly nodes are not created in the web config as they are in a Web Site. I do a solution search for the text 'assembly="SomeAssembly..." and no results are found.
I am just curious as I am trying to centralize updating assembly references as a 3rd party control vendor puts out hotfixes on a regular basis and we end up having to run around and update all the individual page refernces to the assembly. I was able to do this effectively in the Web Site project, but I am fairly new to Web Application Projects. Any advice or links would be appreciated. I guess I'm looking for tips on assembly & control reference management for ASP.NET Web Application Projects.
Like most Visual Studio projects, references are kept in the project.
There are two kinds of reference:
Project References are references to another project in the same solution. They look like this:
<ProjectReference Include="..\VBClassLibrary1\VBClassLibrary1.vbproj">
<Project>{045D7D9F-8E44-4C4B-95F8-620E86593C5B}</Project>
<Name>VBClassLibrary1</Name>
</ProjectReference>
File references are references to an arbitrary file on disk:
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
If you expand the References folder and click on a reference, then look in the Properties window, you'll see that both kinds of reference have a "Copy Local" property. For project references it defaults to true, for file references to false (though maybe that's only if the file is in the GAC). Changing the default adds:
<Private>False</Private>
Since the assembly was not imported to the BIN folder, and your application works, I assume that it is stored in the GAC (global assembly cache) and marked as "copy local=false" in the reference properties. You don't see the reference to the assembly in the web.config, since your code behind assembly - YourApp.dll (which is always created for web-applications), contains a standard assembly reference to that assembly. When you run your application it loads the assembly from the GAC.
Those "missing" dlls are probably in the Global Assembly Cache and are available to all .NET applications.
You can add control references to the pages/controls section of web.config, which will apply to all pages in the application.
I had the same issue, deleting .vs folder in the directory of the project solved the issue for me as it forced the recreation of .suo file which (though bite code) had reference to the web.config file in the wrong directory