Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9
This is the forum to discuss the Wrox book Professional ASP.NET 3.5: In C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470187579
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 18th, 2008, 10:54 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default BuildProvider example not working

I'm having a problem not being able to get the example code in Chapter 1 on Build Providers working.

I have followed the steps in the section 'Using your own Build Providers' but my website code-behind cannot see the class 'Evjen'. This is what I've done:

1. Created a solution called CarBuildProvider with a Class Library project called CarBuildProvider. It contains a single class 'Car' which contains code as per page 48.
2. Built it.
3. Created a new ASP.NET Website called CarBuildProviderDriver containing the usual Default.aspx file.
4. Manually created the App_Code folder (as it wasn't there by default) by right-click on the project name->Add ASP.NET Folder->App_Code.
5. Added a Reference to the CarBuildProvider.dll file that was created in steps 1+2.
6. Added the respecitve <buildProvider> entry into web.config:
<buildProviders>
<add extension=".car" type="CarBuildProvider.Car"/>
</buildProviders>
7. Built it.
8. Dropped the EvjenCar.car file into the App_Code folder
9. Go to type in 'EvjenCar' in the Default.aspx Page_Load method.
Intellisense doesn't pick it up; it cannot resolve the class.

Have I missed something out?
Jack.
  #2 (permalink)  
Old January 21st, 2009, 05:24 PM
Registered User
 
Join Date: Jan 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem

I am having the same problem. Wrox, what is the solution to this?
  #3 (permalink)  
Old August 26th, 2009, 11:00 AM
Authorized User
Points: 73, Level: 1
Points: 73, Level: 1 Points: 73, Level: 1 Points: 73, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2007
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Talking BuildProviders

I got it to work after 4 hours. The first code is for the CarBuilderProvider.dll I created a class library called CarBuildProvider. Complied it into a dll.

using System.IO;
using System.Web.Compilation;
using System.Xml;
using System.CodeDom;
namespace CarBuildProvider
{
classCar : BuildProvider
{
publicoverridevoid GenerateCode(AssemblyBuilder myAb)
{
XmlDocument carXmlDoc = newXmlDocument();
using(Stream passedFile = OpenStream())
{
carXmlDoc.Load(passedFile);
}
XmlNode mainNode = carXmlDoc.SelectSingleNode("/car");
string selectionMainNode = mainNode.Attributes["name"].Value;
XmlNode colorNode = carXmlDoc.SelectSingleNode("/car/color");
string selectionColorNode = colorNode.InnerText;
XmlNode doorNode = carXmlDoc.SelectSingleNode("/car/door");
string selectionDoorNode = doorNode.InnerText;

XmlNode speedNode = carXmlDoc.SelectSingleNode("/car/speed");
string selectionSpeedNode = speedNode.InnerText;
CodeCompileUnit ccu = newCodeCompileUnit();
CodeNamespace cn = newCodeNamespace();
CodeMemberProperty cmp1 = newCodeMemberProperty();
CodeMemberProperty cmp2 = newCodeMemberProperty();
CodeMemberMethod cmm1 = newCodeMemberMethod();
cn.Imports.Add(newCodeNamespaceImport("System"));
cmp1.Name = "Color";
cmp1.Type = newCodeTypeReference(typeof(string));
cmp1.Attributes = MemberAttributes.Public;
cmp1.GetStatements.Add(newCodeSnippetExpression("return \"" + selectionColorNode + "\""));
cmp2.Name = "Doors";
cmp2.Type = newCodeTypeReference(typeof(int));
cmp2.Attributes = MemberAttributes.Public;
cmp2.GetStatements.Add(newCodeSnippetExpression("return " + selectionDoorNode));
cmm1.Name = "Go";
cmm1.ReturnType = newCodeTypeReference(typeof(int));
cmm1.Attributes = MemberAttributes.Public;
cmm1.Statements.Add(newCodeSnippetExpression("return " + selectionSpeedNode));
CodeTypeDeclaration ctd = newCodeTypeDeclaration(selectionMainNode);
ctd.Members.Add(cmp1);
ctd.Members.Add(cmp2);
ctd.Members.Add(cmm1);
cn.Types.Add(ctd);
ccu.Namespaces.Add(cn);
myAb.AddCodeCompileUnit(this, ccu);
}
}
}

Next I created the ExampleBP website. I modified the web.config file and added the following under the <Compilation>:

<buildProviders>
<
addextension=".car"type="CarBuildProvider.Car" />
</
buildProviders>

I created the Car.car xml file and placed it in the App_Code filder:

<?xmlversion="1.0"encoding="utf-8" ?>
<
carname="EvjenCar">
<
color>Blue</color>
<
door>4</door>
<
speed>150</speed>
</
car>

Next I copied the CarBuilderProvider.dll and CarBuildProvider.pdb into the bin folder.

In the default.aspx file I added the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclass_Default : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
EvjenCar newCar = newEvjenCar();
Response.Write(newCar.Color + "<br/>");
Response.Write(newCar.Doors.ToString() + "<br/>");
Response.Write(newCar.Go().ToString() + "<br/>");
}
}

I built the website and ran it and it worked. My mistake the web.config file was wrong. I only added type="CarBuildProvider". I included only the namespace and forgot to add the .Car class name. 4 hours of frustraton.

here is a link to a database version by Fritz Onion that helped my solve my problem:

http://www.pluralsight.com/community...9/06/2188.aspx

At the bottom of the article you can download the code.

I hope this works.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
window.opener working .... not working alyeng2000 Javascript How-To 5 January 5th, 2007 08:05 AM
Web.Config..Working or Not Working peace95 ASP.NET 1.0 and 1.1 Basics 1 September 18th, 2006 06:53 AM
why it is not working rakeshgv SQL Server 2000 0 August 8th, 2006 06:55 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM
Get Working Copy... not working Enkiel Classic ASP Basics 0 April 21st, 2004 01:41 PM



All times are GMT -4. The time now is 10:09 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.