Calling Custom DLL in AC ASCX.CS Pages

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Mon Jan 30, 2012 6:18 pm

I'm sure this is covered somewhere in here, or elsewhere, but for the life of me I can't find it.

I've created a custom DLL in order to integrate an AbleCommerce shopping cart with another ERP system. However, I'm having trouble getting the added code lines in the ASCX.CS file to work correctly. The DLL works in namespace NS_WebServe, the only class is also name NS_WebServe. I've added "using NS_WebServe" to the top of the CS file, as well. However, when I make the call "NS_WebServe.addNewSalesOrder()", I get the error:

d:\inetpub\wwwroot\ConLib\OnePageCheckout.ascx.cs(1331): error CS0234:
The type or namespace name 'newSalesOrder' does not exist in the namespace 'NS_WebServe' (are you missing an assembly reference?)

What am I missing?

User avatar
dgoranov
Lieutenant (LT)
Lieutenant (LT)
Posts: 55
Joined: Sun Jan 16, 2011 3:58 pm
Location: Boston, MA
Contact:

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by dgoranov » Mon Jan 30, 2012 11:03 pm

Make sure the assembly .dll file is in the /bin folder and you have assemblyName referenced in ascx page.

<%@ Register TagPrefix="myTag" Namespace="myreference" Assembly="assemblyName.dll" %>

If you are using Visual Studio add the assembly under Web site project References.
Dimi Goranov
Drundo Software Inc.
AbleCommerce Hosting and Management
Email: dgoranov@drundo.com
Ph: 888.464.2140

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Wed Feb 01, 2012 11:31 am

Ah! Ok, thank you. I don't really do much with ASP.NET, so I wasn't aware I needed to do that. I already had the DLL in the proper folder, just didn't have the reference on the ASCX page. I can't test this out yet, but I'll see what happens tonight.

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Wed Feb 01, 2012 12:48 pm

Ok, I now have this error...

[[ConLib:OnePageCheckout]] Could not load file or assembly 'NS_WebServe.dll' or one of its dependencies. The system cannot find the file specified.

The ASCX page also has this at the top...

<%@ Register Assembly="NS_WebServe.dll" Namespace="NS_WebServe" TagPrefix="ns" %>

The DLL is in the Bin folder, so I know it's not missing.

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Tue Feb 07, 2012 4:06 pm

Ok, well, now I'm back to square one. I removed the .dll extension from the assembly referene, and that particular error went away. But now I'm back to the original error. In the CS page, I have my imports looking like this around where I try to reference the namespace for my DLL...

Code: Select all

using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NS_WebServe;
using CommerceBuilder.Common;
using CommerceBuilder.Users;
I'm assuming that I have to be doing something wrong here. I'm not used to having to create and reference a DLL file in my applications, so any pointers from someone who knows would be very appreciated.

FYI, the namespace is NS_WebServe. The class name is the same.

User avatar
dgoranov
Lieutenant (LT)
Lieutenant (LT)
Posts: 55
Joined: Sun Jan 16, 2011 3:58 pm
Location: Boston, MA
Contact:

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by dgoranov » Wed Feb 08, 2012 12:05 am

Another possible reason for this error could be if the assembly that contains the NS_WebServe code was built with different asp.net version than
the web application. I recently encountered the same error with another project (another asp.net web app. not Ablecommerce). The assembly was built
under asp.net 3.5 and the asp.net web application project was set as asp.net 4.0. I had to rebuild the assembly as asp.net 4.0 project in order to get
the namespace properly recognized.

If you are running the latest Ablecommerce 7.0.7 (asp.net 4.0) try to rebuild the assembly as 4.0 project and see if this solved the issue.
Dimi Goranov
Drundo Software Inc.
AbleCommerce Hosting and Management
Email: dgoranov@drundo.com
Ph: 888.464.2140

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Wed Feb 08, 2012 8:10 am

Keep in mind that you are not required to compile custom class code into a DLL in order to call the code from within AbleCommerce.

You can also just put your custom class code in the /App_Code/ folder. That way you don't have to mess with compiling, assembly target versions etc. Check out the other files in /App_Code/ and you'll see how it's done.

DLL files do come in handy, especially when it comes to deployment. But sometimes they can be a pain too.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Wed Feb 08, 2012 10:34 am

Dimi--

By default my projects are set to work with .NET 4.0, so I don't think that's the issue if AC is running based off of that version.


Joe--

I'll give that a try. I was thinking I should try using the CS file, but I didn't know where it should be placed. The one thing I'm not sure about though would be the config file. I'm used to using compiled code with a config file, so I'm not sure what the naming convention should be in this case.


--Mike

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Wed Feb 08, 2012 10:45 am

Yeah just put the .cs file in the /App_Code/ folder, and the classes contained within are all automatically available throughout the entire application.

I was the exact opposite. I was used to using straight code files. But as I learned how to organize my programming into separate class files, I soon switched to DLL files. It's far easier to deploy a single DLL rather than figuring out which .cs files were changed.

Take a look at ProductHelper.cs. It's a good example of how to do it. First you see the class declaration:

Code: Select all

public class ProductHelper
then you see lots of separate methods defined as 'static'. Static means they are 'public' i.e. those methods are accessible without having to create a unique instance of ProductHelper. like this:

Code: Select all

public static void BuildProductChoices(Product product, PlaceHolder phChoices)
So to call that code in the .cs file you put in /App_Code/ you would simple do:

Code: Select all

ProductHelper.BuildProductChoices(_Product, _PlaceHolder);
No need to do a 'Using MyClass;' or 'Using MyNamespace;' etc. Just call it.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Wed Feb 08, 2012 11:13 am

