Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cast to valid interface fails after Activator.CreateInstance #12676

@steveisok

Description

@steveisok

Steps to Reproduce

  1. Clone https://github.com/steveisok/mono.git and checkout refsrc-webforms-switch-activator-bug
  2. Build
  3. Run make -w -C mcs/class/System.Web.Extensions run-standalone-test

Current Behavior

Test fails with the following:

2) DataPager_NumericPagerField_Bug615315, Test 02
               Test: StandAloneTests.DataPager_NumericPagerField_Bug615315.Test_02
        Description: Page numbers must be sequential (PostBack Mode)
         Failed URL: Test_PostBackMode.aspx
    Callback method: Void StandAloneTests.DataPager_NumericPagerField_Bug615315.Test_02.TestPostBackMode_Aspx_Start(System.String, StandAloneRunnerSupport.TestRunItem)
    Failure details:
      Test failed with exception of type 'System.InvalidCastException':
      System.InvalidCastException: Specified cast is not valid.
      
      
      Server stack trace: 
        at System.Web.Hosting.HostingEnvironment.CreateWellKnownObjectInstance (System.String assemblyQualifiedName, System.Boolean failIfExists) [0x00037] in /Users/steveman/dev/dotnet/mono-rebase-build/mcs/class/referencesource/System.Web/Hosting/HostingEnvironment.cs:759 
        at (wrapper managed-to-native) System.Runtime.Remoting.RemotingServices.InternalExecute(System.Reflection.MethodBase,object,object[],object[]&)
        at System.Runtime.Remoting.RemotingServices.InternalExecuteMessage (System.MarshalByRefObject target, System.Runtime.Remoting.Messaging.IMethodCallMessage reqMsg) [0x000ad] in /Users/steveman/dev/dotnet/mono-rebase-build/mcs/class/corlib/System.Runtime.Remoting/RemotingServices.cs:150 
      
      Exception rethrown at [0]: 
        at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke (System.Runtime.Remoting.Proxies.RealProxy rp, System.Runtime.Remoting.Messaging.IMessage msg, System.Exception& exc, System.Object[]& out_args) [0x001aa] in /Users/steveman/dev/dotnet/mono-rebase-build/mcs/class/corlib/System.Runtime.Remoting.Proxies/RealProxy.cs:326 
        at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_remoting_wrapper(intptr,intptr)
        at (wrapper remoting-invoke) System.Web.Hosting.HostingEnvironment.CreateWellKnownObjectInstance(string,bool)
        at (wrapper xdomain-invoke) System.Web.Hosting.HostingEnvironment.CreateWellKnownObjectInstance(string,bool)
        at (wrapper remoting-invoke-with-check) System.Web.Hosting.HostingEnvironment.CreateWellKnownObjectInstance(string,bool)
        at System.Web.Hosting.ApplicationManager.CreateObjectInternal (System.String appId, System.Type type, System.Web.Hosting.IApplicationHost appHost, System.Boolean failIfExists, System.Web.Hosting.HostingEnvironmentParameters hostingParameters) [0x00040] in /Users/steveman/dev/dotnet/mono-rebase-build/mcs/class/referencesource/System.Web/Hosting/ApplicationManager.cs:293 
        at System.Web.Hosting.ApplicationManager.CreateObject (System.String appId, System.Type type, System.String virtualPath, System.String physicalPath, System.Boolean failIfExists, System.Boolean throwOnError) [0x0002f] in /Users/steveman/dev/dotnet/mono-rebase-build/mcs/class/referencesource/System.Web/Hosting/ApplicationManager.cs:256 
        at System.Web.Hosting.ApplicationManager.CreateObject (System.String appId, System.Type type, System.String virtualPath, System.String physicalPath, System.Boolean failIfExists) [0x00000] in /Users/steveman/dev/dotnet/mono-rebase-build/mcs/class/referencesource/System.Web/Hosting/ApplicationManager.cs:234 
        at (wrapper remoting-invoke-with-check) System.Web.Hosting.ApplicationManager.CreateObject(string,System.Type,string,string,bool)
        at StandAloneRunnerSupport.StandaloneTest.RunInternal (System.Web.Hosting.ApplicationManager appMan, System.Boolean verbose) [0x00233] in /Users/steveman/dev/dotnet/mono-rebase-build/mcs/class/System.Web/Test/standalone-runner-support/StandaloneTest.cs:187 
        at StandAloneRunnerSupport.StandaloneTest.Run (System.Web.Hosting.ApplicationManager appMan, System.Boolean verbose) [0x00007] in /Users/steveman/dev/dotnet/mono-rebase-build/mcs/class/System.Web/Test/standalone-runner-support/StandaloneTest.cs:108

Here's the specific line where the cast fails
(mcs/class/referencesource/System.Web/Hosting/HostingEnvironment.cs)

obj = (IRegisteredObject)Activator.CreateInstance(type);

The type that is trying to be loaded is TestRunner, which implements IRegisterObject and is found at
(mcs/class/System.Web/Test/standalone-runner-support/TestRunner.cs)

public sealed class TestRunner : MarshalByRefObject, IRegisteredObject, ITestRunner

Note that these types of tests that use HostingEnvironment succeed using nunit-lite.

Expected Behavior

The type at the very least should be loaded and the test should pass.

On which platforms did you notice this

[x] macOS
[x] Linux
[] Windows

Version Used:

Mono JIT compiler version 5.23.0 (refsrc-webforms-switch/b9edcc82c68 Sat Jan 26 08:10:32 EST 2019)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	Interpreter:   yes
	LLVM:          supported, not enabled.
	Suspend:       hybrid
	GC:            sgen (concurrent by default)

Stacktrace

Please paste the stack trace here if available.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions