NVELOCITY-0.4.2.8580 's modification record--"It appears that's no class was specified as the ResourceManager ..." bug fixes

Source: Internet
Author: User

Since there are other development record tools up-to-date not how to write development memo in Cnblog. But I think this is a more serious problem, I think it is necessary to let more people know how to deal with, so in Cnblog also put a piece of hope to spread widely.

--------------------------------------------------

First time modification

--------------------------------------------------

Nvelocity the use of this tool is believed that most netizens are using Velocity as I do in Java, so I would like to have a similar toolkit in C #. And the search for it is nvelocity.

Nvelocity I used it two or three years ago, so I don't think it's going to be a problem. Follow the usual online search and join the project and various examples on the web to run. For the material appeared "It appears that is no class was specified as the ResourceManager ...", the heart is not panic, because according to experience is a certain d ll quote didn't get in. The results toss up various documents and various examples on the Web are wrong. Unconsciously a morning passed, think things a bit serious, put down the effect of the mood, opened my previous project. There are several different places to discover:
1. Before the company used is VS2010, now with the vs2008, no way to compile directly.

2. Before the project only a NVelocity.dll file, there is no source code, and this time the download has Nvelocity.dll,nvelocity.http.dll and source and other files.

Well, I've replaced this NVelocity.dll. But the compile error, the version of the file to see the information, it is written for. NET 4.0, of course, the direct swap with vs2010 just fine. But my situation is slightly special, the production environment is. NET 2.0, not too convenient to let The upgrade. NET environment can sometimes become a disaster-I have encountered many times when I upgraded. NET 3.5, although. NET 4.0 is a lot better. I really don't want to complicate things.

Well, I've been searching the internet for countless similar problems. The period saw said because nvelocity by what XXX maintenance, so nvelocity version of the source has multiple. At this time unexpectedly in the example of a netizen found can use of. NET 2.0 version NVelocity.dll but its files do not have version information, apparently not official, but the Netizen's article shows that it has been repeatedly reproduced can not find how to modify the information. The file I downloaded is located at ( NVelocity-0.4.2.8580):

http://nvelocity.sourceforge.net/

Because this is the first Google search, and the first Baidu search is that for. NET 4.0 version:

http://nvelocity.codeplex.com/

The available. NET 2.0 version of the Netizen is gone. Honestly, I can't understand sourceforge.net. This is why it is not possible to use such a well-known control on such a well-known web site to provide the file is actually wrong. The corresponding bug should have been submitted by other information I searched for, I don't know why I didn't submit it to sourceforge.net here.

Well, no matter how much, at least on my Chinese version of vs2008, the following sections need to be modified to work properly:

In File ResourceLocator.cs

Try
{//CLQ
foreach (Assembly A in assemblies)
{
String prefix = a.fullname.substring (0, A.fullname.indexof (",")). ToLower ();
string[] names = A.getmanifestresourcenames ();
Try
{//CLQ//Here are all right, should be the result of the previous two words
foreach (String s in Names)
{

if (S.tolower (). Equals (fn) | | S.tolower (). Equals (prefix + "." + fn))
{
This.filename = s;
Assembly = A;
Isresource = true;
}
}
}
catch (System.Exception ex)
{
String s = ex. Message;
System.Console.WriteLine ("BBBBBB:" + s);
}//clq
}
}catch (System.Exception ex)
{
String s = ex. Message;
System.Console.WriteLine ("AAAAAA:" + s);
}//clq

}//if CLQ

According to my test, the probable cause of the error is that a resource file does not support an interface when it is being searched by the reflection mechanism, causing its exception to exit the processing of the remaining resources. So just add a few try on the line (PS: Reflection implementation, I am afraid the efficiency is not high bar).

After this correction, the following code can be run.

Velocityengine vltengine = new Velocityengine ();
4.0 this is Runtimeconstants.resource_loader.
Vltengine.setproperty (Runtimeconstants_fields.resource_loader, "file");
String path = _this. Server.MapPath ("~/");
Vltengine.setproperty (Runtimeconstants_fields.file_resource_loader_path, PATH);
Vltengine.init ();//Do not modify the library code, here will be an error

--------------------------------------------------

Second Amendment

--------------------------------------------------

After the modification for a period of time, because many of my personal toolchain is not support UTF8 (or very troublesome), here the template is changed to normal GBK encoding. This version is not corrected. I changed a place. The normal encoding correction code is:

Vltengine.setproperty (runtimeconstants_fields.output_encoding, "GB2312");//modify NVelocity-0.4.2.8580 source code to use these two, and preferably with a GBK.
Vltengine.setproperty (runtimeconstants_fields.input_encoding, "GB2312");//

This version of Nvelocity does not work and needs to be modified:

In the Template.cs file

System.IO.StreamReader br = new System.IO.StreamReader (new System.IO.StreamReader (is_renamed, System.Text.Encoding.GetEncoding (Encoding)). BaseStream);
System.IO.StreamReader br = new System.IO.StreamReader (new System.IO.StreamReader (is_renamed, System.Text.Encoding.GetEncoding (Encoding)). BaseStream, System.Text.Encoding.GetEncoding (Encoding));//CLQ 2014.05.23

Obviously the author may be a foreigner, the location of the code is wrong.

--------------------------------------------------

For the convenience of reference, I put on the revised all the project files, here is the debug version, the efficiency of the environment required to automatically compile other versions. There are not many changes in the code, you can search the word "//CLQ" can be found, Other code because I have limited ability to see and do not dare to change. For the sake of stability and do not want to cause trouble in the future is not going to big change, can be in my current small project to use on the line.

For:

Http://files.cnblogs.com/-clq/NVelocity-0.4.2.8580%5B2014.05.23%5D%5Bclq_modify%5D.zip

--------------------------------------------------

If there are other bugs I will upload the new version again. I also hope to have the insider's information about the reasons why nvelocity is so chaotic.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.