Actually, I think I'm going to need the DLL file because of the classes and methods from the web services integration. I had to add the needed components in as a reference, and I'm not sure how that would be handled with straight CS files as opposed to a compiled DLL file. However, I'm going to try some of this stuff out and see what happens.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Wed Feb 08, 2012 12:15 pm

Sounds good, good luck with it !!
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Fri Feb 10, 2012 1:37 pm

This still doesn't want to cooperate. I'm getting this error message:

[[ConLib:OnePageCheckout]] d:\inetpub\wwwroot\ConLib\OnePageCheckout.ascx.cs(1331): error CS0234: The type or namespace name 'newSalesOrder' does not exist in the namespace 'NS_WebServe' (are you missing an assembly reference?)

I'm including a link to a ZIP archive containing the affected files. These would be the ASCX and ASCX.CS file for OnePageCheckOut and my CS file containing my custom class. I'm missing something here and I don't know what. This is getting very frusting and people are getting impatient. The checkout page customizations are at the end of the CheckedOut method. If someone could please look this over and help me figure out where I went wrong, I would be ever so grateful.

http://ledzilla.boldlygoingnowhere.org/ ... bServe.zip

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Fri Feb 10, 2012 3:35 pm

What version of Able are you using? And you're on ASP.Net 4.0 right?
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Fri Feb 10, 2012 3:45 pm

According to the admin page, AbleCommerce 7.0.7 build 14588.

I'm assuming that the machine is on .NET 4.0. I don't have physical access, only FTP access. The VS project is targeting v4.0.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Sat Feb 11, 2012 8:15 am

ok first error I'm getting is below. Without that DLL file, I can't really do any more testing for you. Just to be sure, did you add a reference to that DLL in your Visual Studio project? And is that DLL in your /Bin/ folder?
Capture.JPG
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Sun Feb 12, 2012 12:19 pm

My Visual Studio project is what's creating that DLL. As for what you've highlighted, that was added in as part of a web reference. The URL is https://webservices.netsuite.com/wsdl/v ... suite.wsdl. I've updated the zip file linked in my previous reply to contain the actual compiled DLL file along with its matching config file.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Sun Feb 12, 2012 12:46 pm

Ahhh ok. I'll re-download and light up the DLL this evening. Maybe I can link up my test site the same way you've got yours and find the cause of the compiler error.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Sun Feb 12, 2012 8:29 pm

Ok here's what I've got for ya. Correct me if I'm wrong anywhere:

NS_WebServe.cs: You're building this into a DLL. So you can have the ns_webserve.cs file in the /App_Code/ folder or have the compiled DLL ns_webserve.dll in the /Bin/ folder. But not both, so make sure that's cleaned up first.

My tests were with ns_webserve.cs in the /App_Code/ folder.

Next, I added the web reference to the the website like this....note where I highlighted. You must specify a Namespace to use for the web service reference:
Capture2.JPG
Once the web service is added, you should see it listed in the Solution Explorer like this:
Capture3.JPG
Now at this point, you have object classes defined. But here's the part you're missing: you have to reference the web service namespace like this:
Capture4.JPG
Once you reference the namespace for the objects contained in the web service, your Customer, Address, SalesOrder etc objects all light up. Now they are all available object classes in your code.

But, there's one problem. The web service isn't defining the object class for NetSuiteService(). So I'm not sure where that comes from. My guess is there's another web service reference to be added but that's purely speculation at this point.

Overall, you seemed to be very close. All you needed to do was know the namespace you assigned to the web service and reference it at the top of the file. But, without a web service or other way to define the NetSuiteService() object class, you're not going to get any further. Unfortunately I don't know how much more I can be of help.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Sun Feb 12, 2012 8:33 pm

One important note. If you added the web reference to the DLL project, then there's no need to add that same reference to the actual web site project. It's already defined in your DLL. But if you go the /App_Code/ route, you'll need to define the web service like I showed above into your web project.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Mon Feb 13, 2012 5:30 pm

Yeah, I need that NetSuiteService() defined otherwise nothing will work. It's the required method for establishing the web services connection to the NetSuite servers. In order to have it work, I had to enter it through the "Advanced" button at the bottom of the Service Reference window, and then choose to add a web reference. That's why my "Using" call is the way it is. It's also what I've had to do with other web services integrations I've done with NetSuite. However, with those I didn't have to try to integrate with web pages. I was able to create an executable that runs off of a server.

Here's a screenshot of what NetSuite's instructions provide...
Image

In this fashion, Visual Studio provides no issues and the DLL compiles without any errors.

Also, here's how my solution explorer looks with the references. I've added version 2010.2 and 2011.2 of the web services using the fashion you described, but I have yet to encounter success with them.

Image

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Thu Feb 16, 2012 10:39 am

I think maybe I know why I'm having a problem. I'm going to rebuild the project. I think maybe when I first created it I started it off incorrectly. I'm going to try and start it again as an ASP.NET web application. If you know of the best way to initiate a project like this in Visual Studio 2010, let me know.

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Thu Feb 16, 2012 11:43 am

Ah ha! I fixed it!

The problem was that my class and namespace had the same name. I changed the name of the class and now it's happy.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Thu Feb 16, 2012 11:47 am

OMG what is that simple ?!?!
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Thu Feb 16, 2012 12:02 pm

Apparently. With the reference set in the ASCX file, and by changing the class reference in the ASCX.CS file, I don't get errors loading the page anymore. Now it's down to testing the dll to make sure it works correctly.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Tue Feb 21, 2012 9:56 am

LOL some days you get the bear, other days the bear gets you :D
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

Post Reply