显示标签为“C#”的博文。显示所有博文
显示标签为“C#”的博文。显示所有博文

2009年3月14日星期六

Is it possible to deploy a .NET exe without installing .NET framework

在没有安装.NET Framework的平台上运行.NET程序,问题是可能吗?
答案是:没有不可能。
C#的出现是为了与Java抗衡,和Java一样,需要安装虚拟机平台来运行。如果没有CLR,似乎是不行的。但是如果将所有需要的dll都拷贝过来,将其他的所有设置相关的内容都拷贝过来,集成到exe中,不就可以了吗?

怎么做呢?Google Thinstall to Check the detail.
其他的包括

Static Compilation in Mono

Xenocode(Deploy your .NET app securely, with no Framework install ),
Remotesoft(Salamander .NET Linker, Native Compiler and Mini-Deployment Tool)

Thinstall软件已经被VMWare收购了。

.NET framework virtualization

Deploy and run .NET applications - with out installing the .NET framework. Run applications that require different versions of .NET, concurrently, without conflicts and protect code from dissassembly.

Challenges

Developing with the latest release of the .NET framework offers clear advantages. However, deploying an application requiring the latest .NET can present challenges due to a number issues including:

  • Other applications require an earlier version of .NET
  • Locked down desktops can not be upgraded immediately
  • Computers may need to have different versions of .NET installed concurrently

Whether a commercial application distributed to home computers or a custom application to corporate locked down computers, the correct version of the .NET framework - or any of the .NET components - may not be installed. This presents challenges in terms of updating, running, and installing applications and also problems when applications require different .NET versions to be installed.

VMware ThinApp Solution (Formerly Thinstall)

ThinApp provides essential features that make .NET deployments conflict free and secure. Benefits include:

  • Not requiring the .NET Framework to be installed. By packaging the application and linking the .NET framework with ThinApp, no installation of the .NET framework is required. The application runs without modifying the host computer.
  • Eliminating all installation errors and conflicts. ThinApp enables applications to run concurrently that each require a different version of .NET to be installed.
  • Reducing download and installation time. ThinApp packages all of the .NET framework or only the components that the program needs into a single, compressed EXE. This not only reduces the size of the components that need to be installed (and downloaded), but also makes ‘installation’ significantly faster. Nothing is installed, rather the program is run via the ThinApp Virtual Operating System.

Additionally, even applications created for internal corporate use at some point may be distributed externally. .NET applications can be easily disassembled with readily available developer tools that make inspection of source code easy, enabling hacking and reverse engineering relatively simple for any experienced programmer.

ThinApp also protects against hacking and disassembly. Rather than using obfuscation, ThinApp instead encrypts the .NET Program inside of secure loader which prevents disassembly. The resulting EXE no longer appears to be a .NET Program so codedisassemblers are unable to decrypt the program stored inside.

2009年3月4日星期三

一个可能的原因:Additional information: Cannot access a disposed object.

编译正常,但是在执行CSharp程序的时候却出现了Additional information: Cannot access a disposed object.

检查错误,是自己在Load程序中新建了一个Form对象,使用了Show(),改为ShowDialog()后正常。

Built successfully, but fail to run.
change the frmSomething.Show()
into frmSomething.ShowDialog();
Things are OK.

2009年2月26日星期四

修改堆栈的大小,避免程序调用函数时出现System.StackOverflowException错误

System.StackOverflowException异常通常出现在死循环处。
但是这次我的程序显示异常出现在程序定义行,因为我有一个类里面定义了一个很大的数组。
C#等编译器在编译的时候并没有修改堆栈大小的选项,默认的堆栈大小是1MB,但是可以通过
EditBin.exe程序修改默认的堆栈大小。
如某人的测试:

That works.

Test:

class App {
private static long _Depth = 0;

private static void GoDeep() {
if ((++_Depth % 10000) == 0) System.Console.WriteLine("Depth is " +
_Depth.ToString());
GoDeep();
return;
}

public static void Main() {
try {
GoDeep();
} finally {
}
return;
}
}




editbin /stack:100000,1000 q.exe
Depth is 10000
Depth is 20000

Unhandled Exception: StackOverflowException.

editbin /stack:1000000,1000 q.exe
Depth is 10000
Depth is 20000
Depth is 30000
Depth is 40000
Depth is 50000
Depth is 60000
Depth is 70000
Depth is 80000

Unhandled Exception: StackOverflowException.

2008年1月18日星期五

c#访问googleAPI

  • 准备工作

要使用googleAPI 来开发自己的桌面应用程序,先要做下面的准备工作:

