0
点赞
收藏
分享

微信扫一扫

【蛙蛙推荐】.NET 1.1移植到.NET 2.0出现的一些小问题的解决

东言肆语 2022-01-25 阅读 42

  【蛙蛙推荐】.NET 1.1移植到.NET 2.0出现的一些小问题的解决

经过wawaCRM项目组成员的讨论,wawaCRM项目决定使用新一台的.NET平台来进行构建。 

Microsoft Visual Studio 2005 + C#2.0 + SqlServer2005 + ASP.NET 2.0

做出这个决定还未经过充分的讨论,有一些问题还没有充分考虑到如何解决,比如说这样搭建起来的项目会对特定的平台有较强的依赖性,做一个企业级,产品级的项目不应该用不成熟的技术和测试版的平台等。但是这些问题在.NET 2.0技术以及相关工具的推出所产生的好处面前已经显得不是非常重要而不可解决,我们相信,微软会做好一切的,会帮我们提供哪些问题的解决方案的。 

今天我就开始把以前在1.1环境下的CMP架构开始移植到2.0下,并且我想让CMP架构增加对【事务管理】和【并发处理】的功能,可是导入到vs.net 2005下编译的时候出了一些小问题,现在把这些问题的解决办法说一下。 

一、对程序集设置强名的改动

CMP架构的每个项目都有一个链接到SharedAssemblyInfo.cs文件并在那个文件里集中设置程序集的一些属性,包括强名,此文件里有如下一句来设置各个程序集的强名。

[assembly: AssemblyKeyFile(@"..\..\..\GadgetsWarehouse.SNK")]


结果编译的时候提示了一个警告,如下。

使用命令行选项“/keyfile”或适当的项目设置来代替“AssemblyKeyFile”


原来vs.net 2005不提倡使用[assembly: AssemblyKeyFile()]属性,需要在每个项目(不是解决方案)的属性里的【签名标签】里为程序集设置强名键文件。


二、获取当前线程ID的改动
CMP架构里的错误处理模块里面要在发生异常的时候获取当前应用程序的线程信息,异常信息,堆栈信息,要持久的实体序列化信息等来生成错误报告,使用了以下语句来获取当前线程ID,当然了,这句代码默认是不允许的,需要设置注册表和Machine.Config文件。

AppDomain.GetCurrentThreadId()


结果编译器警告如下

“System.AppDomain.GetCurrentThreadId()”已过时:“AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread.  http://go.microsoft.com/fwlink/?linkid=14202”


后来google了一下,把.net 1.1下的“AppDomain.GetCurrentThreadId()”方法换成.net 2.0下的“System.Threading.Thread.CurrentThread.ManagedThreadId”属性就可以了。


参考链接:

http://lists.ximian.com/pipermail/gtk-sharp-list/2005-September/006374.html


三、访问程序配置信息的改动

CMP架构在写错误日志的时候需要在.Config文件里读取日志保存的路径,使用如下的代码。

string errorLogBaseDir = System.Configuration.ConfigurationSettings.AppSettings["ErrorLogBaseDir"];

编译时出现如下警告信息

“System.Configuration.ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by ConfigurationManager.AppSettings”


后来我使用   [Obsolete("这里要读取config文件", false)]属性标志了那个方法,可是调用这个方法的代码都标记了警告,我晕。

后来明白了,出现这些警告是因为System.AppDomain.GetCurrentThreadId(),System.Configuration.ConfigurationSettings.AppSettings等类成员被标记了Obsolete属性,所以在编译的时候出现了这些自定义警告,用来警示人们可以使用更新的类成员来替换现有的函数。

 后来google到一个外国人的博客,得到了结果。

把.net 1.0下的“System.Configuration.ConfigurationSettings.AppSettings”索引器换成.net 2.0下的“System.Configuration.ConfigurationManager.AppSettings[]”索引器。


参考文章

ConfigurationManager Gotcha

http://www.irishdev.com/blogs/kieranlynam/archive/2005/05/17/728.aspx


ConfigurationManager Gotcha

Quick Gotcha... Up to now, you use the ConfigurationSettings.AppSettings property to read an entry from the AppSettings section of the config file.

In ASP.NET 2.0, this property is marked as obsolete; you must now use the ConfigurationManager class. However, this does not seem to exist in the System.Configuration namespace. Annoying.

Actually, it does exist in this namepsace, but you must add a referene to the System.Configuration assembly first (this assembly is not one of the default references).

小节:从.net 1.1到.net 2.0移植代码会出现一些细小的改动,但是微软大多都已经给出了提示,只要英文能力比较好,会很快解决的,不会像我,解决这三个小问题,用金山词霸翻译老半天,再到QQ里问这个问那个,又上google搜索,再翻译,理解,折腾了一上午才得出答案。另外劝一些程序员新手好好学学英语吧,别像偶一样,除了C#关键字那几个英文外,别的一个也不懂。




举报

相关推荐

0 条评论