Unable to build a service with a contract

May 8, 2011 at 6:02 PM

I am currently trying to implement remote channels.

I already know exactly what I need to do but the sgc compiler (Why is it not open source? It would make so many things so much easier!) has a bug:

I am getting "EXEC : warning : the current runtime's endpoint is a struct that has no parents. If you are compiling for wince, use command line /wince. If not, use the right runtime.",

followed by: "Unhandled Exception: System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configurationsection runtime. (D:\coding\C#\Singularity\base\Build\sgc.exe.config line 3)"

It tells me that the "runtime" node is invalid in line 3.

 

However, after following the Exception stack trace and considering the Microsoft.SingSharp.dll in Reflector, I realize that the problem is caused by a bug in the parsing of contracts:

It is caused by the code generation for the endpoints in ChannelContract.AddPeekMethod (funnily called from a method of name "PreChecker"): The getter for "Singularity.Channels.Endpoint.PeerClosed" could not be found - Which is bogus since it clearly exists, in your compiled dlls, as well as inside the Singularity code.

If this project is really as dead as it seems, I will probably have to either manually translate the contract into a C# class or write a simple compiler for that.

 

Every help would be greatly appreciated!

-Domi

 

Here is the entire Exception & Stacktrace:

 Unhandled Exception: System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section runtime. (D:\coding\C#\Singularity\base\Build\sgc.exe.config line 3)
    at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
    at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
    at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
    at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
    --- End of inner exception stack trace ---
    at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
    at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
    at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
    at System.Configuration.ConfigurationManager.GetSection(String sectionName)
    at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
    at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
    at System.Diagnostics.DiagnosticsConfiguration.Initialize()
    at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
    at System.Diagnostics.TraceInternal.InitializeSettings()
    at System.Diagnostics.TraceInternal.Fail(String message)
    at System.Diagnostics.Debug.Assert(Boolean condition)
    at System.Compiler.MemberBinding..ctor(Expression targetObject, Member boundMember, Boolean volatile, Int32 alignment) in C:\cci5\SingularityDrop\System.Compiler\Nodes.cs:line 2384
    at System.Compiler.MemberBinding..ctor(Expression targetObject, Member boundMember) in C:\cci5\SingularityDrop\System.Compiler\Nodes.cs:line 2360
    at Microsoft.SingSharp.ChannelContract.AddPeekMethod(TypeNode endpoint) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Nodes.cs:line 1119							<-- This is the evil-doer!
    at Microsoft.SingSharp.ChannelContract.CheckWellFormednessOfStateMachine(Checker checker) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Nodes.cs:line 2393
    at Microsoft.SingSharp.ChannelContract.PreChecker(Checker checker) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Nodes.cs:line 952
    at Microsoft.SingSharp.Checker.VisitChannelContract(ChannelContract contract) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Checker.cs:line 1500
    at Microsoft.SingSharp.Checker.VisitClass(Class Class) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Checker.cs:line 939
    at System.Compiler.StandardVisitor.Visit(Node node) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 189
    at System.Compiler.StandardVisitor.VisitTypeNodeList(TypeNodeList types) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 1631
    at System.Compiler.StandardVisitor.VisitNamespace(Namespace nspace) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 1310
    at System.Compiler.Checker.VisitNamespace(Namespace nspace) in C:\cci5\SingularityDrop\System.Compiler.Framework\Compiler\Checker.cs:line 4462
    at Microsoft.SingSharp.Checker.VisitNamespace(Namespace nspace) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Checker.cs:line 1574
    at System.Compiler.StandardVisitor.VisitNamespaceList(NamespaceList namespaces) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 1317
    at System.Compiler.StandardVisitor.VisitNamespace(Namespace nspace) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 1311
    at System.Compiler.Checker.VisitNamespace(Namespace nspace) in C:\cci5\SingularityDrop\System.Compiler.Framework\Compiler\Checker.cs:line 4462
    at Microsoft.SingSharp.Checker.VisitNamespace(Namespace nspace) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Checker.cs:line 1574
    at System.Compiler.StandardVisitor.Visit(Node node) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 333
    at System.Compiler.StandardVisitor.VisitNodeList(NodeList nodes) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 832
    at System.Compiler.StandardVisitor.VisitCompilationUnit(CompilationUnit cUnit) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 826
    at System.Compiler.Checker.VisitCompilationUnit(CompilationUnit cUnit) in C:\cci5\SingularityDrop\System.Compiler.Framework\Compiler\Checker.cs:line 2077
    at Microsoft.SingSharp.Checker.VisitCompilationUnit(CompilationUnit cUnit) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Checker.cs:line 395
    at System.Compiler.StandardVisitor.VisitCompilationUnitSnippet(CompilationUnitSnippet snippet) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 842
    at System.Compiler.StandardVisitor.Visit(Node node) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 162
    at System.Compiler.StandardVisitor.VisitCompilationUnitList(CompilationUnitList compilationUnits) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 838
    at System.Compiler.StandardVisitor.VisitCompilation(Compilation compilation) in C:\cci5\SingularityDrop\System.Compiler\StandardVisitor.cs:line 821
    at System.Compiler.Checker.VisitCompilation(Compilation compilation) in C:\cci5\SingularityDrop\System.Compiler.Framework\Compiler\Checker.cs:line 2051
    at Microsoft.SingSharp.Checker.VisitCompilation(Compilation compilation) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Checker.cs:line 58
    at Microsoft.SingSharp.Compiler.CompileParseTree(Compilation compilation, ErrorNodeList errorNodes) in C:\cci5\SingularityDrop\Microsoft.SingSharp\Compiler.cs:line 238
    at System.Compiler.Compiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames, ErrorNodeList errorNodes, Boolean canUseMemoryMap) in C:\cci5\SingularityDrop\System.Compiler.Framework\Compiler\Compiler.cs:line 165
    at System.Compiler.Compiler.CompileAssemblyFromFile(CompilerParameters options, String fileName, ErrorNodeList errorNodes, Boolean canUseMemoryMap) in C:\cci5\SingularityDrop\System.Compiler.Framework\Compiler\Compiler.cs:line 137
    at main.Main(String[] args) in C:\cci5\SingularityDrop\Microsoft.SingSharp\CommandLineCompiler\Main.cs:line 117

