0

my problem is the error mentioned in the title.

I am trying to use an objects as CAO type. I've creasted proper assembly, serwer and the client.

It occurs when I try to use the line:

JamesBondCar[] cars = { new JamesBondCar("one", 100, true, true), 
                                      new JamesBondCar("Two", 100, true, true), 
                                      new JamesBondCar("Three", 100, true, true) };
CarProvider cp=new CarProvider(cars);

This works when I use default constructor. What might be the problem?

Edit: This is the code for CarProvider:

 public class CarProvider : MarshalByRefObject 
    {
        private ArrayList theJBCars = new ArrayList(); 
        public CarProvider()
        {
            Console.WriteLine("Utworzono CarProvider.");
            theJBCars.Add(new JamesBondCar("QMobile", 140, true, true));
            theJBCars.Add(new JamesBondCar("FLyer", 140, true, false));
            theJBCars.Add(new JamesBondCar("Swimmer", 140, false, true));
            theJBCars.Add(new JamesBondCar("BasicJBC", 140, false, false));
        }
        public CarProvider(JamesBondCar[] theCars)
        { 
            Console.WriteLine("Utworzono JamesBondCar za pomocą niestandardowego konstruktora.");
            theJBCars.AddRange(theCars);
        }
        public ArrayList GetAllAutos() 
        { return theJBCars; }
        public JamesBondCar GetJBCByIndex(int i)
        { return (JamesBondCar)theJBCars[i]; }
    }

App.config for the serwer:

<configuration>
  <system.runtime.remoting>
    <application>
      <service>
        <activated
            type="CarGeneralAsm.CarProvider,CarGeneralAsm"/>
      </service>
        <channels>
          <channel ref="http" port="32469"/>
        </channels>
    </application>
  </system.runtime.remoting>
</configuration>

And the App.config for the client:

<configuration>
  <system.runtime.remoting>
    <application name="TestowanieTypówCAO">
      <client
        url="http://localhost:32469">
        <activated
          type="CarGeneralAsm.CarProvider,CarGeneralAsm"/>
      </client>
      <channels>
        <channel ref="http"/>
      </channels>
    </application>
  </system.runtime.remoting>
</configuration>

Edit2:

Error msg and stack trace:

System.Security.SecurityException was unhandled
  _HResult=-2146233078
  _message=Żądanie nie powiodło się.
  HResult=-2146233078
  IsTransient=false
  Message=Żądanie nie powiodło się.
  RemoteStackTrace=
Server stack trace: 
   w System.Array.InternalCreate(Void* elementType, Int32 rank, Int32* pLengths, Int32* pLowerBounds)
   w System.Array.CreateInstance(Type elementType, Int32 length)
   w System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseArray(ParseRecord pr)
   w System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseObject(ParseRecord pr)
   w System.Runtime.Serialization.Formatters.Soap.ObjectReader.Parse(ParseRecord pr)
   w System.Runtime.Serialization.Formatters.Soap.SoapHandler.StartChildren()
   w System.Runtime.Serialization.Formatters.Soap.SoapParser.ParseXml()
   w System.Runtime.Serialization.Formatters.Soap.SoapParser.Run()
   w System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler handler, ISerParser serParser)
   w System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream serializationStream, HeaderHandler handler)
   w System.Runtime.Remoting.Channels.CoreChannel.DeserializeSoapRequestMessage(Stream inputStream, Header[] h, Boolean bStrictBinding, TypeFilterLevel securityLevel)
   w System.Runtime.Remoting.Channels.SoapServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)

Exception rethrown at [0]: 

  Source=mscorlib
  GrantedSet=""
  PermissionState=<PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>

  RefusedSet=""
  Url=""
  StackTrace:
    Server stack trace: 
       w System.Array.InternalCreate(Void* elementType, Int32 rank, Int32* pLengths, Int32* pLowerBounds)
       w System.Array.CreateInstance(Type elementType, Int32 length)
       w System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseArray(ParseRecord pr)
       w System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseObject(ParseRecord pr)
       w System.Runtime.Serialization.Formatters.Soap.ObjectReader.Parse(ParseRecord pr)
       w System.Runtime.Serialization.Formatters.Soap.SoapHandler.StartChildren()
       w System.Runtime.Serialization.Formatters.Soap.SoapParser.ParseXml()
       w System.Runtime.Serialization.Formatters.Soap.SoapParser.Run()
       w System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler handler, ISerParser serParser)
       w System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream serializationStream, HeaderHandler handler)
       w System.Runtime.Remoting.Channels.CoreChannel.DeserializeSoapRequestMessage(Stream inputStream, Header[] h, Boolean bStrictBinding, TypeFilterLevel securityLevel)
       w System.Runtime.Remoting.Channels.SoapServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
    Exception rethrown at [0]: 
       w System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       w System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       w System.Runtime.Remoting.Activation.IActivator.Activate(IConstructionCallMessage msg)
       w System.Runtime.Remoting.Activation.LocalActivator.DoRemoteActivation(IConstructionCallMessage ctorMsg)
       w System.Runtime.Remoting.Activation.LocalActivator.Activate(IConstructionCallMessage ctorMsg)
       w System.Runtime.Remoting.Activation.AppDomainLevelActivator.Activate(IConstructionCallMessage ctorMsg)
       w System.Runtime.Remoting.Messaging.ClientContextTerminatorSink.SyncProcessMessage(IMessage reqMsg)
       w System.Runtime.Remoting.Activation.ActivationServices.Activate(RemotingProxy remProxy, IConstructionCallMessage ctorMsg)
       w System.Runtime.Remoting.Proxies.RemotingProxy.InternalActivate(IConstructionCallMessage ctorMsg)
       w System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(IMessage reqMsg)
       w System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       w CarGeneralAsm.CarProvider..ctor(JamesBondCar[] theCars)
       w CarProviderClient.CarClient.Main(String[] args) w c:\Users\Paweł\Documents\Visual Studio 2013\Projects\CarProviderClient\CarProviderClient\CarClient.cs:wiersz 31
       w System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       w System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       w Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       w System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       w System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       w System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
Paweł Poręba
  • 1,084
  • 1
  • 14
  • 37
  • 2
    Can you post the error message and stack trace in your question? – Greg Burghardt Aug 06 '15 at 14:10
  • How can I get stack trace? I'm newbie and I don't really know. – Paweł Poręba Aug 06 '15 at 14:25
  • When are you getting this exception? When debugging in Visual Studio? when this is running on the server? If you are running this locally on your machine, you can check the Windows Event Log for this error, and it should give you the full stack trace as well. When debugging through Visual Studio it should `break` at the line causing the exception. At that point you can open a small pop up window to get detailed information about the exception. – Greg Burghardt Aug 06 '15 at 14:29
  • It's after I use CarProvider cp=.... . Then I get the message saying: You can't connect to the remote serwer. – Paweł Poręba Aug 06 '15 at 14:37
  • Ok. Can you post the code for `CarProvider` and the necessary configuration in App.config or Web.config? We can't help you unless you provide this information. – Greg Burghardt Aug 06 '15 at 14:41
  • Ok, I updated this. Thanks for helping me:) – Paweł Poręba Aug 06 '15 at 14:47
  • I wonder if `localhost` is the problem. Maybe try replacing that with `12.7.0.0.1` or using your windows machine name? – Greg Burghardt Aug 06 '15 at 15:18
  • Another possibility? [System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.](http://blogs.msdn.com/b/narahari/archive/2010/06/03/system-security-securityexception-request-for-the-permission-of-type-system-web-aspnethostingpermission-system-version-2-0-0-0-culture-neutral-publickeytoken-b77a5c561934e089-failed.aspx) – Greg Burghardt Aug 06 '15 at 15:20
  • Similar question? [Throws Security Exception on server , runs on localhost](http://stackoverflow.com/questions/29326261/throws-security-exception-on-server-runs-on-localhost) – Greg Burghardt Aug 06 '15 at 15:20
  • I think it's not the point, I am not using System.Web and my program works when I use default constructor. Anyway, I tried to write 12.7.0.0.1, but it doesn't help (only generates another System.WebNet Exception). Changing to windows machine name won't help too :( Those other topics I have already seen and it didn't solve my problem. – Paweł Poręba Aug 06 '15 at 15:36
  • You'll need to post the full exception message and stack trace, including any inner exceptions. – Greg Burghardt Aug 06 '15 at 15:47
  • I just updated my post with that. – Paweł Poręba Aug 06 '15 at 15:54
  • I'm sorry, but could you translate the exception messages to English in the stacktrace? I'm afraid I don't speak your language. – Greg Burghardt Aug 06 '15 at 16:30
  • I tried running "Żądanie nie powiodło się" through Google Translate and it recognized it as Polish, meaning "Request Failed," is this correct? – Greg Burghardt Aug 06 '15 at 16:33
  • I searched Google for __MarshalByRefObject soap securityexception request failed__ and it came up with some interesting results. Specifically: [PermissionSet - Request Failed error](http://stackoverflow.com/questions/21888291/permissionset-request-failed-error). – Greg Burghardt Aug 06 '15 at 16:35
  • Another possibly related post on a different site: http://bytes.com/topic/c-sharp/answers/541405-remoting-beginner-whats-missing-code – Greg Burghardt Aug 06 '15 at 16:36
  • Well, thanks for trying to help me. It still gives nothing, the error is still the same. What's interesting, when I add constructor like CarProvider(int a, string s){Console.WriteLine("blabla"):} and I try to use it in the client app, I don't get the mentioned error, but I get another one: "'System.Runtime.Remoting.RemotingException" saying : "Can't find '.ctor' method" altough it is defined.. – Paweł Poręba Aug 06 '15 at 16:55

1 Answers1

1

I guess I finally figured it out. @Greg Burghardt's suggested posts made me read more about it in MSDN and I found that it is connected with changes made in .NET 4.0 regarding security.

And "typeFilterLevel=full" was the solution, but there were other mistakes in my server/client *.config files. Below, I present their proper versions:

Client

<configuration>
  <system.runtime.remoting>
    <application name="TestowanieTypówCAO">
      <channels>
        <channel ref="http">
          <clientProviders>
            <formatter ref="soap"/>
          </clientProviders>
          <serverProviders>
            <formatter ref="soap"  typeFilterLevel="Full"/>
          </serverProviders>
        </channel>
      </channels>
      <client url="http://localhost:32469">
        <activated type="CarGeneralAsm.CarProvider,CarGeneralAsm"/>
      </client>    
    </application>
  </system.runtime.remoting>
</configuration>

Serwer

<configuration>
  <system.runtime.remoting>
    <application>
      <channels>
          <channel ref="http" port="32469">
             <serverProviders>
                <formatter ref="soap" typeFilterLevel="Full"/>
             </serverProviders>
             <clientProviders>
               <formatter ref="soap"/>
             </clientProviders>
            </channel>
        </channels>
      <service>
        <activated
            type="CarGeneralAsm.CarProvider,CarGeneralAsm"/>
      </service>    
    </application>
  </system.runtime.remoting>
</configuration>

I know .NET Remoting is now not often used, cause of WCF, but I just wanted to know how all of it works, before stepping into WCF.

Cheers!

Paweł Poręba
  • 1,084
  • 1
  • 14
  • 37