1. 首先在下面地址http://www.google.com/apis/download.html下载the Google Web APIs Developer's Kit

2. 然后在下面地址https://www.google.com/accounts/NewAccount?continue=http://api.google.com/createkey&followup=http://api.google.com/createkey注册一个 license key 以使用google提供的搜索服务。

  • 新建一个Google Search应用程序

1. 新建一个Windows From 项目命名为Google Search

2. 添加Web引用,以便使用google web services。具体做法是将下载的the Google Web APIs Developer's Kit中的GoogleSearch.wsdl文件放入本地的服务器上,然后在VS中右键点击资源管理器中的引用,再选择添加Web引用,然后输入GoogleSearch.wsdl文件在本机服务器上的地址http://localhost/GoogleSearch.wsdl,更改Web引用名为GoogleSearch后,点击添加引用后返回。

3. 进行界面设计,添加3个控件,TextBox(用于输入关键字)Button(用于提交信息),RichTextBox(用于显示搜索结果信息)。如图:

4. 编写事件处理。

1) 添加命名空间。using Google_Search.googlesearch;

2) 双击Button控件,在Button的事件处理中添加下面的代码:

1 try
2
3 {
4
5 GoogleSearchService s = new GoogleSearchService();
6
7 GoogleSearchResult r = s.doGoogleSearch("NGYfW7dQFHKshnXPwvctLsaipk03YK2x", textBox1.Text, 0, 10, true, "", true, "", "", "");
8
9 ResultElement[] re = r.resultElements;
10
11 foreach (ResultElement n in re)
12
13 {
14
15 richTextBox1.AppendText(n.title+"\r");
16
17 richTextBox1.AppendText(n.snippet+"\r");
18
19 richTextBox1.AppendText(n.URL);
20
21 richTextBox1.AppendText("\n\r\r");
22
23 }

24
25 }

26
27
28
29 catch(Exception ee)
30
31 {
32
33 MessageBox.Show(ee.Message);
34
35 }

36
37

3) 按ctrl+F5就能测试应用程序了。

l GoogleSearchServicesdoGoogleSearch方法

需要进行搜索先建立一个GoogleSearchServices 类的对象,然后调用doGoogleSearch方法取得信息。下面是google提供的对该方法的描述。

public doGoogleSearch(string key, string q, int start, int maxResults, bool filter, string restrict, bool safeSearch, string lr, string ie, string oe)

下面对各个参数进行介绍:

Key:这是由google提供的一个认证用的ID,可以在http://www.google.com/apis/申请。由于目前是测试阶段,每个ID一天只提供1000次的搜索服务请求。

q:这个就是要搜索的关键字。string类型

start:结果开始的索引数,从0开始。 int 类型

maxresults:返回的结果数的最大值,最大为10int 类型

filter:用于标识是否对搜索的结果进行过滤,所进行的过滤是对于同一主机上的内容只返回1—2个结果。bool类型

restrict:用于限定搜索的国家或地区,如果为空,表示不限制。string 类型。

下表将列出所有能选的代号。

国家

代号

国家

代号

国家

代号

国家

代号

Andorra

countryAD

Estonia

countryEE

Kazakhstan

countryKZ

Qatar

countryQA

United Arab Emirates

countryAE

Egypt

countryEG

Lao People's Democratic Republic

countryLA

Reunion

countryRE

Afghanistan

countryAF

Western Sahara

countryEH

Lebanon

countryLB

Romania

countryRO

Antigua and Barbuda

countryAG

Eritrea

countryER

Saint Lucia

countryLC

Russian Federation

countryRU

Anguilla

countryAI

Spain

countryES

Liechtenstein

countryLI

Rwanda

countryRW

Albania

countryAL

Ethiopia

countryET

Sri Lanka

countryLK

Saudi Arabia

countrySA

Armenia

countryAM

European Union

countryEU

Liberia

countryLR

Solomon Islands

countrySB

Netherlands Antilles

countryAN

Finland

countryFI

Lesotho

countryLS

Seychelles

countrySC

Angola

countryAO

Fiji

countryFJ

Lithuania

countryLT

Sudan

countrySD

Antarctica

countryAQ

Falkland Islands (Malvinas)

countryFK

Luxembourg

countryLU

Sweden

countrySE

Argentina

countryAR

Micronesia, Federated States of

countryFM

Latvia

countryLV

Singapore

countrySG

American Samoa

countryAS

Faroe Islands

countryFO

Libyan Arab Jamahiriya

countryLY

St. Helena

countrySH

Austria

countryAT

France

countryFR

Morocco

countryMA

Slovenia

countrySI

Australia

countryAU

France, Metropolitan

