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

Cannot create an instance of......because Type.ContainsGenericParameters is true #134

Closed
vawwyakr opened this issue Dec 13, 2018 · 3 comments
Labels

Comments

@vawwyakr
Copy link

I am trying to use the Roslyn compiler but if I use any anonymous objects (eg: "var t = new { test = ""test"" }") I get the below error. Is there a work around for this? This script compiles with Mono but I have other issues with Mono and would prefer not to have to switch compilers based on script all over the place.

Error:
Cannot create an instance of <>f__AnonymousType0#1`1[j__TPar] because Type.ContainsGenericParameters is true.

StackTrace:
at System.RuntimeType.CreateInstanceCheckThis()
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at CSScriptLibraryExtensionMethods.CreateInstance(Assembly assembly, String typeName, Object[] args)
at CSScriptLibrary.AsmBrowser.createInstance(Assembly asm, String typeName, Object[] args)
at CSScriptLibrary.AsmBrowser.CreateInstance(String typeName, Object[] args)
at CSScriptLibraryExtensionMethods.CreateObject(Assembly obj, String typeName, Object[] args)
at CSScriptLibrary.RoslynEvaluator.LoadCode(String scriptText, Object[] args)

@oleg-shilo
Copy link
Owner

This is a compiler (e.g. Roslyn) specific issue that is unfortunately impossible to address by scripting infrastructure (CS-Script).

This is not that surprising considering that quite a few normal syntax concepts are illegal in Roslyn scripting implementation. IE "error CS7021: Cannot declare namespace in script code"

It also looks like it is something that is under consideration by the Roslyn team: [Proposal] Allow explicit declaration of anonymous types (in local collections) #3304

@vawwyakr
Copy link
Author

Wow ok darn I was hoping there might be some parameter being passed into the compiler that caused this. So Roslyn can't do anonymous types, interesting. Thank you!

@oleg-shilo
Copy link
Owner

oleg-shilo commented Dec 15, 2018

So Roslyn can't do anonymous types, interesting.

I know. Hard to believe, right!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants