servicehost constructor doesn't initialize its members in linux (mono - vb.net) - vb.net

I wrote a simple program since my application doesn't work in mono. But even that simple program doesn't work and I understand is the ServiceHost constructor that doens't initialize its member (despite the fact that in mono source code you can see correct instructions).
I use mono/.net 4.0 ('mono --version' says 4.0.1, monodevelop 5.10, ubuntu 14.04.2 lts (32bit). I've tried to add the dll needed (ver 4.0) in the exe path, but nothing change.
That's the easy code I uses (in .Net no errors, in linux "invalid IL code in System.ServiceModel.ServiceHostBase:get_Credentials() : IL_0000 ret").
Imports System.Security.Cryptography.X509Certificates
Imports System.servicemodel
Public Interface IMyService
Sub DoSomething()
End Interface
Public Class CMyService
Implements IMyService
Public Sub DoSomething() Implements IMyService.DoSomething
Console.WriteLine("-dosomething-")
End Sub
End Class
Module Module1
Sub Main()
Dim h As New ServiceHost(GetType(CMyService), New System.Uri("net.tcp://127.0.0.1/10000"))
'if you check 'h', you'll see all its member set to Nothing :(
h.Credentials.ClientCertificate.Authentication.CertificateValidationMode = Security.X509CertificateValidationMode.None
End Sub
End Module
It is compiled succesfully but it throws an exception if executed.
As reported on source code, if you check members of variable 'h' I have all its items set to 'Nothing'.
I've tried using 32bit and 64bit exe compiled on Windows 7 using Xamarin Studio and Visual Studio (they work great on Windows, but same error in mono). I used in ubuntu the dll copied from Windows .net 4.0. Obviously the 64bit version doesn't even start. I even compiled inside linux using monodevelop 5.10 but I get the same runtime error.
I changed "System.Security.Criptography.X509Certificates" in "Mono.Security.Criptography.X509Certificates" changing also the dll, but in linux I have the same error invariably.
What can I do/check?
I'm stuck for 2 days :/
Thank you in advance.
Update 1
I converted the source code in c#, compiled with mcs, which suggests using also System.IdentityModel.dll. The application in c# works this way. I then update the project in monodevelop, it compile and I can do step-by-step in that IDE.
Then I updated the vb.net project, adding the "missing" dll. It compiles again correctly under monodevelop and the step-by-step debug stops again for the same reason.
Then I compiled using vbnc and it works. But I cannot debug inside the IDE.
I cannot understand why... I hope I must not convert all my source code to C# to see other "missing dll", and guess strange behavour of monodevelop...
Maybe I try to add the 'missing' dll in Windows 7, compile and see what linux says.
Update 2
Linux doesn't like the program compiled in Windows 7, it must be compiled in linux using vbnc by command line.

The problem was solved compiling the test program in linux with vbnc called by command line (for some unknown reason, monodevelop compile correctly only the c# version and not the equivalent version in vb.net).
So it's impossible to do a step-by-step debuggin using monodevelop and vb.net, but it works using c#.
During compilation in c# (using msc) a warning about a missing dll (System.Identity.dll) appears. Microsoft exe doesn't need it, mono does, but only msc tell you about it. I find info about it nowhere, so maybe it can be usefull to someone else... I was 3 days stuck on this :/

Related

VB.NET EntryPointNotFoundException

I have a .DLL file for x64 architecture without adequate documentation. I tried the following as a .NET Core Console App in Visual Studio 2017 adding the DLL as a reference:
Imports System
Module Program
Sub Main(args As String())
Dim newObject As NewNamespace.NewInterface
'Create New Instance
newObject = NewNamespace.Factory.Instance.Create()
'Do something
'Clean up
NewNamespace.Factory.Instance.Destroy()
End Sub
End Module
When I tried to run the code in Debug for X64 CPU I get the following error:
System.TypeInitializationException
EntryPointNotFoundException: A library name must be specified in a DllImport attribute applied to non-IJW methods.
EDIT: Removed a lot of unnecessary information
Using the same code and references in a .Net Framework Console project in VS2017 build and ran the code without error.

Xul.dll missing dependencies after upgrade from Xulrunner and Gecko 14 to 33 due to Xpcom.dll conflict

I'm using Xulrunner and GeckoFX in a vb application (version 33.0-0.1 for both), and when debugging the application, the line
Gecko.Xpcom.Initialize(System.IO.Directory.GetCurrentDirectory() & "\xulrunner")
throws the exception:
Unable to load DLL 'xul': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Note that regardless of how I call the Initialize() function, the exact same exception comes up. I've tried:
Gecko.Xpcom.Initialize()
Gecko.Xpcom.Initialize(System.IO.Directory.GetCurrentDirectory() & "\xulrunner")
Gecko.Xpcom.Initialize(System.IO.Directory.GetCurrentDirectory() & "\bin\xulrunner")
Gecko.Xpcom.Initialize("C:\full path here\xulrunner")
This question Unable to load DLL (Module could not be found HRESULT: 0x8007007E) led me to use Dependency walker to check the dll.
Checking the dll showed that I was "missing" a slew of other things, as shown below:
That in turn led me to Win 7, 64 bit, dll problems, which also didn't help. While DW does show some of the same missing DLLs, it's also showing other ones that aren't listed in that question.
Of the offered solutions in that question, I've tried:
reinstalling the VS Redistributable Package
running 'sfc /scannow'
I've noticed in the aforementioned question that some people are saying it's an issue with OCX files instead of the DLL, but I'm not sure how to even start on that end. I couldn't find any OCX files in the project directory.
I realize that the problem may also lie in how I implemented GeckoFX and Xulrunner. Previously, this application was working using SkyboundGecko, GeckoFX, and Xulrunner. It seems that the previous developer working on this application followed this tutorial (or something very similar) using version 14 of GeckoFX and Xulrunner. However, this recently started causing problems for some customers using the application, as there was an Xpcom.dll conflict with a different application they were using. This issue only applies to those customers which had application X (I don't remember the name) installed on their computer. Other computers did not have this issue.
A bit of research has led me to believe that more current versions of GeckoFX and Xulrunner no longer require XPCom.dll, which means that an upgrade should in theory resolve this issue.
Thus, I started (loosely) following this tutorial in order to upgrade Gecko and Xulrunner. I removed the previous reference to the Skybound.Gecko.dll, and replaced Xulrunner with a newer version. I also downloaded and extracted the GeckoFX DLLs and files. My Bin now looks like this:
I added the reference to Gecko back to the project, and changed any references of Skybound.Gecko.xxxx to Gecko.xxxx. (Perhaps this tells you something that I don't know/haven't realized, since the tutorials I've seen never use Gecko.xxx - the function calls, for example, are Xpcom.Initialize() instead of Gecko.Xpcom.Initialize())
I'm running Windows 8 on Windows Server 2012 R2 Standard, 64 bit OS.
Is there another way to avoid the Xpcom.dll conflict, and if not, how do I resolve this issue?
If any other information is required, comment and I'll try my best to provide it.
In my case this error is caused because of I initialised xulrunner in Form1_Load function. I resolved it by initialising xulrunner in public Form1() function.
Try to initialise xulrunner as shown below,
public Form1()
{
InitializeComponent();
Gecko.Xpcom.Initialize(#"C:\Users\PAVILION\Documents\visual studio 2010\Projects\SiteFilterAutomation\SiteFilterAutomation\bin\Debug\xulrunner\");
}
private void Form1_Load(object sender, EventArgs e)
{
geckoWebBrowser1.Navigate("www.google.com");
}

regsvr32 fails for simple freepascal COM dll

I'm completely new to free-pascal and I try to implement a simple dll that should register a COM class.
Unfortunately I could only find little information about COM Programming for freepascal. Thus I hope that someone here can give me some hints or even a link to some examples.
So here is what I did:
my operating system is Windows 7 64 bit
downloaded and installed Lazarus 32bit version
Version #: 1.2.6
Date: 2014-10-11
FPC: Version 2.6.4
SVN Revision: 46529
i386-win32-win32/win64
installed the ActiveX package in Lazarus
made a new project - type Library with a simple TAutoObject and a default TAutoObjectFactory for the COM registration: source code included after this description
build the dll
use regsvr32.exe to register my dll --> this fails with
"make sure the binary is stored at the specified path ..."
Invalid access to memory location.
then I tried to change the default project options:
under Compiler Options - Config and Target, I set
Target OS: Win32
Target CPU family: i386
still the same error occurs
Project source
library LazarusSimpleComRegTest;
{$mode objfpc}{$H+}
uses
Classes,
{ you can add units after this }
ComServ, MyComObj;
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
end.
MyComObj Unit:
unit MyComObj;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, ComObj;
const
CLASS_Plugin: TGUID = '{5E020FB0-B593-4ADF-9288-801C2FD432CF}';
type
TPlugin = class(TAutoObject)
end;
implementation
uses ComServ;
initialization
TAutoObjectFactory.Create(ComServer, TPlugin, CLASS_Plugin,
ciMultiInstance, tmApartment);
end.
I think the main problem was, that I did not include the type library as a resource in my dll file: Now it works fine.
I've made a very basic and simple working example on git-hub with some basic documentation:
lazarus-com-example

Can't get System.Numerics to work with command-line Mono (mcs) on OS X

We're trying to run a simple Mono script on the command line on OS X. Most scripts work fine for us, but as soon as we try to use System.Numerics, we get "error CS0234: The type or namespace name `Numerics' does not exist in the namespace System."
This isn't too surprising, and should be fixable with an appropriate command-line option to mcs, plus properly set up PKG_CONFIG_PATH... but this is where we get stumped. First, here's the script so you can follow along at home:
using System;
using System.Numerics;
public static class MainProgram {
public static void Main(string[] args) {
Console.WriteLine("Hello world!");
}
}
So next we tried "mcs -r:System.Numerics Test.cs". This produces "error CS0006: Metadata file `System.Numerics' could not be found".
"man mcs" suggests that we can get the other system packages by adding "-pkg:dotnet" to the command line. But that produces:
Package dotnet was not found in the pkg-config search path. Perhaps
you should add the directory containing `dotnet.pc' to the
PKG_CONFIG_PATH environment variable No package 'dotnet' found error
CS8027: Error running pkg-config. Check the above output.
OK then, we had no PKG_CONFIG_PATH, so we tried defining one:
export PKG_CONFIG_PATH=/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig/
This fixes the CS8027; but we still get the CS0234 we started with. And if I combine the -pkg and the -r, e.g. "mcs -pkg:dotnet -r:System.Numerics Test.cs", I get "error CS0006: Metadata file `System.Numerics' could not be found".
I'm stumped at this point... any idea what incantation I'm missing to make System.Numerics work with mcs?
If you're using Mono 2.10.x, you will have to compile with dmcs rather than mcs to enable the 4.0 profile (System.Numerics is a C# 4.0+ feature only).
If you're using Mono 2.11.x or 3.0.x, then mcs by default should select the 4.5 profile. mcs -help should show 2, 4, and 4.5 as possible values for the -sdk option. If it doesn't, then the framework isn't properly installed; I had that once, where I think that /Library/Frameworks/Mono.framework/Versions/Current pointed to the wrong directory; installing a second time fixed that.
Manipulating pkg-config should be unnecessary.

Does mono 2.8 support 'dynamic' keyword?

I tested IronPython on mono 2.8 with the code in the book Professional IronPython p.315 listing 15-3.
using System;
using IronPython.Hosting;
using IronPython.Runtime;
using Microsoft.Scripting.Hosting;
namespace Method2
{
class Program
{
static void Main(string[] args)
{
// Obtain the runtime.
var IPY = Python.CreateRuntime();
// Create a dynamic object containing the script.
dynamic TestPy = IPY.UseFile("TestClass.py");
// Execute the __test__() method.
TestPy.__test__();
}
}
}
I see it's compiled OK, and run without a problem on Windows 7, whereas the mono 2.8 gives me the following error message.
Unhandled Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:
`Microsoft.Scripting.Hosting.ScriptScope' does not contain a definition for `__test__'
at (wrapper dynamic-method) object.CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1
(System.Runtime.CompilerServices.CallSite,object)
at Method2.Program.Main (string[])
I thought Mono 2.8 supports C# 4.0 which has the dynamic keyword, but I see that the 'dynamic' keyword is not fully supported with mono.
Is this a bug of Mono 2.8?
ADDED
This is the python script.
# The class you want to access externally.
class DoCalculations():
# A method within the class that adds two numbers.
def DoAdd(self, First, Second):
# Provide a result.
return First + Second
# A test suite in IronPython.
def __test__():
# Create the object.
MyCalc = DoCalculations()
# Perform the test.
print MyCalc.DoAdd(5, 10)
# Pause after the test session.
raw_input('\nPress any key to continue...')
This is the command that I used
dmcs Program.cs /r:System.Core /r:IronPython.dll /r:IronPython.Modules.dll /r:Microsoft.Dynamic.dll /r:Microsoft.Scripting.dll /r:Microsoft.CSharp.dll
It compiles well, but it still breaks when I run the execution binary. Do I need to have all the dlls in the same directory where the execution binary locates?
The fact that you are getting a Microsoft.CSharp.RuntimeBinder.RuntimeBinderException means that the dynamic keyword worked. The problem you are having is that IPY.UseFile("TestClass.py"); is returning a ScriptScope that doesn't see your test method. So the problem lies with your python source or how you are including IronPython with mono.
The dynamic keyword is certainly supported by Mono 2.8 when using the C# 4 profile.
I guess my question is how you are building this sample?
Just for kicks, I just pasted your sample into MonoDevelop. I had to tell MonoDevelop to use C# 4 instead of C# 3.5 first of all.
The dynamic keyword was introduced in C# 4 obviously.
Also, I did have to include a few assembly references: System.Core, IronPython.dll, IronPython.Modules.dll, Microsoft.Dynamic.dll, Microsoft.Scripting.dll, and Microsoft.CSharp.dll. I am not sure if I needed them all.
If you are building from the command-line you need to use 'dmcs' as the compiler (to indicate the .NET 4 profile) and you need to include the assembly references.
It builds without problems with this configuration (for me at least).
I am responding to this question with respect to Mono 2.10.
I could successfully build and execute the code from command line on Windows 7 without using MonoDevelop. Here are the steps:
Install Mono 2.10.8 on Windows 7.
Install IronPython 2.7.2.1.
"C:\Program Files\Mono\bin" or equivalent and "C:\Program Files\IronPython 2.7" or equivalent should be part of system path.
Both TestClass.py and Program.cs should be in the same folder.
From the dos prompt, corresponding to the folder where TestClass.py and Program.cs exists, execute setmonopath batch file.
From the same dos prompt execute the following command:
dmcs Program.cs /r:System /r:"C:\Program Files\IronPython 2.7\IronPython.dll" /r:"C:\Program Files\IronPython 2.7\IronPython.Modules.dll" /r:"C:\Program Files\IronPython 2.7\Microsoft.Dynamic.dll" /r:"C:\Program Files\IronPython 2.7\Microsoft.Scripting.dll" /r:"C:\program Files\IronPython 2.7\Microsoft.Scripting.MetaData.dll" /r:Microsoft.Csharp
Program.exe should be successfully generated and the same can be executed without any error message.