Topics: Customizing BugNET
Nov 19, 2012 at 5:03 AM


It seems that my SMTP and POP3 mail modules are now working and that the system is in fact polling for mail. However, when mail is sitting in the POP3 mailbox being polled, I am receiving a FileLoadException error related to HtmlAgilityPack. I have the HtmlAgilityPack.dll in the bin folder but I don't seem to have the source code for it. 

The Error Log details follow.

Thank you,
-- Jon 


System.IO.FileLoadException: Could not load file or assembly 'HtmlAgilityPack, Version=, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)File name: 'HtmlAgilityPack, Version=, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a'   at BugNET.MailboxReader.MailboxReader.SaveMailboxEntry(MailboxEntry entry)   at BugNET.MailboxReader.MailboxReader.ReadMail() in c:\Users\testwork\Documents\Visual Studio 2012\Projects\BugNet\BugNET-1.2.231-Source\src\BugNET.MailboxReader\MailboxReader.cs:line 159

Nov 19, 2012 at 2:51 PM

The source code is here however it was added to the project as a Nuget package so there is no need for the source code.

Are you running the source code or as a published web site?  If you are running the source code you might want to do a Solution Build (Ctrl-Shift-B) this will pull any missing (or update) any Nuget packages in the entier solution tree.


Nov 19, 2012 at 4:50 PM

I should correct something: The 213 build might also have the same problem--I just realized that this was a runtime error, not a compile-time error.

OK, the Ctrl-Shift-B seems to have fixed the HtmlAgilityPack issue. Now I have a new one, I will write a new thread for that. Thanks.

-- Jon

Feb 19, 2013 at 10:08 PM
I have this same problem running from source. I ended up uninstalling the NuGet package for HTMLAgilityPack on the MailBoxReader project and then installing it again (which installed an updated reference). So now I am running 1.4.6 instead of 1.4.0.

After this change I am now getting System.NullReferenceException: Object reference not set to an instance of an object.
at BugNET.MailboxReader.MailboxReader.SaveMailboxEntry(MailboxEntry entry)
at BugNET.MailboxReader.MailboxReader.ReadMail()

when the reader tries to read new mail.

Maybe it is related to the fact that the AjaxControlTookit contains "SanitizerProviders" one of which is HtmlAgilityPack 1.4.0 and which might cause some kind of referencing conflict. Any advice on how to get this working?
Feb 20, 2013 at 2:38 AM
I just updated from the main source tree and tested the mailreader and it seems to work for me using the following versions:

AjaxControlToolkit: 4.1.60919
HtmlAgilityPack: 1.4.6

I am connecting against SmarterMail v10.2

I also configured log4net to ALL level and noticed all of the INFO messages being logged.

As an FYI I also run Visual Studio with Administrator elevation, not sure if that will make a difference or not with regards to the mailreader.
Feb 20, 2013 at 2:56 PM
Looking at the current source, I see that the main BugNET_WAP has a reference to HtmlAgilityPack 1.4.0 (the one contained in AjaxToolkit) while the reference used in the MailBoxReader is HtmlAgilityPack 1.4.6. My confusion is over how these references work once you build because only one of these dlls can sit in the bin folder.
Feb 20, 2013 at 5:17 PM
I would think that HtmlAgilityPack 1.4.0 would be the one that is in the bin folder due to the reference chain (BugNET_WAP being the deciding factor) as it would be the last one compiled.

However since the MailReader is using the basic features of the Agility Pack it probably should not matter what version unless the interface has changed. If the logging is working you should be able to track the INFO's up to the point of the exception.

There is a possibility that the mail reader is having an issue parsing the email that you are getting back from your email server. What email server are you trying to connect to?
Feb 21, 2013 at 2:56 PM
I've tried both gmail and with the same error (I'm testing with third party hosting before setting up something on our mail servers).
Feb 21, 2013 at 3:23 PM
I have Log4Net set to "All" and I get INFO messages that the correct number of emails are being read and parsed. It fails after this info message: "pop3Client: >> Readed period-terminated message 5145 bytes" with a null reference exception. Also, I noticed that the logged username for the mail reader is NULL.
Feb 21, 2013 at 4:28 PM
The logged NULL for the user is by design as the mailreader does not run under the context of the logged in user it is more of a system thing.

Based on the last message it would seem that the POP3 client was able to parse the header information from the email but was not able to parse the body of the email for some reason. Do the emails that are being sent actually have an email body or are they empty?

If I have time this weekend I can look at it. but it might be tight.

Feb 25, 2013 at 5:23 PM
They all have a subject and a body.
Feb 28, 2013 at 3:01 AM
I was able to test the POP3 integration against Gmail using the HtmlAgilityPack 1.4.6 referenced in the WAP project (so this version was pulled into the project while debugging) and was able to download and process over 400 spam messages (some failed due to the fact they had no subject).

So it would seem that having the HtmlAgilityPack 1.4.6 version in the WAP project might not be a bad idea, however I did not test if the AjaxControlToolkit was affected by this.
Mar 4, 2013 at 7:19 PM
Thanks for testing this! I must have some referencing problems, I can't get it to work. All I did was use NuGet to update any packages that had a later version - turns out that was a bad move.
Mar 15, 2013 at 12:27 PM
I am working with the source code version. Here is solution I came up with and it worked for me:

An older version of HtmlAgilityPack was referenced from the BugNET_WAP project and 'Copy Local' was set true for this project.
the location of the dll was this: \BugNET-1.3.242-Source\src\packages\AjaxControlToolkit.4.1.60919\lib\40\SanitizerProviders\HtmlAgilityPack.dll
which seemed not to be the correct one.

However the BugNET.MailboxReader project was referencing another version of the HtmlAgilityPack which was not being copied to the bin folder.
I just removed the old reference from the BugNET_WAP project and added a reference to the dll located at \BugNET-1.3.242-Source\src\packages\HtmlAgilityPack.1.4.6\lib\Net40

That fixed the assembly loading error.
Apr 4, 2013 at 4:31 PM
Yeah, I tried that, and it does fix the build issue. But then I get a runtime exception when the mailbox reader tries to read new emails and save them as bugs:

2013-04-04 11:27:36,447 [37] ERROR BugNET.HttpModules.MailboxReaderModule [(null)] - System.NullReferenceException: Object reference not set to an instance of an object.
at BugNET.MailboxReader.MailboxReader.SaveMailboxEntry(MailboxEntry entry)
at BugNET.MailboxReader.MailboxReader.ReadMail()
Oct 17, 2013 at 2:12 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.