0%

Please refer to this article (http://blogs.msdn.com/jasonz/archive/2004/05/31/145105.aspx).

Memory consumption been eating more and more?

1
2
3
4
do
{
Assembly.LoadFrom("Library1.dll");
}while( true );

The result is NO. It will only keep a copy of Library1 Assembly in Memory, And never been release.
But I need the plugin Mechanism for Load/Unload Assembly.

How to load and unload Library1 Assembly?
Step1: Create the Library1 Project.

1
2
3
4
5
6
7
8
[Serializable]
public class MyClass1
{
public string Test()
{
return "abc";
}
}

Step 2: Create the Test Project.

1
2
3
AppDomainSetup ads = new AppDomainSetup();
ShadowCopyFiles = "true";
var myAppDomain = AppDomain.CreateDomain("MyAppDomainName", null, ads);

The follow code will load Library1.dll file.

1
object proxy = myAppDomain.CreateInstanceFromAndUnwrap("Library1.dll", "Library1.MyClass1");

Invoke the Test Method.

1
2
MethodInfo mi = proxy.GetType().GetMethod("Test", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
string s = (string)mi.Invoke(proxy, new object[]{});

Unload the Library1.dll file.

1
AppDomain.Unload(myAppDomain);

If you use T1 Common Library. You can write the following simple code.

1
2
3
UnloadAssembly asm = UnloadAssembly.Load("Library1.dll");
UnloadClass cls = asm.GetUnloadClass("Library1.MyClass1");
string s = (string)cls.Invoke("Test");

If you run FastCGI and show following error:

1
2
3
4
5
6
7
8
FastCGI Error
The FastCGI Handler was unable to process the request.
--------------------------------------------------------------------------------
Error Details:
Could not find entry for "php" on site 2043809562 in [Types] section.
Error Number: 1413 (0x80070585).
HTTP Error 500 - Server Error.
Internet Information Services (IIS)

You can modify C:\WINDOWS\system32\inetsrv\fcgiext.ini file:

1
2
3
4
5
6
7
8
9
[Types]
php=PHP

[PHP]
ExePath=C:\Devp\PHP\php-cgi.exe
InstanceMaxRequests=10000
ActivityTimeout=300
RequestTimeout=300
EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000,PHPRC:C:\Devp\PHP\

If you ever get a message like this when trying to create a diagram in SQL 2005/2008 Express.

Database diagram support objects cannot be installed because this database does not have a valid owner.

To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.

Here’s step by step what you have to do:

1
2
3
4
5
6
7
8
EXEC sp_dbcmptlevel 'yourDB', '90';
go
ALTER AUTHORIZATION ON DATABASE::yourDB TO "yourLogin"
go
use [yourDB]
go
EXECUTE AS USER = N'dbo' REVERT
go

1
2
3
<Target Name="BeforeBuild">
<Message Text="Justin Dearing Message" />
<Target/>

However, the messages don’t show up in the Visual Studio .NET build output.

To change the build output verbosity shown in the VS.NET output window, open the Options dialog and select the Build and Run settings below the Projects and Solutions node.

options dialog

Unless you explicitly specify a low message importance, your messages should show up at Normal verbosity or higher.

When I try to render a view whose model type is specified as: @model dynamic

by using the following code:

1
@{ Html.RenderPartial("PartialView", Model.UserProfile); }

I get the following exception:

‘System.Web.Mvc.HtmlHelper‘ has no applicable method named ‘RenderPartial’
but appears to have an extension method by that name.
Extension methods cannot be dynamically dispatched.
Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

Answer: It appears that the view where I was placing the RenderPartial code had a dynamic model, and thus, MVC couldn’t choose the correct method to use. Casting the model in the RenderPartial call to the correct type fixed the issue.

1
2
@Html.Partial("_PartialView", (ModelClass)View.UserProfile)
@{ Html.RenderPartial("PartialView", (ModelClass)Model.UserProfile); }

When you send the anonymous type model to the view:

1
return View(new {x=4, y=6});

It show that using anonymous types is not supported, however, there is a workaround, you can use an ExpandoObject, convert it to Expando

1
2
using T1.Web.Mvc4;
return View(new {x=4, y=6}.ToExpando());

If we use Asp.net Web Application (File -> New-> Project-> Asp.net Web Application), we can add Global.asax as well as Global.asax.cs file.

However, if we use Asp.net Web site (File->New->Website->Asp.net Website), it is not the case. By default we will have Global.asax file only and not the Global.asax.cs file.

The structure of the Global.asax file is as under

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
}
</script>

So how can we add a Global.asax.cs file for a Asp.net Web site project? Let us observer the same in the below steps

Step 1: Right click App_Code -> Add New Item -> Class -> Rename it as Global.cs . Then click on the Add button.

Step 2: In the Global.cs file that got created, decorate it by inheriting the class from System.Web.HttpApplication

So the Global.asax.cs file will now look like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class Global : System.Web.HttpApplication
{
public Global()
{
// TODO: Add constructor logic here
}

protected void Application_Start(object sender, EventArgs e)
{
}

protected void Session_Start(object sender, EventArgs e)
{
}

protected void Session_End(object sender, EventArgs e)
{
}

protected void Application_End(object sender, EventArgs e)
{
}
}

Step 3: Now, from the Global.asax file, remove the entire script code and change the

1
<%@ Application Language="C#" %>

to

1
<%@ Application Language="C#" CodeBehind="~/App_Code/Global.asax.cs" Inherits="Global" %>

That’s it. Now run the application and it will work
Hope this helps atleast for the newbies. Happy coding.

This morning I faced a problem while creating my Visual Studio 2012 Library Project. It said “no exports were found that match the constraint contract name”

I solved this problem by clearing Visual Studio Component Model Cache. Just delete or rename this folder:

%AppData%..\Local\Microsoft\VisualStudio\11.0\ComponentModelCache

Visual Studio Express 2012 has different paths. Visual Studio Express

…\Users{user}\AppData\Local\Microsoft\WDExpress\11.0\ComponentModelCache

With Visual Studio Express 2012 for Web

…\Users{user}\AppData\Local\Microsoft\VWDExpress\11.0\ComponentModelCache

When I running MyWebSite in .NET 4.0 and I can’t get it working.

HTTP error 500.22-Internal Server Error
Detect ASP.NET setting does not apply to integrated Managed pipeline mode.

If you still need to use the HTTP Module you need to configure it (.NET 4.0 framework) as follows:

1
2
3
4
5
6
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="MyModule" type="<<Namespace>>.<<Class>>, <<assembly>>"/>
</modules>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>

Declare variables

1
2
var i:number = 1;
var s:string = "text";

interface and class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
interface IPersion{
firtname: string;
lastname: string;
}

class Student implements IPersion{
firtname: string;
lastname: string;

constructor(public name: string){
this.firstname = name;
this.lastname = "Student";
}
sayName()
{
return "Student";
}
}

class Teacher extends Student{
constructor()
{
super("Flash");
this.lastname = "Teacher";
}

sayName()
{
return "Teacher";
}
}

static method

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class utils{
public static CopyProperties(source: any, target: any): void {
for (var prop in source) {
if (target[prop] !== undefined) {
target[prop] = source[prop];
}
else {
console.error("Cannot set undefined property: " + prop);
}
}
}
}

utils.CopyProperties(source, dest);

create module in math.ts

1
2
3
4
5
6
module math{
export function MathAdd(a:number, b:number)
{
return a+b;
}
}

use math module in test.ts

1
2
/// <reference path="math.ts" />
var c:number = math.MathAdd(1, 2);

create module in file1.ts

1
2
3
4
export function MathAdd(a:number, b:number)
{
return a+b;
}

use file1 file module in test.ts

1
2
import f1 = module('file1')
var c:number = f1.MathAdd(1, 2);

Powershell: dir file whose File size is greater than 1024KB

The following example perform is will list the files with .pdf extensions. where-object will filter the result set to files with length greater than 1MB. format-table will format the final output to display only the name of the file

1
ls *.pdf -Recurse | where-object {$_.length -gt 1048576} | format-table -property Name

Compile-on-Save With TypeScript 0.8.2, we’ve enabled the ability to compile a project when source files in the project are saved, circumventing the usual manual compile step.

Download TypeScript for Visual Studio 2012 and 2013 http://www.microsoft.com/en-us/download/details.aspx?id=34790

For this to work, you need to enable the global setting in Tools->Options->Text Editor->TypeScript->Project. Specifically, enable “Automatically compile TypeScript files which are part of a project”.

Next, you need to make sure your Visual Studio project uses the new TypeScript targets file. You can do this in one of two ways. New projects created with the TypeScript 0.8.2 release will automatically include a link to this targets file (as will the new version of the Windows 8 sample in the samples directory). For projects made with previous versions, you will need to edit the project file by right-clicking the project, selecting “Unload Project”, right-clicking the project, selecting “Edit”, and updating the project XML with the following:

For each TypeScript file in your project, change the build action to ‘TypeScriptCompile’:

<TypeScriptCompile Include="app.ts" />

Then additionally add (or replace if you had an older PreBuild action for TypeScript) the following at the end of your project file to include TypeScript compilation in your project.

For JavaScript projects (.jsproj):

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.VisualStudio.$(WMSJSProject).targets" />
  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptIncludeComments>true</TypeScriptIncludeComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptIncludeComments>false</TypeScriptIncludeComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
  </PropertyGroup>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" />

For C#-style projects (.csproj):

 <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptIncludeComments>true</TypeScriptIncludeComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptIncludeComments>false</TypeScriptIncludeComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
  </PropertyGroup>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" />

PS:Web Essentials 2012 is a feature of Visual Studio 2012 expansion plug For v3.0: Remove all support for the TypeScript (http://madskristensen.net/post/Web-Essentials-2013-Where-is-the-TypeScript-support.aspx) This was because many of those features were built directly in to Visual Studio 2013 and therefore no longer needed support by Web Essentials.

The repository for high quality TypeScript type definitions. https://github.com/borisyankov/DefinitelyTyped#readme

Usage: Include a line like this:

/// <reference path="jquery.d.ts" />