May 8, 2011 at 7:00 PM

The problem is caused by the compiler: The AddPeekMethod() method is called twice, once for each ep.

The first time it is called for Imp which is fine and it's BaseType is "Microsoft.Singularity.Channels.Endpoint".

The second time it is called for Exp whose BaseType is "System.ValueType" for mysterious reasons.

 

Now there are two questions: 

1. Why does it only happen to my custom contracts? I am assuming all default contracts are pre-compiled? How did you compile them if the compiler is flawed?

2. When looking at all members of the Exp ep, I see the following, however, "PeerClosed" is not among them:

       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.#ctor(System.Int32)
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.InState(System.Int32)
RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.CurrentState        RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.RecvBind(System.optional(NonNullType) optional(CustomVector) optional(ExHeap) Char*@,System.optional(NonNullType) optional(CustomVector) optional(ExHeap) Char*@
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.SendAckBind
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.SendNakBind
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.SendReady
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.TransferContentsOwnership(Microsoft.Singularity.Channels.Endpoint@)
         RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.TransferOwnership(Microsoft.Singularity.Channels.Endpoint@,optional(Microsoft.Singularity.Channels.ExHeap) RemoteDirectory.Contracts.RemoteDirectoryContract+Exp*)
         RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.TransferVectorOwnership(Microsoft.Singularity.Channels.Endpoint@,optional(Microsoft.SingSharp.CustomVector) optional(Microsoft.Singularity.Channels.ExHeap) RemoteDirectory.Contracts.RemoteDirectoryContract+Exp*)
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.MarshallAll(System.Byte*,Microsoft.Singularity.Channels.Endpoint@)
         RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.MarshallVector(System.Byte*,Microsoft.Singularity.Channels.Endpoint@,System.Byte*,optional(Microsoft.SingSharp.CustomVector) optional(Microsoft.Singularity.Channels.ExHeap) RemoteDirectory.Contracts.RemoteDirectoryContract+Exp*)
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.MarshallContent(System.Byte*,Microsoft.Singularity.Channels.Endpoint@,System.Byte*)
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.Dispose
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.Expose
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.UnExpose
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.Acquire
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.Release
       RemoteDirectory.Contracts.RemoteDirectoryContract+Exp.TagPod0

 

Still - Any help would be greatly appreciated!

-Domi

 

This is how my contract looks like:

using Microsoft.SingSharp;
using Microsoft.Singularity.Channels;
using Microsoft.Singularity.Directory;
using System;

namespace RemoteDirectory.Contracts
{
    public contract RemoteDirectoryContract : ServiceContract
    {
        // This is the name under which the Remote Directory Service registers itself with the name server
        public const string ModuleName = "/service/remotedir";

		// ######################################################
        // Request messages by the DirectoryService:
		
		// Bind the given ep to the given path.
		// The nodeName is the name of the node that is sending the request.
        in	message Bind(char[]! in ExHeap nodeName, char[]! in ExHeap path, ServiceContract.Exp:Start! exp);
		
		
		// ######################################################
        // Response messages:
		
		// bind succeeded, exp now belongs to the RDC
		out	message AckBind();
		
		// attempt to return unused endpoint if possible
		out	message NakBind(ServiceContract.Exp:Start! exp, ErrorCode code);
		
		// Send upon successful connection
        out message Ready();
		
		// ######################################################
        // State diagram
        override state Start : Ready! -> ReadyState;

        state ReadyState : one
        {
            Bind? -> (AckBind! or NakBind!) -> ReadyState;
        }
    }
}