Z3_test_1.exe[2448] unhandled exception in Microsoft .net framework - z3

I wrote the following program in visual studio 2010(Version: 10.0.30319.1 RTMREL) with C# language and the version of .net framework is 4.0.30319 RTMREL. There is no errors or warnings when compiling, but it throw an exception when running the program. The exception is that "Z3_test_1.exe[2448] unhandled exception happened in Microsoft .net framework", Where Z3_test_1.exe is the program file name. The Z3 prover I used is in version Z3 4.0 and in the program i used Microsoft.Z3.dll rather than Microsoft.Z3V3.dll.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Z3;
//using Microsoft.Z3V3;
namespace Z3_test_1
{
class Program
{
static void Main(string[] args)
{
using (Context ctx = new Context())
{
RealExpr c = ctx.MkRealConst("c");
BoolExpr Eqzero = ctx.MkGt(c,ctx.MkReal(0));
BoolExpr Gezero = ctx.MkGe(c,ctx.MkReal(0));
BoolExpr Lttwo = ctx.MkLt(c,ctx.MkReal(2));
BoolExpr Gtthree = ctx.MkGt(c,ctx.MkReal(3));
BoolExpr b1 = ctx.MkBoolConst("b1");
BoolExpr b2 = ctx.MkBoolConst("b2");
BoolExpr b3 = ctx.MkBoolConst("b3");
BoolExpr b0 = ctx.MkBoolConst("b0");
RealExpr[] lamb=new RealExpr[1];
lamb[0]=ctx.MkRealConst("lamb");
BoolExpr temp=ctx.MkAnd(ctx.MkGt(lamb[0],ctx.MkReal(0)),ctx.MkEq(b0,ctx.MkTrue()),ctx.MkEq(b1,ctx.MkTrue()),ctx.MkGe(ctx.MkAdd(c,lamb[0]),ctx.MkReal(0)),ctx.MkLe(ctx.MkAdd(c,lamb[0]),ctx.MkReal(3)),ctx.MkGe(c,ctx.MkReal(0)),ctx.MkLe(c,ctx.MkReal(3)));
BoolExpr exist = ctx.MkExists(lamb, temp, 1, null, null, ctx.MkSymbol("Q2"),ctx.MkSymbol("skid2"));
Console.WriteLine(exist.ToString());
Solver s1 = ctx.MkSolver();
s1.Assert(exist);
if (s1.Check() == Status.SATISFIABLE){
Console.WriteLine("get pre");
Console.Write(s1);
}
else
{
Console.WriteLine("Not reach");
}
Console.ReadKey();
}
}
}
}

I tried to reproduce your errors. The test works just fine for me.
I suspect it is the same compilation problem that Leo points out because it worked for me. The subtle problem is that if you reference an x86 assembly from a x64 environment, or the other round, then runtime errors start happening. The fool-proof way is to add a /platform indication with the arguments you pass to the compiler (csc.exe).

Related

pragma solidity - compilation error in jpmorganchase cakeshop

