To embed some IronPython Code into C# I want to use the ScriptEngine
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
I found the reference for IronPython, but where is the necessary reference for Scripting.Hosting? I can't find it within VisualStudio 2008, targeting .Net 3.5.
The DLR is actually broken into 2 parts:
the "inner layer" which is included in .NET 4.0 and is part of System.Core.dll (and on downlevel platforms is available as Microsoft.Scripting.Core.dll)
the "outer layer" which is available on CodePlex and ships w/ IronPython and IronRuby and is in Microsoft.Scripting.dll and Microsoft.Dynamic.dll. This part does not ship w/ .NET 4.0.
It looks like this is part of the DLR binaries ... more information here:
https://blogs.msdn.com/seshadripv/archive/2008/06/24/how-to-write-a-simple-dlr-host-in-c-using-hosting-api.aspx
Microsoft.Scripting is part of the Dynamic Language Runtime. The Dynamic Language Runtime is part of .NET 4, IronPython and IronRuby and is also available standalone.
John Lam, the lead developer of IronRuby, created a little library called repl-lib, which implements a simple editor/REPL hybrid for IronRuby and IronPython which you can just drop into your application. In a blog post, John Lam demonstrates how he used repl-lib to add scripting to the Witty .NET Twitter client in 8(!) lines of code (plus 90 or so lines of XAML for the REPL UI and the REPL button).
That blog post is based on a presentation at TechEd 2009, which I unfortunately don't have access to, but if you do, you should check it out.
Be sure to also check out the forks of repl-lib, especially Jim Deville's.
I suggest that you use NuGet instead of managing the binaries yourself.
This worked for me.
http://nuget.org/packages/DynamicLanguageRuntime.Net40.Unofficial
Related
I'm trying to get Saxon 9.7 HE up and running in C#, and failing miserably.
As per instructions, I am downloading and running https://sourceforge.net/projects/saxon/files/Saxon-HE/9.7/SaxonHE9-7-0-14N-setup.exe/download
This installs a bunch of files into C:\Program Files\Saxonica\SaxonHE9.7N.
In the bin folder inside this one, the following files are present:
No matter which DLLs I add as references to my project, the "using Saxon.Api;" reference fails to resolve.
Am I using the correct DLLs here? Is it some sort of .Net version mismatch? My class library project is set to .Net 3.5 currently.
Thanks for any help
The minimum supported version of .NET for Saxon is indeed 4.0.
The bug is in the documentation which will be updated shortly: See bug issue: https://saxonica.plan.io/issues/3085
Thanks for reporting the issue.
Some guess work here. But the dependency on .net 4 is most likley from the compiling of the C# wrapper over the saxon java library that was converted using IKVM. IKVM says it only requires .net 2.0, so I think the only place that dependancy can come from is the saxon9he-api.
You should be able to build this yourself, its quite thin.
https://dev.saxonica.com/repos/archive/opensource/latest9.7/hen/csource/api/Saxon.Api/
Otherwise if its a show stopper ask Michael Kay (the author), he's pretty active on stack overflow.
Updated
I was curious so I checked, the .Net 4 dependency seems to come from the saxon9he-api (which i'm fairly certain could be re-compiled under 3.5 with no/minimal changes), the same for the Query and Transform exe's.
I am working on a game using Unity3D version 5. The game should use strict business rules already programmed in a C# .NET4.5 engine. Using Xamarin/Mono, we hope to make this usable on windows, android, others...
I tried building the engine into a dll and use it as a managed plugin in Unity. But Unity uses an old version of Mono to compile the whole game and refuses to use .NET 4.5 dlls.
I really need to use this code, I looked into downgrading it to .NET 3.5 but it is not an acceptable solution given the work already done on the engine.
Concerning android, I think to use Xamarin to get native android code and use it as a native plugin in Unity. Now I need a solution for Windows. I am looking into ways to use the C# code in C++ to make an unmanaged dll but I am struggling understanding which way is applicable here between COM interop, C++/CLI or other methods.
Does any one knows a way to include code from .NET 4.5 in Unity with no/little effort ?
Looks like Unity is upgrading to 4.6+ and is available in beta now
https://forum.unity3d.com/threads/upgraded-mono-net-in-editor-on-5-5-0b4.433541/
Using a visual studio plugin: unmanaged exports, I have been able to export the C# .NET 4.5 to an unmanaged/native dll which I can use in Unity Engine.
This forces to call only simple functions, but with little work, it was possible for me to wrap the core of my engine.
Short answer is no.
Unity has ".NET 2.0/3.5 era functionality," according to an official blog post.
According to the same post, a future version of Unity will be upgraded to "a modern version of .NET," with no timeline given for this major undertaking.
NOTE: This answer was written in response to the original version of the question, which was simply whether the .NET 4.5 library could be used directly in Unity.
When I'm writing a C# (or any .NET programme) I use methods and classes. Most of the code I use is calling methods from the .NET classes. Is it possible (purely out of curiosity) to see the actual source code for these classes?
I know MSDN has full listings of the classes, their properties and their methods. But I would like to see the code.
Yes, it is:
Browse the .NET Framework source code online, with search and navigation powered by Roslyn.
See details at the .NET Framework blog...
Yes it is possible. See here for more info:
http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx
You can also run a disassembler (such as the one in Reflector) over the base class libraries and view code that way, if you don't want to configure your dev environment. You won't get real variable names or comments, but for isolated viewing this can be easier.
Yes, Microsoft has released the source .NET.
This article should help get you started.
The link mentioned in the accepted answer (https://referencesource.microsoft.com/) only contains .NET source up to version 4.8. Development is now done on Github, where you can find (literally) up-to-the-minute versions of the source files.
The dotnet Github organization (the .NET Foundation) has many of the repos relating to .NET, including core, the CLR runtime, aspnetcore, and a bunch of others. Most of the source code is organized into Visual Studio projects and solutions, so you can import them easily.
Is there an API to access Subversion from C#?
SharpSvn is a new Subversion wrapper library for .Net/C# that hides all interopand memory management for you and includes a staticly compiled Subversion library for easy integration. It is probably the only Subversion binding designed to perform well in a multithreaded environment.
SharpSvn is not platform independent, but it makes it really easy to use Subversion from your .Net applications. Several projects switched from other libraries to using SharpSvn in the last year. (AnkhSVN, Collabnet desktop for Visual Studio, SharpForge, to name a few)
Svn.NET is a continuation (fork) of SubversionSharp mentioned in CMS's answer. SubversionSharp is limited to the .NET 1.1 platform.
Svn.NET supports the following platforms:
.NET 2.0 on Windows Platforms
Mono on Win32 (2.0 framework)
Mono on Linux (2.0 framework)
Check SubversionSharp, its basically a C# wrapper library that fully covers the client API of Subversion.
I tried Svn.NET at one point and remember that it didn't do everything that I was looking for. If Svn.NET works for you I'd definitely recommend that route, but if you have problems like I did you can get wild and try using http://www.ikvm.net/ to convert http://svnkit.com/ to a .NET assembly. I definitely got this to work and was experimenting with it in my project when we decided to move away from SVN after all and I shelved the whole thing.
Two Questions:
Is there any way to write cross platform programs on Microsoft Visual Studio?
If there isn't then could I write a C# application on VS2008 and recompile it with MonoDevelop and have it work?
1 - I dont' think so. Not without something like Mono.
2 - Yes you can, but Mono doesn't cover all the framework - they are working on it.
The best thing to do is check with the Mono Migration Analyzer. The Mono Migration Analyzer (MoMA) tool helps you identify issues you may have on Mono - http://mono-project.com/MoMA.
I have found most of my .NET 2.0 applications can be converted, but you may need some tweaks.
You can always use C++ and QT. Soon QT will be released on LGPL license (from version 4.5) that will give some more freedom.
The only limit of using free QT license is that you don't get integration with VS. However this can be handled by using eg. CMake (which will generate VS solution files).
Yes, Write your code, compile and run on another platform using Mono. When you compile you generate IL, which Mono can use. Note: Some functions aren't available on Mono. Delphi Prism, is an add on for Visual Studio which allows you to code to Linux and Mac from VS albeit in the object Pascal language though.
Yes, see same issues as in 1
I agree with Joe90, just one thing he left out: MonoDevelop can compile .sln and .csproj files because it has a MSBuild implementation.
So point MoMA at your code and if you get a green light it should compile as-is in MonoDevelop.
As a MSCLR junkie I have to admit that Mono has a few 'better' implementations of certain critical functions (mostly to do with encryption). You will get more usability power from these.
Another thing to watch out for is subtle logic errors. If a class is implemented in Mono it does not mean that it will behave the same the MSCLR one (Mono is a cold-room implementation and as such they DO NOT use the original source code). This is really where you will get good results from a well unit-tested code base.
For a good indication of what you should expect, I remember seeing a large amount of #if MONO in the AgsXMPP repository.
You could ideally write a C# application and have it run on the Mono platform. BUT, that will depend on the libraries of MS .NET that has been ported yet to Mono.
Just in case, there is no language constraint, you could consider using other languages like Java, Python, Ruby and the like..
Good Luck!
As many others mention your success will depend on the libraries you use. Mono does have Winforms but I would suggest that you also look at GTK# http://www.mono-project.com/GtkSharp as your windowing library. If you use GTK# you will use a library which is not reverse engineered (as Winforms is in Mono).
My understanding is that "non-gui" .NET 2.0 stuff is pretty much in place with the newest versions of Mono
You don't need mono develop, the whole idea of mono is you can develop for .net and have the same assemblies work on both mono and .net, provided you only use stuff which has been implemented in mono.
Stuff which won't work:
pinvoke,
wpf,
linq to SQL
Stuff which will work:
.net 2.0,
c# 3.0 (including linq to objects and linq to xml),
winforms
If you write your application in Silverlight, anyone with a web browser and the Silverlight plugin can access your app. This is as cross-platform as you're going to get with .NET.