Subscribe to Feed

 

You can invoke a C# or a managed .Net dll from a Native application written in VC++ or C++ in several ways. Here are the three main ways you can use to achieve this.

  1. Use a C++/CLI wrapper
  2. Host CLR (Common Language Runtime)
  3. Convert .NET assembly to a COM server, and call it from C++ through .NET-COM interop

1. Use of C++/CLI Wrapper

C++/CLI is a self-contained, component-based dynamic programming language that, like C# or Java, is derived from C++. You can say that C++/CLI is to C++ as C++ is to C. In essence, it is how you do .NET programming using C++ rather than using C# or VB or several other languages. To learn more about C++/CLI refer to the following articles.

2. Host CLR

Hosting CLR is basically using entire CLR as a library and loading it into your application host process. This will allow your application to contain the whole CLR virtual machine and loads assemblies and run managed code with in the virtual machine. Once you load the CLR into your application, the host process is now responsible for defining the application domains with in the process and executing user code within these domains. For more information related about CLE hosting, refer to this CLR Inside Out article on MSDN.

 

Related titles:

  • How to invoke a .Net assembly from a Native application?
  • How to invoke a VB.Net dll from a C++ application?
  • How to use a managed dll in a native application?

 

By default, Asp.Net specifies a limit for the input stream buffering threshold. This limit can be used to prevent denial of service attacks that are caused, for example by users posting large files to the server. The default value for this is 4096 kb. If the threshold is exceeded, you get a ConfigurationErrorsExeption with a message similar to the one in the title.

You can change the the Maximum request length and several other HTTP runtime parameters for an ASP.NET application by specifying them in the web.config. For example, here is how you can set the maximum allowed request length in web.config:

 

<configuration>
  <system.web>
  <httpRuntime maxRequestLength="8192"
    enable = "True"
    requestLengthDiskThreshold="512
    useFullyQualifiedRedirectUrl="True"
    executionTimeout="45"
    versionHeader="1.1.4128"/>
  </system.web>
</configuration>

 

The httpRuntime element is not explicitly defined in the Machine.config file or in the root Web.config file. However, the default values as initialized by the system.

For more information refer to MSDN page at: http://msdn.microsoft.com/en-us/library/e1f13641.aspx

Hope this helps.

 

There usually are several occasions where you might want to loop through all the controls in a container like a panel or a form etc.. looking for a particular type of control. For example, lets say you have a panel on your form which has several CheckBoxes in it, and you wish to find out all the checkboxes that are checked, here is how you can do it (Name of the panel is panel1)

 

foreach (Control box in panel1.Controls)
{
       if (box is CheckBox)
       {
              if (((CheckBox)box).Checked)
                  Console.WriteLine(box.Name + " is Checked");
        }
 }

 

You can replace the panel1 here with your own container like a Form or GroupBox or LayOutPanel etc.

Hoe this helps.

 

Escaping XML text basically means we are trying to replace the “<”, “>” etc. characters that are used to construct the XML with the encoded values. Here are the 5 values that we care about

XML Value Encoded Value
< &lt;
> &gt;
&quot;
&apos;
& &amp;

There are several ways in which you can escape an XML file or string in .Net.

 

1. Using Regular Expression and do a string.Replace()

This is a brute force method but works as expected.

string xmlData = "<Root><Node Name=\"MyNode\">I am \"xml\" data & I have one Node.</Node></Root>"

string escapedXmlData = xmlData.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;"); 

 

//Output: &lt;Root&gt;&gt;Node Name=&quot;MyNode&quot;&gt;I am &quot;xml&quot; data &amp; I have one node. &lt;\Node&gt;&lt;Root&gt;

One caveat here is, if you look at the replace sequence above, you should see that we are starting the first replace with ‘&amp;’. This is because we should avoid replacing the ‘&’ in the encoded values.

You can also use the RegEx.Replace to achieve the same behavior.

2. innerText property of the XmlDocument object

When you read in XML data using XmlDocument object, the innerText property will always return the escaped XML text.

string xmlData = "<Root><Node Name=\"MyNode\">I am \"xml\" data & I have one Node.</Node></Root>";

XmlDocument myXmlDoc = new XmlDocument();

myXmlDoc.Load(xmlData);

