Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Core - HttpWebRequest #245

Closed
jirisykora83 opened this issue Aug 16, 2016 · 5 comments
Closed

.NET Core - HttpWebRequest #245

jirisykora83 opened this issue Aug 16, 2016 · 5 comments

Comments

@jirisykora83
Copy link

In .NET Core not working this code. But same code working on full .NET.

HttpWebRequest webRequestMock = Substitute.For<HttpWebRequest>();

Error message:
Parent does not have a default constructor. The default constructor must be explicitly defined.

StackTrace:

at System.Reflection.Emit.TypeBuilder.DefineDefaultConstructorNoLock(MethodAttributes attributes)
at System.Reflection.Emit.TypeBuilder.DefineDefaultConstructor(MethodAttributes attributes)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(TypeBuilder type)
at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope)
at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
at NSubstitute.Proxies.CastleDynamicProxy.CastleDynamicProxyFactory.GenerateProxy(ICallRouter callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[] constructorArguments)
at NSubstitute.Core.SubstituteFactory.Create(Type[] typesToProxy, Object[] constructorArguments, SubstituteConfig config)
at NSubstitute.Substitute.For[T](Object[] constructorArguments)
...
@alexandrnikitin
Copy link
Member

I'm sorry I didn't dig deep but it turns out that the HttpWebRequest class was changed in .NET Core version. var ctrs = typeof(HttpWebRequest).GetConstructors(); gives you an empty array while it returns a constructor in .NET version.

@jirisykora83
Copy link
Author

@alexandrnikitin I look on currently TypeExtensions source code via decompiler and it's look currently .NET Core doesn't support GetConstructors();

public static ConstructorInfo[] GetConstructors(this Type type) { return (ConstructorInfo[]) null; }

@alexandrnikitin
Copy link
Member

@jirisykora83 I wouldn't be surprised if they shipped that not implemented version. But hopefully they didn't. https://github.com/dotnet/corefx/blob/release/1.0.0/src/System.Reflection.TypeExtensions/src/System/Reflection/TypeExtensions.CoreCLR.cs

@jirisykora83
Copy link
Author

I again try look on typeof(HttpWebRequest) and here what a i get.

image

I think it's have constructors (non-public) but it's look currently GetConstructors(); not support non-public.

@dtchepak
Copy link
Member

dtchepak commented Oct 7, 2017

Could not reproduce this with NSub 3.0 and .NET Core 2.0. Please re-open is this is still an issue.

@dtchepak dtchepak closed this as completed Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants