gilesrpa
gilesrpa

Reputation: 1061

app_code find assemblyqualifiedname of class

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?

Upvotes: 0

Views: 261

Answers (2)

Sean C
Sean C

Reputation: 1

  1. Add a new Class Library project to your ASP.NET website solution and call it Startup.

  2. Create a new class in this library called "ApplicationPreload" that implements IProcessHostPreloadClient.

  3. Add your new Startup class library as a Reference in your ASP.NET Website

  4. Compile your Solution which will add Startup.dll to your website's Bin directory

  5. 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>
    

Upvotes: 0

NicoD
NicoD

Reputation: 1189

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

Upvotes: 1

Related Questions