countryFX

Monaco

countryMC

Svalbard and Jan Mayen Islands

countrySJ

Aruba

countryAW

Gabon

countryGA

Moldova

countryMD

Slovakia (Slovak Republic)

countrySK

Azerbaijan

countryAZ

United Kingdom

countryUK

Madagascar

countryMG

Sierra Leone

countrySL

Bosnia and Herzegowina

countryBA

Grenada

countryGD

Marshall Islands

countryMH

San Marino

countrySM

Barbados

countryBB

Georgia

countryGE

Macedonia, The Former Yugoslav Republic of

countryMK

Senegal

countrySN

Bangladesh

countryBD

French Quiana

countryGF

Mali

countryML

Somalia

countrySO

Belgium

countryBE

Ghana

countryGH

Myanmar

countryMM

Suriname

countrySR

Burkina Faso

countryBF

Gibraltar

countryGI

Mongolia

countryMN

Sao Tome and Principe

countryST

Bulgaria

countryBG

Greenland

countryGL

Macau

countryMO

El Salvador

countrySV

Bahrain

countryBH

Gambia

countryGM

Northern Mariana Islands

countryMP

Syria

countrySY

Burundi

countryBI

Guinea

countryGN

Martinique

countryMQ

Swaziland

countrySZ

Benin

countryBJ

Guadeloupe

countryGP

Mauritania

countryMR

Turks and Caicos Islands

countryTC

Bermuda

countryBM

Equatorial Guinea

countryGQ

Montserrat

countryMS

Chad

countryTD

Brunei Darussalam

countryBN

Greece

countryGR

Malta

countryMT

French Southern Territories

countryTF

Bolivia

countryBO

South Georgia and the South Sandwich Islands

countryGS

Mauritius

countryMU

Togo

countryTG

Brazil

countryBR

Guatemala

countryGT

Maldives

countryMV

Thailand

countryTH

Bahamas

countryBS

Guam

countryGU

Malawi

countryMW

Tajikistan

countryTJ

Bhutan

countryBT

Guinea-Bissau

countryGW

Mexico

countryMX

Tokelau

countryTK

Bouvet Island

countryBV

Guyana

countryGY

Malaysia

countryMY

Turkmenistan

countryTM

Botswana

countryBW

Hong Kong

countryHK

Mozambique

countryMZ

Tunisia

countryTN

Belarus

countryBY

Heard and Mc Donald Islands

countryHM

Namibia

countryNA

Tonga

countryTO

Belize

countryBZ

Honduras

countryHN

New Caledonia

countryNC

East Timor

countryTP

Canada

countryCA

Croatia (local name: Hrvatska)

countryHR

Niger

countryNE

Turkey

countryTR

Cocos (Keeling) Islands

countryCC

Haiti

countryHT

Norfolk Island

countryNF

Trinidad and Tobago

countryTT

Congo, The Democratic Republic of the

countryCD

Hungary

countryHU

Nigeria

countryNG

Tuvalu

countryTV

Central African Republic

countryCF

Indonesia

countryID

Nicaragua

countryNI

Taiwan

countryTW

Congo

countryCG

Ireland

countryIE

Netherlands

countryNL

Tanzania

countryTZ

Switzerland

countryCH

Israel

countryIL

Norway

countryNO

Ukraine

countryUA

Cote D'ivoire

countryCI

India

countryIN

Nepal

countryNP

Uganda

countryUG

Cook Islands

countryCK

British Indian Ocean Territory

countryIO

Nauru

countryNR

United States Minor Outlying Islands

countryUM

Chile

countryCL

Iraq

countryIQ

Niue

countryNU

United States

countryUS

Cameroon

countryCM

Iran (Islamic Republic of)

countryIR

New Zealand

countryNZ

Uruguay

countryUY

China

countryCN

Iceland

countryIS

Oman

countryOM

Uzbekistan

countryUZ

Colombia

countryCO

Italy

countryIT

Panama

countryPA

Holy See (Vatican City State)

countryVA

Costa Rica

countryCR

Jamaica

countryJM

Peru

countryPE

Saint Vincent and the Grenadines

countryVC

Cuba

countryCU

Jordan

countryJO

French Polynesia

countryPF

Venezuela

countryVE

Cape Verde

countryCV

Japan

countryJP

Papua New Guinea

countryPG

Virgin Islands (British)

countryVG

Christmas Island

countryCX

Kenya

countryKE

Philippines

countryPH

Virgin Islands (U.S.)

countryVI

Cyprus

countryCY

Kyrgyzstan

countryKG

Pakistan

countryPK

Vietnam

countryVN

Czech Republic

