how to use classes written in IronPython in VB.NET - vb.net

I have a class (e.g. MksMath) written in IronPython using SharpDevelop 3.2. After compiling it for class library, it produced the following output:
IronPython.dll
IronPython.Modules.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.Core.dll
Microsoft.Scripting.Debugging.dll
Microsoft.Scripting.dll
Microsoft.Scripting.ExtensionAttribute.dll
mksmath.dll
If I try to add reference to all above dll and import "MksMath", I am unable to access it. The vbc is throwing the following error:
Namespace or type specified in the Imports 'MksMath' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
I am new to IronPython. Kindly advise how to use this class in my vb.net code?

I post here my answer that I posted to IronPythopn mailing list :-)
You cannot use mksmath.dll directly from VB (see Compiling Python code into an assembly) so you have to host IronPython engine in your VB app and use mksmath.dll from the engine. See Using Compiled Python Classes from .NET/CSharp IP 2.6 for example (in C#).

Here is a link that I think may solve the issue. http://msmvps.com/blogs/theproblemsolver/archive/2008/08/14/calling-ironpython-functions-from-net.aspx

Related

Microsoft.AspNet.Identity.Owin.OwinContextExtensions doesn't seem to work

I am creating a custom asp.net.identity provider in a separate assembly in order to use it from two different web api 2 projects.
I took the default vs2013 template for a web api project as a guide and so far I have implement the required classes.
In the separate assembly I am using a user manager class derived from Microsoft.AspNet.Identity.UserManager(Of T) class.
Public Class EzeUserManager
Inherits UserManager(Of EzeIdentityUser)
Now I want to implement the create shared function in order to use as a callback in the CreatePerOwinContext function. According to the template, I am declaring it like this:
Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin
Public Class EzeUserManager
Inherits UserManager(Of EzeIdentityUser)
... Class Implementation ...
Public Shared Function Create(options As IdentityFactoryOptions(Of EzeUserManager), context As IOwinContext)
Dim Result As New EzeUserManager(New EzeIdentityUserStore(context.Get(Of EzeLDAPContext)()))
The problem is that
context.Get(Of EzeLDAPContext)()
fails because it requires a key.
From the template I can see that the get method which doesn't require a key is an extension defined in Microsoft.AspNet.Identity.Owin.OwinContextExtensions which I have already installed and referenced through nuget and imported it in the class.
But it doesn't work.
I found that the key is actually the type name of the class so probably I can overcome this problem, however I didn't try it yet because I really want to make the extensions to work.
The question is: Am I missing something here?
Notes: The project in question is a Class Library targeting .NET 4.5.1 with the following references:
Microsoft.AspNet.Identity.Core
Microsoft.AspNet.Identity.Owin
Microsoft.Owin
Microsoft.Owin.Security
Microsoft.Owin.Security.Cookies
Microsoft.Owin.Security.OAuth
Newtonsoft.Json
Owin
As I explained in the question, I was using the template generated by VS as a guide. During the implementation process of my project, I had update the nuget packages several times but only in my project not in the template project (same solution) since I was going to deleted it afterwards. This resulted the two projects to reference two different versions of the required assemblies.
I don't know how exactly and why this "multi" reference caused this problem but once I updated the template project's nuget packages the problem was resolved.
I hope this helps someone with a similar issue.

Where To Find Host Class For Using Statements in VB.NET

I am following this tutorial
and like many other tutorials, it is very vague as to where to insert code. Which vb.net file would I insert the host class to begin adding the using statement?
I have a file called crawler.aspx...this accepts html and the like. I also have crawler.aspx.vb...tried adding the code there and received an error saying that the statement could not be used outside of the method/body lambda.
The code example is in C#. The equivalent VB.NET directive is Imports. It tells the compiler that you will be using classes and methods and such from the specified assembly.
As long as you have a reference to the assemblies in your project (which if you installed this via NuGet you should), you can simply add the following lines to the top of your file containing the code of the host class, like this:
Imports Abot.Crawler
Imports Abot.Poco
This should not be confused with the Using statement, which is something different entirely.

Using CreateObject ActiveX component can't create object w/ Registered Class Library

I have written some classes in visual basic.net and want to use them in a visual basic 6 application.
Now I have registered the tlb/dll files on my computer and I am able to create an instance of the class in vb6 with
Dim c As New Advantage_Dealer_Email_CoreClassLibrary.CoreClass
However I want to use CreateObject(Class) but when I try I get the ActiveX error, here is the code I am using for that
Dim c As Object
Set c = CreateObject("Advantage.Dealer.Email.CoreClassLibrary.CoreClass")
Is this possible what am I doing wrong?
Thanks
Update:
After searching through the registry I am only able to find a CLSID which references Advantage.Dealer.Email.CoreClassLibrary.
{CFB8F7A1-BC6F-4771-839F-1343785ED9D6} > 1.0 > (Default) REG_SZ Advantage.Dealer.Email.CoreClassLibrary
Solution
I had another look in the registry and found a Guid called
CoreClassInterface
which referenced the library, when I used the code
CreateObject("CoreClassInterface")
the vb6 program worked.
For anyone that comes across this post in the future it was because I had set the ProgID in the vb.net class when setting up the class with an interface for the Com Interop.
<Guid("7EB55A33-34E7-4FC4-A87B-41635EEAF32D"), ClassInterface(ClassInterfaceType.None), ProgId("CommClassInterface")> Public Class CoreClass : Implements _CoreClassInterface
After removing the ProgID for the class and rebuilding/registering the library on my computer I found
Advantage.Dealer.Email.CoreClassLibrary.CoreClass
In the Registry, and my vb6 app worked.
Thanks for your help tcarvin
I find it best, when creating .NET libraries for consumption by VB6, to keep the namespace of COM-visible classes to only one-layer deep to avoid the underscores. Anyway, have you attempted to use:
CreateObject("Advantage_Dealer_Email_CoreClassLibrary.CoreClass")
When all else fails, the answer is in your registry. Use regedit and see what the component is listed under.

Can I import a dll for one class only?

Good day,
I have used dll imports for "user32.dll" in the past.
However, I am trying to import a class library into my application which has some namespaces which come into conflict with namespaces which are already imported and referenced from other class libraries.
How can I reference this dll and only use the namespaces contained in it, or override the other namespaces imported from other class libraries in one class without it affecting the rest of the application.
I am still pretty new, this may not be possible.
Thank you.
To summarize the relevant issues:
In VB.NET one can use the Declare statement to call win32 functions in DLL's with typical EntryPoint constructs.
.NET Assemblies do not provide classical Win32 type EntryPoints (as such they cannot be 'declared')
If one needs to reference a .NET Assembly [or COM] you need to add a reference to the target library when compiling (usually done in the VS IDE or with the /r: switch)
In some cases Namespaces of such referenced Assemblies may collide with others. (i.E. referencing the same Assembly in different versions)
In that case one needs to import the required (conflicting) Namespaces with an Alias
For example:
Assuming you have an assembly with a root namespace Net that could collide with System.Net use:
Imports System
Imports ExtNet = SomeNetworkAssembly
Then in this case to access members of that assembly use ExtNet instead of Net
Note you can name the ExtNet part as you wish.
In C# one can do it via the using keyword instead.

MVC2 Extension Methods throwing errors in my views

I have a project written in MVC2 and VB.NET. I use a lot of htmlhelper extension methods, and I have them all in a public module. They work just fine, and I can compile and run my project. I reference the namespace they are in with this:
<%# Import Namespace="MyProject.WebUI.Extensions" %>
So, again, they work great, my project runs and compiles without a hitch.
The problem is that each one of these extension methods is shown as an error:
Error 33 'TabbedMenu' is not a member of 'System.Web.Mvc.HtmlHelper(Of Object)'. C:\Projects\MyProject\MyProject.WebUI\Views\Shared\Site.Master 23 21 MyProject.WebUI
This doesn't prevent the project from compiling and running, it just creates an error, which is annoying. I've tried looking for solutions, but all of the solutions I've found were for projects that don't compile, all with simple solutions like referencing the right namespace or making sure your module is declared public. Any thoughts?
Have you included an import statement in your site.Master to include the extensions class where your extensions are defined. Also I assume your extension class is a public static class with public static methods defined?
Also check this out if you haven't already, it may be related to what you are after.
How do I use an extension method in an ASP.NET MVC View?
You need to import the namespace where you have placed your extension. And since it is a bit annoying that this problem shows up no sooner than in runtime, you can enable view compilation to have the compiler detect the problem. I should warn you that compiling the views is a time consuming operation though.