I am running a simple code from SimpleStorage example and just added few lines on top of it which I was using for my other contracts. The contract compiles fine from truffle. But on the Cakeshop Integrated IDE it shows compilation error.
pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;
contract SimpleStorage {
uint public storedData;
event Change(string message, uint newVal);
function SimpleStorage(uint initVal) {
Change("initialized", initVal);
storedData = initVal;
}
function set(uint x) {
Change("set", x);
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
It should compile on the cakeshop web UI as it compiles on local machine
Utilizing Remix, it seems the following could be potential issues with your contract:
You are using the Contract name for the constructor. You should use the constructor keyword instead.
All of your functions are missing visibility modifiers. Consider adding the public modifier to each function including the constructor.
Events should be invoked using the emit keyword. Example: emit Change("set", x);

Missing method exception while InvokeMember

I'm creating a COM component in F#. The component is expected to be used from scripting.
The component code:
namespace WebUIPlugin
open System
open System.Windows
open System.Runtime.InteropServices
[<Guid("BAEF0C5B-EFA5-4868-8342-7A1E6F8F7AF4")>]
type IPlugin =
[<DispId(1)>]
abstract OpenFormFromFile : path:string -> unit
[<Guid("8D71E2DB-D718-4595-B856-58D14EEAEBB2");
ClassInterface(ClassInterfaceType.None);
ComVisible(true)>]
type Plugin = class
new () = {}
interface IPlugin with
member this.OpenFormFromFile(path) =
let showWindow =
let window = Window()
window.Show
UI.spawn showWindow |> ignore
end
end
I'm registering it with regasm /codebase Plugin.dll and it works well from scripting cscript test.js.
test.js is following:
var obj = new ActiveXObject("WebUIPlugin.Plugin");
obj.OpenFormFromFile("");
It even stops on breakpoint in OpenFormFromFile. So good so far.
Unfortunately, I cannot make it work from F#/C#:
let objectType = Type.GetTypeFromProgID("WebUIPlugin.Plugin")
let handler = Activator.CreateInstance(objectType)
objectType.InvokeMember("OpenFormFromFile", BindingFlags.InvokeMethod, null, handler, [|""|]) |> ignore
var objectType = Type.GetTypeFromProgID("WebUIPlugin.Plugin");
dynamic handler = Activator.CreateInstance(objectType);
objectType.InvokeMember("OpenFormFromFile", BindingFlags.InvokeMethod, null, handler, new object[]{""});
The code throws exception:
An unhandled exception of type System.MissingMethodException occurred in mscorlib.dll
Additional information: Attempted to access a missing member.
Everything (component, test C# and F# projects, regasm, cscript) is either in x64 or x86 consistently. With the same result - WSH script works, .NET assembly does not.

Awaiting an IAsyncOperation in F#

I have the following code in F#:
let CreateSampleDataFromJson<'T>(path) =
let uri = new Uri(path)
async {
let file = StorageFile.GetFileFromApplicationUriAsync(uri)
let jsonText = FileIO.ReadTextAsync(file)
return JsonObject<'T>.Parse(jsonText)
}
The problem I'm having is that file is an IAsyncOperation<StorageFile> and not a StorageFile as ReadTextAsync expects.
In C# you can do something similar to this:
var file = await StorageFile.GetFileFromApplicationUriAsync(uri)
i.e.
public async Task<T> CreateSampleDataFromUrl<T>(string path)
{
var uri = new Uri(path);
var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
var jsonText = await FileIO.ReadTextAsync(file);
return JsonObject<T>.Parse(jsonText);
}
The problem is that I don't know how to await an IAsyncOperation in F#. The usual let! doesn't work. i.e. the following fails to compile:
async {
let! file = StorageFile.GetFileFromApplicationUriAsync(uri)
With the compiler error:
error FS0001: This expression was expected to have type Async<'a> but here has type IAsyncOperation<StorageFile>
I found a document that said there's an AsTask() extension method defined in the System.WindowsRuntimeSystemExtensions class which I can use as follows:
let! file = StorageFile.GetFileFromApplicationUriAsync(uri).AsTask() |> Async.AwaitTask
Is there a standard way of doing this or something available in an F# library somewhere that makes this a bit nicer?
Your solution seems fine by me. If you're looking for a nicer syntax, how about rolling it into a function like this (without the possibly gratuitous type annotations):
let await<'a> (op: IAsyncOperation<'a>) : Async<'a> =
op.AsTask() |> Async.AwaitTask
This will give you the almost exact same syntax you'd see in c#:
async {
let! file = await <| StorageFile.GetFileFromApplicationUriAsync(uri)
...
}
The compiler errors you were getting with your previous approaches are to be expected. All async workflow cares about is the F#-specific Async type. This type gives you a way to interop with the rest of .NET world through Tasks, but that's it. IAsyncOperation is from a 'different part of the world', I wouldn't expect F# core libraries to support it anytime soon.

localization with c++ builder 2009 reinit.pas

I am loacalizing a RAD Studio 2009 C++ Builder project. In the IDE I can use Project/Language/Acivate to choose a language before the program starts. That works fine.
Now I want to change languages at runtime. In order to do that I need the Delphi unit reinit.pas which curiosly enough, isn't included in my installation. I found two versions somewhere on the net. The one is dated Aug.9,2002. The other one is dated March 9, 2013. There are two buttons on the form which call the respective methods below in order to switch to the appropriate language.
void __fastcall TFormMonitor::ButtonEnglishClick(TObject *Sender)
{
const cEnglish = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
if(LoadNewResourceModule(cEnglish))
{
ReinitializeForms();
}
}
//---------------------------------------------------------------------------
void __fastcall TFormMonitor::ButtonDeutschClick(TObject *Sender)
{
const cGerman = (SUBLANG_GERMAN | LANG_GERMAN);
if(LoadNewResourceModule(cGerman))
{
ReinitializeForms();
}
}
Both versions of reinit.pas have the same behavior. ReinitialzeForms() throws a class EReadError excecption with the comment "Ancestor not found".
Where can I get a version of reinit.pas that matches the C++ Builder 2009?
Or is the EReadError exception caused by some the problem?
I've aleady done hours of researching on the net and have not come up with a solution.
Thanks for your help,
Derl
This error is raised because there is one or more components whose Name property is empty (""). To solve this problem, the empty-Name component should be found and set a name. The code to find the empty-name component in the application is:
TComponent *pform, *pcomponent;
AnsiString NoNameComponent;
for( int ff=0; ff< Application->ComponentCount; ff++) {
pform = Application->Components[ff]; // get a form
for( int i=0; i< pform->ComponentCount; i++ ) {
pcomponent = pform->Components[i]; // get a component
if( pcomponent->Name == "" ) {
NoNameComponent = pcomponent->ClassName()
+" at "+pform->Name + "has no name";
}
}
}

How to inherit the same generic interface twice with different types in F# 3.0 [duplicate]

In C#, I can implement a generic interface twice on one class, using two different type-parameters:
interface IFoo<T> { void Foo(T x); }
class Bar : IFoo<int>, IFoo<float>
{
public void Foo(int x) { }
public void Foo(float y) { }
}
I would like to do the same thing in F#:
type IFoo<'a> = abstract member Foo : 'a -> unit
type Bar() =
interface IFoo<int> with
[<OverloadID("int")>]
member this.Foo x = ()
interface IFoo<float> with
[<OverloadID("float")>]
member this.Foo x = ()
But it gives a compiler error:
This type implements or inherits the same interface at different generic instantiations 'IFoo<float>' and 'IFoo<int>'. This is not permitted in this version of F#.
I can't find any discussion of this issue on the web. Is such use frowned upon for some reason? Are there plans to allow this in an upcoming release of F#?
Right now I don't know of plans to allow this.. The feature has been planned and is, at least partially (see comments) implemented in F# 4.0.
I think the only reasons its currently disallowed are that it's non-trivial to implement (especially with F# type inference), and it rarely arises in practice (I only recall one customer ever asking about this).
Given an infinite amount of time and resources, I think this would be allowed (I can imagine this being added to a future version of the language), but right now it does not seem like this is a feature worth the effort of supporting. (If you know a strong motivating case, please mail fsbugs#microsoft.com.)
EDIT
As an experiment for the curious, I wrote this C#:
public interface IG<T>
{
void F(T x);
}
public class CIG : IG<int>, IG<string>
{
public void F(int x) { Console.WriteLine("int"); }
public void F(string x) { Console.WriteLine("str"); }
}
and referenced it from F# (with comments suggesting the results)
let cig = new CIG()
let idunno = cig :> IG<_> // type IG<int>, guess just picks 'first' interface?
let ii = cig :> IG<int> // works
ii.F(42) // prints "int"
let is = cig :> IG<string> // works
is.F("foo") // prints "str"
so this is what typically happens on this 'boundary' stuff with F# - F# can consume this stuff ok, even if you can't author the same stuff from within the language.
There is a reasonable although not elegant way to do it, create a new type for each interface here is an example of consuming multiple events from an ESB (nSvcBus) which requires that each event corresponds to an implemented interface. The first type below contains the generic 'handler' code, the other types just implement the interface and call to the generic handler
type public nSvcBusEvents() =
member this.HandleEvents(msg:IEvent) = ()
//handle messages ie: let json = JsonConvert.SerializeObject(msg)
type public ActionLoggedHandler() =
interface IHandleMessages<Events.ActionLoggedEvent> with
member this.Handle(msg : ActionLoggedEvent) =
nSvcBusEvents().HandleEvents(msg)
type public ActionCompletedHandler() =
interface IHandleMessages<Events.ActionCompletedHandler> with
member this.Handle(msg : ActionCompletedHandler) =
nSvcBusEvents().HandleEvents(msg)
type public ActionFailedHandler() =
interface IHandleMessages<Events.ActionFailedHandler> with
member this.Handle(msg : ActionFailedHandler) =
nSvcBusEvents().HandleEvents(msg)

Resources