string escapedXml = myXmlDoc.InnerText);

 

// Output: escapedXml = &lt;Root&gt;&gt;Node Name=&quot;MyNode&quot;&gt;I am &quot;xml&quot; data &amp; I have one node. &lt;\Node&gt;&lt;Root&gt;

One thing to consider here, using XmlDocumnet object is expensive and you should consider using it only if you are also doing other XML manipulation stuff on your XML data that require XmlDocument API.

3. Using XmlWriter object

You can also use the XmlWriter object to write escaped Xml data into a StringWriter

string xmlData = "<Root><Node Name=\"MyNode\">
                  I am \"xml\" data & I have one Node.</Node></Root>";
StringBuilder escapedXml = new StringBuilder (xmlData.Length);
using (var writer = XmlWriter.Create(escapedXml))
{
writer.WriteString(xmlData);
}

4. Using System.Security.SecurityElement.Escape() method

string xmlData = "<Root>
                     <Node Name=\"MyNode\">
                         I am \"xml\" data & I have one Node.
                     </Node>
                 </Root>";
string escapedXml = System.Security.SecurityElement.Escape(xmlData);

 

Hope this helps.

 

If you are trying to troubleshoot problems occurred in you .Net application, especially if they are caused by ASP.net, you are now in luck. Microsoft recently released an extension for WinDbg that will allow you to diagnose high-memory issues, high-CPU issues, crashes, hangs and many other problems that might occur in a Asp.NET application. This extension is of great help especially if you only have access to the dump files for your application. You can read more and download the PssCor2 windbg extension from MSDN site here.

If you are familiar with SOS.dll, the managed-debugging extension that ships with the .NET Framework, Psscor2.dll provides a superset of that functionality. Most of the added functionality helps you identify issues in ASP.NET.

