Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to implement Drools in .Net. I am new to .Net as well as Drools.I've read the following document for implementation of Drools:

http://www.codeproject.com/Articles/29165/Getting-Started-with-Drools-NET

I've downloaded this project and it was working fine. Here is my code which I have implemented:-


C#
requirementBusinessRules = this;
            PackageBuilder builder = new PackageBuilder();
            Stream stream = new FileStream(@"C:\Users\Sdixit\Desktop\LatesetVersion\ReadMails\SimpleRulesExt.drl", FileMode.Open);           
            builder.AddPackageFromDrl("SimpleRules.drl", stream);   // Exception
            Package pkg = builder.GetPackage();
            ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);           
            workingMemory = ruleBase.NewWorkingMemory();           
            if (_currentRawMail == null)            {
                _currentRawMail = requirementBusinessRules.workingMemory.assertObject(em); 
            }
            else
            {
                requirementBusinessRules.workingMemory.modifyObject(_currentRawMail, em);
            }
            requirementBusinessRules.workingMemory.fireAllRules();
            EmailProperties mails = (EmailProperties)requirementBusinessRules.workingMemory.getObject(_currentRawMail);


C#
drools.dotnet.dll!org.drools.dotnet.semantics.DotnetBaseClassFieldExtractor.DotnetBaseClassFieldExtractor(java.lang.Class clazz, string fieldName) Line 61 + 0x13 bytes C#
drools.dotnet.dll!org.drools.dotnet.semantics.DotnetClassFieldExtractorFactory.getClassFieldExtractor(java.lang.Class clazz, string fieldName) Line 50 + 0x1b bytes C#
[External Code] 
drools-3.0.dll!org.drools.base.ClassFieldExtractor.init() Line 73 + 0x58 bytes  Unknown
drools-3.0.dll!org.drools.base.ClassFieldExtractor.ClassFieldExtractor(java.lang.Class clazz, string fieldName) Line 53 Unknown
drools-3.0.dll!org.drools.base.ClassFieldExtractorCache.getExtractor(java.lang.Class clazz, string fieldName) Line 27 + 0x1d bytes  Unknown
drools-3.0.dll!org.drools.semantics.java.RuleBuilder.getFieldExtractor(org.drools.lang.descr.PatternDescr descr, java.lang.Class clazz, string fieldName) Line 998 + 0x1b bytes Unknown
drools-3.0.dll!org.drools.semantics.java.RuleBuilder.build(org.drools.rule.Column column, org.drools.lang.descr.LiteralDescr literalDescr) Line 527 + 0x36 bytes    Unknown
drools-3.0.dll!org.drools.semantics.java.RuleBuilder.build(org.drools.lang.descr.ColumnDescr columnDescr) Line 431 + 0x36 bytes Unknown
drools-3.0.dll!org.drools.semantics.java.RuleBuilder.build(org.drools.lang.descr.RuleDescr ruleDescr) Line 303 + 0x3e bytes Unknown
drools-3.0.dll!org.drools.semantics.java.RuleBuilder.build(org.drools.rule.Package pkg, org.drools.lang.descr.RuleDescr ruleDescr) Line 203 Unknown
drools-3.0.dll!org.drools.compiler.PackageBuilder.addRule(org.drools.lang.descr.RuleDescr ruleDescr) Line 337 + 0x1b bytes  Unknown
drools-3.0.dll!org.drools.compiler.PackageBuilder.addPackage(org.drools.lang.descr.PackageDescr packageDescr) Line 204 + 0x4a bytes Unknown
drools-3.0.dll!org.drools.compiler.PackageBuilder.addPackageFromDrl(string fileName, java.io.Reader reader) Line 129    Unknown
drools.dotnet.dll!org.drools.dotnet.compiler.PackageBuilder.AddPackageFromDrl(string fileName, System.IO.Stream drlStream) Line 78 + 0x2b bytes C#


But I am getting an Exception "NullReferenceException unhandled by user code .object reference not set to an instance of an object." What to do Now?? What am I missing here?? I went through Drools: NullPointerException when addPackageFromDrl(source) is called

I am using Drools 3.0 and Visual Studio 2012 Thanks
I have found that Drools 6 is the latest version but when i installed it in my pc i found that it contains only .jar file no .dll files . Thanks Please Help!
Posted
Comments
Shyam Dixit 3-Mar-14 9:56am    
builder.AddPackageFromDrl(source); //Exception

You did not show where the exception with the message "Object reference not set to an instance of an object" is thrown.

Not to worry. This is one of the very easiest cases to detect and fix. It simply means that some member/variable of some reference type is dereferenced by using and of its instance (non-static) members, which requires this member/variable to be non-null, but in fact it appears to be null. Simply execute it under debugger, it will stop the execution where the exception is thrown. Put a break point on that line, restart the application and come to this point again. Evaluate all references involved in next line and see which one is null while it needs to be not null. After you figure this out, fix the code: either make sure the member/variable is properly initialized to a non-null reference, or check it for null and, in case of null, do something else.

Please see also: want to display next record on button click. but got an error in if condition of next record function "object reference not set to an instance of an object"[^].

Sometimes, you cannot do it under debugger, by one or another reason. One really nasty case is when the problem is only manifested if software is built when debug information is not available. In this case, you have to use the harder way. First, you need to make sure that you never block propagation of exceptions by handling them silently (this is a crime of developers against themselves, yet very usual). The you need to catch absolutely all exceptions on the very top stack frame of each thread. You can do it if you handle the exceptions of the type System.Exception. In the handler, you need to log all the exception information, especially the System.Exception.StackTrace:
http://msdn.microsoft.com/en-us/library/system.exception.aspx[^],
http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx[^].

The stack trace is just a string showing the full path of exception propagation from the throw statement to the handler. By reading it, you can always find ends. For logging, it's the best (in most cases) to use the class System.Diagnostics.EventLog:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[^].

Good luck,
—SA
 
Share this answer
 
Try to change exception line to this:

string fname = @"C:\Users\Sdixit\Desktop\LatesetVersion\ReadMails\SimpleRulesExt.drl";
Stream stream = new FileStream(fname, FileMode.Open);
builder.AddPackageFromDrl(fname, stream);


I think it requires full path to the file.
 
Share this answer
 
Comments
Shyam Dixit 3-Mar-14 10:05am    
I checked it already And I checked for all Five overloaded AddPackageFromDrl() Methods. I still confused as I mentioned that in a codeproject's project(link) it is working well but not working in my project
Vedat Ozan Oner 3-Mar-14 10:10am    
OK, maybe it would be better to read its documentation for special cases. if you can't still solve, you may get help from the forum of that article.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900