Wrox Programmer Forums
|
BOOK: Professional ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Professional ASP.NET 4 in C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470502204
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2013, 04:42 AM
Authorized User
 
Join Date: Aug 2012
Posts: 19
Thanks: 8
Thanked 0 Times in 0 Posts
Default Chapter1 : CarBuildProvider web.config error

hello

i've made my build provider as you said in section (USING YOUR OWN BUILD PROVIDER) but it has one error : Could not load type 'CarBuildProvider.Car'

thank you.

here is my Codes:
Code:
using System.IO;
using System.Web.Compilation;
using System.CodeDom;
using System.Xml;

/// <summary>
/// Summary description for CarBuilderProvider
/// </summary>
namespace CarBuildProvider
{
  public class Car : BuildProvider
  {
    public override void GenerateCode(AssemblyBuilder myAb)
    {
      XmlDocument carXmlDoc = new XmlDocument();
      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 = new CodeCompileUnit();
      CodeNamespace cn = new CodeNamespace();
      CodeMemberProperty cmp1 = new CodeMemberProperty();
      CodeMemberProperty cmp2 = new CodeMemberProperty();
      CodeMemberMethod cmm1 = new CodeMemberMethod();

      cn.Imports.Add(new CodeNamespaceImport("System"));

      cmp1.Name = "Color";
      cmp1.Type = new CodeTypeReference(typeof(string));
      cmp1.Attributes = MemberAttributes.Public;
      cmp1.GetStatements.Add(new CodeSnippetExpression("return \"" + selectioncolorNode + "\""));

      cmp2.Name = "Doors";
      cmp2.Type = new CodeTypeReference(typeof(int));
      cmp2.Attributes = MemberAttributes.Public;
      cmp2.GetStatements.Add(new CodeSnippetExpression("return" + selectionDoorNode));

      cmm1.Name = "Go";
      cmm1.ReturnType = new CodeTypeReference(typeof(int));
      cmm1.Attributes = MemberAttributes.Public;
      cmm1.Statements.Add(new CodeSnippetExpression("return" + selectionSpeedNode));

      CodeTypeDeclaration ctd = new CodeTypeDeclaration(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);
    }

  }
}
web.config Code :
Code:
<configuration>
  <system.web>
    <compilation debug="false">
      <buildProviders>
        <add extension=".car" type="CarBuildProvider.Car"/>
      </buildProviders>
    </compilation>
  </system.web>
</configuration>
and .car code :
Code:
<?xml version="1.0" encoding="utf-8" ?>
<car name="EvjenCar">
  <color>Blue</color>
  <door>4</door>
  <speed>150</speed>
</car>

Last edited by kafshdoozak; January 27th, 2013 at 04:53 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Web.config.. ashokparchuri General .NET 10 April 30th, 2011 05:14 AM
Web.config Error Janhemberg@hotmail.com BOOK: Beginning ASP.NET 4 : in C# and VB 3 August 6th, 2010 03:12 AM
Fix for Web.config Error in ...\Chapter01\LINQforBinding Web Sites rogerj BOOK: Professional ADO.NET 3.5 with LINQ and the Entity Framework ISBN: 978-0-470-22988-0 0 February 18th, 2009 01:59 PM
web.config error koco ASP.NET 2.0 Basics 1 February 16th, 2007 12:04 PM
Web.config error ashokparchuri General .NET 4 June 28th, 2005 04:51 AM





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