To name some you can use the PssCor2 to view stuff like

  • managed call stacks (with source mappings)
  • managed exception information
  • what types are in the managed heap and their reference chain
  • which ASP.NET pages are running on which thread
  • the contents of the ASP.NET cache
  • etc..

    Note: Psscor2 supports debugging applications running on .NET Framework versions 2, 3, and 3.5. You will also need to have the Debugging Tools for Windows installed to be able to use PssCor2.

    Hope this helps.

    Reference: Psscor2 Managed-Code Debugging Extension for WinDbg on MSDN

     

    It is very simple to get the name of the application pool current worker process is associated with in Asp.NET. You can simple use the server variables for that. For example, to display the app pool name on your web page you can simply use the below code snippet.

    <%= Request.ServerVariables("APP_POOL_ID") %>

     

    This is usually helpful when you are trying to debug permission issues in your application or change something in your web application based of the current application pool being used.

    Hope this helps

     

    When you create a new ATL project in Visual Studio 2010, IDE generated StdAfx.h does not include the ATL namespace by default. Because of this behavior, when you try to use any ATL API (Like CComBstr for example) in your main cpp file, the build will fail with several “Undeclared Identifier” errors. Any existing project created using earlier versions of Visual Studio, upgraded to VS 2010 should build fine because all the previous Visual Studios used to include the “using namespace ATL” statement in IDE generated StdAfx.h.

    To fix this, you can either add “using namespace ATL” statement in your StdAfx.h file or add it in the main cpp file of the project. It is suggested that you always add it in the main cpp file instead of the StdAfx.h to avoid conflicts with similar classes in MFC which does not have a namespace.

    Hope this helps.

     

    I just got this email from Microsoft. Hope this helps some one waiting to get certified for .Net Framework 4 Development. It seems slots are very limit, register asap.

    You are invited to take part in one or more beta exams for Visual Studio 2010 and the Microsoft .NET Framework 4.

    If you pass one of the beta exams, the exam credit will be added to your transcript and you will not need to take the exam in its released form. The 71-xxx identifier is used for registering for beta versions of MCP exams, when the exam is released in its final form the 70-xxx identifier is used for registration.
    By participating in beta exams, you have the opportunity to provide the Microsoft Certification program with feedback about exam content, which is integral to development of exams in their released version. We depend on the contributions of experienced IT professionals and developers as we continually improve exam content and maintain the value of Microsoft certifications. The following exams are a part of this beta offering.

    Exam 71-511, TS: Windows Applications Development with Microsoft .NET Framework 4

    Exam 71-515, TS: Web Applications Development with Microsoft .NET Framework 4

    Exam 70-513: TS: Windows Communication Foundation Development with Microsoft .NET Framework 4

    Exam 70-516: TS: Accessing Data with Microsoft .NET Framework 4

    Exam 70-518: Pro: Designing and Developing Windows Applications Using Microsoft .NET Framework 4

    Exam 70-519: Pro: Designing and Developing Web Applications Using Microsoft .NET Framework 4


    Availability

    Registration begins: March 17, 2010

    Beta exam period runs: April 5, 2010 - April 30, 2010

    Receiving this invitation does not guarantee you a seat in the beta; we recommend that you register as soon as registration opens. Beta exams have limited availability and are operated under a first-come-first-served basis. Once all beta slots are filled, no additional seats will be offered. If you register, please ensure you are committed to attend.

    Testing is held at Prometric testing centers worldwide, although this exam may not be available in all countries (see Regional Restrictions). All testing centers will have the capability to offer this exam in its live version.

    Regional Restrictions: India, Pakistan, China


    Registration Information

    You must register at least 24 hours prior to taking the exam.
    Please use the following promotional codes when registering for your chosen exam(s):

    Exam Number

    Beta Code

    70-511

    511BC

    70-515

    515AA

    70-513

    513CD

    70-516

    516B1

    70-518

    518PE

    70-519

    519ZS

    To register in North America, please call:

    .

    Prometric: (800) 755-EXAM (800-755-3926)

    Outside the U.S./Canada, please contact:

    .

    Prometric: http://www.register.prometric.com/ClientInformation.asp


    Test Information and Support

    You are invited to take this beta exam at no charge.
    You will be given four hours to complete the beta exam. Please plan accordingly.

    Find exam preparation information:

    Exam 71-511, TS: Windows Applications Development with Microsoft .NET Framework 4

    Exam 71-515, TS: Web Applications Development with Microsoft .NET Framework 4

    Exam 70-513: TS: Windows Communication Foundation Development with Microsoft .NET Framework 4

    Exam 70-516: TS: Accessing Data with Microsoft .NET Framework 4

    Exam 70-518: Pro: Designing and Developing Windows Applications Using Microsoft .NET Framework 4

    Exam 70-519: Pro: Designing and Developing Web Applications Using Microsoft .NET Framework 4


    Frequently Asked Questions

    For Microsoft Certified Professional (MCP) help and information, you may log in to the MCP Web site at http://www.microsoft.com/learning/mcp/or contact your Regional Service Center: http://www.microsoft.com/learning/support/worldsites.asp.

    .

    What is a beta exam?

    .

    Where can I learn more about the registration process?

    .

    Where can I learn more about the beta exam invitation process?

    .

    Where can I learn more about the new structure of Microsoft Certification?

    .

    Who do I contact for help with this beta exam or other MCP questions?

     

    You can use Microsoft.Web.Administration namespace to create a binding and set the certificate hash. Let us say you are trying to add a new binding to a website “MySite” with a new SSL certificate hash “MyCertHash”, here is what you have to do to achieve this

    ServerManager serverManager = new ServerManager();
    serverManager.Sites["MySite"].Bindings.Add("*.443:", MyCertHash, "MyCert");

    The bindings member configures binding information for an IIS 7.0 Web site. You can also add multiple bindings to a website or use similar approach to add other bindings.

     

    On some occasions you might want to deploy the Asp.Net MVC application to avoid compiling it yourself etc. You can achieve this by following the below steps

    1. Create an ASP.NET website project in Visual Studio
    2. Add a reference to the System.Web.Mvc.dll (and any other DLLs that your application might need)
    3. Copy the web.config from regular ASP.NET MVC project and make all additional changes that you  need for your web application.
    4. Place all your controllers and models in ~/App_Code folder.
    5. Place all your views ~/Views/Home/Index.aspx (The usual location where Views are in a regular MVC application)
    6. Run the application and you are good to go.

    Of course there are couple of limitations to this approach like You will not get the addition tooling support from Visual Studio that it usually provides for an MVC.

     

     

    Subscribe to Feed

    Categories

    Links

    Dev Jobs