.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Proper order of a class members, generated via System.CodeDom

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :.NET Framework

I use System.CodeDom to dynamically create a C++/CLI class and fill it with fields and methods. 

When I fill methods with statements, everything is fine. However, when I insert class fields, I run into a problem of order.


For example, the following lines

CodeTypeDelegate delegateDecl = new CodeTypeDelegate("delegate_name");

CodeMemberField delegateField = new CodeMemberField(new CodeTypeReference(delegateDecl.Name), "delegate_field");

codeType.Members.Add(delegateDecl);    /// the order of insertion - delegate declaration first !!!

codeType.Members.Add(delegateField);   /// the order of insertion - field with the delegate usage second!!!

generates the following code:

    public ref class classA


View Complete Post

More Related Resource Links

Class Templates: Bring the Power of Templates to Your .NET Applications with the CodeDOM Namespace


In the .NET Framework, the CodeDOM object model can represent code in a variety of languages. This article examines how source code templates written with the Framework's System.CodeDom and System.CodeDom.Compiler namespaces allow developers to create reusable boilerplate source code that can be shared between projects. Components designed via templates improve productivity and shorten development time.Here C++-style classes and templates are simulated and code is generated in multiple languages through the creation of CodeDOM object graphs. Compiling object graphs and formatting output code are also explained.

Adam J. Steinert

MSDN Magazine February 2003

Working with System.IO.Path static class

Hello everyone. Today, I was exploring the System.IO namespace in .NET 4.0 on an ASP.NET web application where I came to few changes, comparing with the previous versions of .NET, related to the System.IO.Path static class. The Path class contains the same method names in .NET 2.0, 3.5 as well as 4.0, only (in .NET 4.0) new overloads are added to System.IO.Path.Combine() method. In the following blog post, I will show the usage of few methods belonging to the System.IO.Path static class, as well as, the changes in Combine() method added in .NET 4.0. Besides the first method that is available in the previous versions for combining two string paths, now in .NET 4.0 you can combine unlimited strings to the path. Note: For testing purpose, on your web application root, create folders with name Files, Files/SubFolder, Files/SubSubFolder and add three text files: text1.txt (in Files), text2.txt (in Files/SubFolder), text3.txt (in Files/SubFolder/SubSubFolder).   Here are few examples:             string path1 = System.IO.Path.Combine(Server.MapPath("Files"), "text1.txt"); //this will give the path to %WEBAPP_ROOT%/Files/text1.text -             string path2 = System.IO.Path.Combine(Server.MapPath("Files"), "SubFolder", "text2.txt"); //this will give

Prompt "The proper type library could not be found in the system registry" when open SQL2008 Express

Hi folks, I just format my notebook and installed the Win7Pro Eng 32-bit version and then install the SQL2008Express. I restarted my notebook as usual after the installation and open the SQL SMS, it prompt the following error "The proper type library could not be found in the system registry", It's a big dialog with certain text saying I do not have permission...etc. Since, I am using administrator account to open the program already but still fail. I have to repaire the SQL SMS too. May I know any other I can check? Any comment is highly appreciated. Thank you very much! Regards, Tony  

T-SQL 2005 datetime as Mmm-YYYY and proper Order By?

Hi I have datetime column in SQL 2005 table. I want to convert that date time into Mmm-YYYY format i.e. Jan-2010, May-2010, Dec-2010 and then proper ORDER BY in month ordering ( in my actual query I want data to be GROUP BY month & year) Table has OrderDate colmin with type datetime Query result output I am looking is : OrderDate       OrderDateMonthYYYY   ORDER BY too 2010-01-25     Jan-2010 2010-02-15     Feb-2010 2010-08-15     Aug-2010 Any T-SQL 2005 Pls…  

Can I use class members for data or do I need to use Variable?

I have a class derived from CodeActivity that creates some objects in its constructor which will be used by Execute. These objects are exposed as properties so I can fake them for unit tests. In a code review a colleague suggested that I might need to make all of those objects Variable<T> "for them to play nicely in WF (with all the threading etc. going on)", but wasn't sure on that. Do I need to make these Variable<T>? If not, when would I want to use Variable<T> in a CodeActivity?

InvalidOperationException using auto-generated class

I'm getting the below exception while trying to create an instance of  XmlSerializer using the class generated from XsdObjecGen. Any ideas on what may be causing this? System.InvalidOperationException: There was an error reflecting field '__ApplicationArea'. ---> System.InvalidOperationException: There was an error reflecting type 'ConsoleApplication2.Oagis.ApplicationArea'. ---> System.InvalidOperationException: There was an error reflecting field '__Sender'. ---> System.InvalidOperationException: There was an error reflecting type 'ConsoleApplication2.Oagis.Sender'. ---> System.InvalidOperationException: There was an error reflecting field '__LogicalID'. ---> System.InvalidOperationException: There was an error reflecting type 'ConsoleApplication2.Oagis.LogicalID'. ---> System.InvalidOperationException: There was an error reflecting field '__Value'. ---> System.InvalidOperationException: There was an error reflecting type 'System.String'. ---> System.InvalidOperationException: Value 'String' cannot be used for the XmlElementAttribute.DataType property. The datatype 'http://www.w3.org/2001/XMLSchema:String' is missing. The code in question from the exception.. '*********************** XmlText field *********************** <XmlText(DataType:="String"), _ EditorBrowsable(EditorBrowsableState.Advance

spmetal generated class and content type (for page layout) retrieve problem


I'm working with a console application to generate my sites and subsites (hierarchy). And i've got a problem with a generated spmetal class.


this doesn't work:


static void Main(string[] args)


            string SITE = string.Concat("http://"Environment.MachineName);         