countryCZ

Cambodia

countryKH

Poland

countryPL

Vanuatu

countryVU

Germany

countryDE

Kiribati

countryKI

St. Pierre and Miquelon

countryPM

Wallis and Futuna Islands

countryWF

Djibouti

countryDJ

Comoros

countryKM

Pitcairn

countryPN

Samoa

countryWS

Denmark

countryDK

Saint Kitts and Nevis

countryKN

Puerto Rico

countryPR

Yemen

countryYE

Dominica

countryDM

Korea, Democratic People's Republic of

countryKP

Palestine

countryPS

Mayotte

countryYT

Dominican Republic

countryDO

Korea, Republic of

countryKR

Portugal

countryPT

Yugoslavia

countryYU

Algeria

countryDZ

Kuwait

countryKW

Palau

countryPW

South Africa

countryZA

Ecuador

countryEC

Cayman Islands

countryKY

Paraguay

countryPY

Zambia

countryZM

Zaire

countryZR

safeSearch:使用一个bool值表示是否过滤垃圾信息。

lr:对语言的限制,string类型可选代号如下表:

语言

代号

语言

代号

Arabic

lang_ar

Icelandic

lang_is

Chinese (S)

lang_zh-CN

Italian

lang_it

Chinese (T)

lang_zh-TW

Japanese

lang_ja

Czech

lang_cs

Korean

lang_ko

Danish

lang_da

Latvian

lang_lv

Dutch

lang_nl

Lithuanian

lang_lt

English

lang_en

Norwegian

lang_no

Estonian

lang_et

Portuguese

lang_pt

Finnish

lang_fi

Polish

lang_pl

French

lang_fr

Romanian

lang_ro

German

lang_de

Russian

lang_ru

Greek

lang_el

Spanish

lang_es

Hebrew

lang_iw

Swedish

lang_sv

Hungarian

lang_hu

Turkish

lang_tr

ie:输入所使用的字符编码。这个参数将被忽略,所有的输入都将采用UTF-8

oe:输出所使用的字符编码。这个参数将被忽略,所有的输出都将采用UTF-8

通过对这个方法的各个参数的设定可以是自己的应用程序在搜索方面更加人性化。具体使用时可以通过各种控件来收集这些信息。


l GoogleSearchResult

这个类用于存储搜索结果,下面介绍这个类的一些重要属性:

1. estimatedTotalResultsCount 所有与关键字有关的信息的总数

2. searchTime 提交信息到返回信息所用的时间。

3. searchTips 根据关键字提供一些与关键字相关的关键字,供选择。

4. resultElements 返回一个数组,用于存储返回结果的每一项。

l Result Element

这个类的是搜索的结果中的每一项,所有的结果处理都依靠这个类。下面是这个类的一些属性的介绍:

1. URL 显示结果网页的url

2. snippet 返回在目标网页中摘录一些包含关键字片段。

3. title 目标网页的标题。

4. hostname 该参数显示目标网页所在的主机明。

5. summary 如果目标网页在ODP 目录中存在,则返回摘要信息。

6. directoryTitle 显示ODP 目录的标题。

通过这两个类可以取得各种与查询有关的信息,通过以上的介绍,基本可以使用googleAPI提供的全部功能。

2008年1月14日星期一

FileHelpers Library

http://www.filehelpers.com/

The FileHelpers are an easy to use .NET library written in C#. Is designed to read/write data from flat files with fixed length or delimited records (CSV). Also has support to import/export data from different data storages (Excel, Access, SqlServer)
Latest File Releases.

FileHelpers 库是简单易用的.NET库,使用C#语言编写,开源。可以用来读写分隔符分开或者固定长度的记录,如CSV。
这里是一片介绍性的文章

2007年11月13日星期二

Transform XML and apply XSLT in C#

I searched the internet and found two articles:
first from MSDN
using System;
using System.Xml;
using System.Xml.Xsl;
namespace XSLTransformation
{
/// Summary description for Class1.
class Class1
{
static void Main(string[] args)
{
XslTransform myXslTransform;
myXslTransform = new XslTransform();
myXslTransform.Load("books.xsl");
myXslTransform.Transform("books.xml", "ISBNBookList.xml");

}
}
}


The second is from CodeProject

This one is long and you should check it yourself.

2007年7月12日星期四

Genghis Group Tools - C# WinForms 库

http://www.sellsbrothers.com/tools/genghis/

Genghis is a set of extensions built on top of .NET and integrated with WinForms to provide application-level services in the same flavor as the Microsoft Foundation Classes. Genghis gets its name as the functional heir to Attila, a similar set of functionality built on top of ATL.

Genghis is written in C#. Building Genghis requires Visual C# or Visual Studio.NET. Visual Studio.NET solution and project files (*.sln and *.csproj) are provided to build Genghis and all the samples. You should be able to load any solution file into Visual C#/Visual Studio.NET and build the project for yourself.


它包括如下的类

Command line parser
Completion combo
Control hosting status bar
Cursor changer
Custom check state treeview
Custom XP theming controls
File Search Engine
FileDocument class (doc/dirty bit management)
FindReplaceDialog
FolderNameDialog
HandleCollector for the world
Header group box control
Image combo
More robust validation ala WebForms
Most-Recently-Used (MRU) files support
MSN Messenger-style popup window
Multiple Top-Level Windows
Multiple-instance detection
Path resolution b/w UNC, local (including SUBST, etc)
Retrieving mapped drives
Retrieving shares
Screen Saver class
Scrollable Picture Box
Sorting listview (including the little triangle thingy)
Splash Screen class
Status Bar Extender
WebCommandLineHelper
Window serializer
Wizard framework
HtmlLinkLabel class
User-resizable panel
Gradient Progress Bar
Command updating
Cool bars/Cool menus
Docking App Bar

下载地址在这里 http://www.codeplex.com/genghis/Release/ProjectReleases.aspx?ReleaseId=4759

2007年6月15日星期五

C# XML Comments

C#使用一种新的注释定义,利用定义好的Tag和HTML的关键字,用户可以将注释转化一个很好的文档。
可能Linux下的用户更熟悉Doxygen之类的注释处理工具。
下面的内容是来自微软的MSDN中的一段,简单地介绍了这些注释的语法。
原来的文章里面有更多更高级的应用,可以去看看。
http://msdn.microsoft.com/msdnmag/issues/02/06/XMLC/
There are nine primary tags: , , , , , , , , and .
In this context, the tag is used to describe a type such as a class:
/// 
/// Class that contains functions to do
/// transformations to help files.
///

The C# documentation recommends using to describe a type and a tag to describe a type member. Oddly, if you start a comment before a type using the /// combination, the Visual Studio .NET IDE will still insert a tag. Therefore, tags need to be inserted manually.
The tag is the tag found most often in a C# source file. This tag is used to describe type members, including methods, properties, and fields:
/// 
/// This XmlDocument based attribute contains the
/// XML documentation for the project.
///

The tag can describe types as well, but it is not recommended. The XML comment documentation recommends that the tag be used for describing types.
The tag is used to mark the beginning of an example showing how to use the item. The example can be any valid text, but most often it is a snippet of code:
/// 
///
/// // create the class that does translations
/// GiveHelpTransforms ght = new GiveHelpTransforms();
/// // have it load our XML into the SourceXML property
/// ght.LoadXMLFromFile(
/// "E:\\Inetpub\\wwwroot\\GiveHelp\\GiveHelpDoc.xml");
///

///

If code is used, it is usually marked with a tag. The tag will be discussed in the section on support tags.
The tag documents the exceptions, if any, that the item may throw. If more than one exception may be thrown, then more than one of these tags may be used. Unlike most of the tags, the tag has one attribute, cref. The value of this attribute is the name of the exception that could be thrown. This must be a valid class because the C# parser will verify it and extract the context information to put into the XML documentation. I will explain this later.
I did not throw any exceptions in the code for this article, but here is an example of how the cref attribute can be used with the tag:
/// 
/// Normally, a discussion on any exceptions thrown would go here.
///

The tag describes the parameters of a method or property. It is automatically inserted by the IDE when using the three forward slashes before a method. The tag has one attribute, name, which is simply the same name that the parameter has in the source:
/// The path to the file containing the
/// source XML.
Member access is identified with the tag. The text that is assigned to it sets permission-related descriptions. There is no requirement for the value for this tag. Permission is one possibility, with values such as public, private, protected, and so on. Scope is another possible value, with information about whether the method is static. However, you are free to put whatever value you must have here.
The tag has one attribute—cref. The documentation describes the use of cref in this context as "a reference to a member or field that is available to be called from the current compilation environment." It is usually set to System.Security.PermissionSet:
/// Public
/// Access

The tag is similar to the tag, but it's used to describe what the method or property returns:
/// The HTML for a list of types based on the XML

/// documentation.
The tag specifies "other" links related to the same topic. This tag usually does not include a text value, just a cref attribute that specifies a reference to a symbol. This could be a type, member, field, and so on.
/// 
The XML compiler will identify the content of the symbol and use it accordingly in the compiled XML documentation. I'll discuss this again in the section on the XML documentation file.