class contains non-dependency-property data members that are DependencyObject objects, you must also


I was reading the article Freezable Objects Overviewand came acrosee the statement

"If  your class contains non-dependency-property data members that are DependencyObject objects, you must also call the OnFreezablePropertyChanged method each time you change on of their values, even if you're setting the member to null. "

I quite do not understand the part about non-dependency-property data members that are DependencyObject objects. Can some one explain exactly what this means? If a data member is derived from the DependencyObject  class how then can the data member be a non dependency property?

I am also trying to locate some source code / project that overrides the OnFreezablePropertyChanged method, and have yet to find any on the interenet.

If anyone know whe

Serializing / Storing VS2010 generated WCF Proxy Class reference in SQL SessionState



I have a WCF 4 service being consumed by an ASP.NET 3.5 (SharePoint 2010 actually) application.

Because we have implemented session support in the WCF service (ws2007HttpBinding) to maintain some objects that are very expensive to intialize, I'm also trying to keep my service client reference persisted on the ASP.NET consumer-side. However in order to persist it across post-backs, I need to add it to the session (using SharePoint's SQL SessionState provider), and this causes serialization (binary serialization) of the WCF service referece.

The ASP.NET application is throwing an error, because it cannot serialize the WCF service reference.

Any thoughts?

Use System.Drawing class



How can I to use System.Drawing.Bitmap class into athoer class?

using System.Data;
using System.Collections;
using System.Globalization;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace University
    public class Class1

      System.Drawing.Bitmap BMP=new System.Drawing .Bitmap();



when I use System.Drawing.Bitmap gives error this class does not exists !!!!!!!!

TT Template files not proper generated in website


When I use TT files to generate code, output files within Websites ar never properly generated.

The resut is always some "Chinese character garbage", and the generated extension is always .cs (whatever the given outputextension may be)

Generating text files works fine in class libraries, MVC websites and  other "projects".

Just not in plain websites. Is this a known issue, am I forgetting some swith or doing something wrong, can or can I not fix this?



It seems to be a problem with the Tangible T4 Editor,

after uninstalling this tool, it seems to work fine. However, I've lost syntax highlighting and intellisense then.

Since this is an external tool, I don't think this forum covers that scope.


Web Service to inherit from a Custom Base Class that inherits System.Web.Services.WebMethod instead


Hi All,

Recently, I tried to get my Web Service class to inherit from a custom base class that inherits from System.Web.Services.WebMethod instead of the System.Web.Services.WebMethod directly.

However, I've been getting Error 500.

Public Class Service1
    Inherits BaseClass
    <System.Web.Services.WebMethod()> _
    Public Function GetSessionID() As String
        GetSessionID = Me.Session.SessionID
    End Function
End Class


public class BaseClass
    Inherits System.Web.Services.WebService

    public property Property1 as string
    public property Property2 as string

End Class


Please kindly assist.

Thank you in advance.

Warmest Regards,


Unable to cast COM oject of type 'System.__ComObject' to class type of 'System.Drawing.Bitmap' .

 private void DirectXViewer_DragDrop(object sender, DragEventArgs e)


   mousePressedFlag = false;



    Object obj = e.Data.GetData(typeof(Bitmap));





      Bitmap image = (Bitmap)((Bitmap)obj).Clone();

      RenderImage = image;



     catch(Exception ex)








private void DirectXViewer_MouseMove(object sender, MouseEventArgs e)


   if (mousePressedFlag)


    if(cacheBitmap != null)

     this.DoDragDrop(new Bitmap(cacheBitmap), DragDropEffects.Copy);




Hi All,

I try to d

COM Object Interop DLL generated on Visual Studio 2010 does not work on 64-bit system



When I add a COM object Example.dll as reference, it will automatically generate a file called Interop.ExampleLib.dll to my bin folder. It works fine on 32-bit system but when I try it on a 64-bit my program fails to run.

I replaced the Interop.ExampleLib.dll with one that I generated a while ago using Visual Studio 2008, and it works on both 32 and 64-bit system.

Anyone knows what's the problem?

Thanks in advance!




Problem with Removing Byte Order Mark in Beginning of XML generated by SQL


The problem:  --> When we Transmit our XML File to our trading partner they are complaining the first 3 bytes of the file contain ascii characters (239 (187) (191) ... and they are rejecting our File

These are non printable characters seemingly generated automatically by .net Framework.  Our process is the following:

1) We call a stored proceedure that generates sql via xml document object.  The insertion of the btye order seems to occur when converting the String to XML.  Does anyone know a way to prevent this "automatic" insertion of the byte order (non visble).

Private Function SaveXMLFile(ByVal sXML As String, ByVal sFile As String, ByVal sId As String) As Boolean
        Dim m_xmld As XmlDocument
        Dim bErr As Boolean = False

        'Create the XML Document
        m_xmld = New XmlDocument()


            Dim byteArray As Byte() = System.Text.Encoding.Unicode.GetBytes(sXML)
            Dim UTF8Bytes As Byte() = System.Text.Encoding.Convert(System.Text

How to convert image class object to byte type in order to insert database


I am trying to resize images after uploading and than inserting them into my database.

Dim newMainImage As System.IO.Stream = System.IO.Stream.Null
resizedMainImage.Save(newMainImage, jgpEncoder, myEncoderParameters)
Dim newMain As Image = Image.FromStream(newMainImage)

I was able to resize it however I couldnt find a way to convert image object to byte() in order to

I need something like

Dim ImageContent(newMain.ContentLength - 1) As Byte

newMain.InputStream.Read(ImageContent, 0 , newMain.ContentLength)

I need to convert image object to a file type in order to get its contentlenght and use .inputStream.Read function. Or is there any other way?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend