[WORKAROUND] Unimplemented form of generic method parameter: 'T'.

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
Ajcek
Posts: 7
Joined: Thu Mar 09, 2017 7:03 am

[WORKAROUND] Unimplemented form of generic method parameter: 'T'.

Postby Ajcek » Tue Feb 06, 2018 11:54 pm

When I try to run my app there is an error while generating javascript files:

ERROR: C#/XAML for HTML5: JavaScriptGenerator failed: System.Exception: Error occurred while generating javascript for assembly 'Manufaktura.Controls.XamlForHtml5.MusicShadow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. ---> System.Exception: An error occurred while declaring the type 'Manufaktura.Music.Xml.XAttributeHelper' ---> System.Exception: An error occurred while declaring the type 'Manufaktura.Music.Xml.XHelperBase' ---> System.NotImplementedException: Unimplemented form of generic method parameter: 'T'.

I thought that it might be related to nullable generic parameter:
private static T? ParseValue<T>(string value) where T : struct

but it seems that it's not the case.

Can you tell me which form of generic parameter is unsupported here? This is my class:
public abstract class XHelperBase : IXHelper
{
public XHelperExistsResult Exists()
{
return new XHelperExistsResult(ElementExists(), GetObject(), GetValue());
}

public XHelperHasValueResult<string> HasAnyValue()
{
if (!ElementExists()) return new XHelperHasValueResult<string>(null, null, false);
var value = GetValue();
return !string.IsNullOrWhiteSpace(value) ? new XHelperHasValueResult<string>(value, value, true) : new XHelperHasValueResult<string>(null, null, false);
}

public XHelperHasValueResult<T> HasValue<T>(Dictionary<string, T> values)
{
if (ElementExists() && values.ContainsKey(GetValue())) return new XHelperHasValueResult<T>(values[GetValue()], GetValue(), true);
return new XHelperHasValueResult<T>(default(T), GetValue(), false);
}

public XHelperHasValueResult<T> HasValue<T>() where T : struct
{
if (!ElementExists()) return new XHelperHasValueResult<T>(default(T), null, false);
var unparsedValue = GetValue();
var value = ParseValue<T>(unparsedValue);

return value.HasValue ? new XHelperHasValueResult<T>(value.Value, GetValue(), true) : new XHelperHasValueResult<T>(default(T), GetValue(), false);
}

public XHelperHasValueResult<string> HasValue(string s)
{
if (!ElementExists()) return new XHelperHasValueResult<string>(null, null, false);
var value = GetValue();
return !string.IsNullOrWhiteSpace(value) && s == value ? new XHelperHasValueResult<string>(value, GetValue(), true) : new XHelperHasValueResult<string>(null, GetValue(), false);
}

protected abstract bool ElementExists();

protected abstract string GetValue();

protected abstract object GetObject();


private static T? ParseValue<T>(string value) where T : struct
{
if (typeof(T) == typeof(int)) return UsefulMath.TryParseInt(value) as T?;
if (typeof(T) == typeof(double)) return UsefulMath.TryParse(value) as T?;
if (typeof(T) == typeof(float)) return UsefulMath.TryParse(value) as T?;
if (typeof(T) == typeof(DateTime)) return UsefulMath.TryParseDateTime(value) as T?;
throw new NotImplementedException("Type not supported");
}


public XHelperHasValueResult<T> HasValue<T>(Func<Dictionary<string, T>, Dictionary<string, T>> valueFactory)
{
var dict = valueFactory(new Dictionary<string, T>());
return HasValue(dict);
}
}

Thanks in advance.

JS-Support @Userware
Site Admin
Posts: 883
Joined: Tue Apr 08, 2014 3:42 pm

Re: Unimplemented form of generic method parameter: 'T'.

Postby JS-Support @Userware » Fri Feb 09, 2018 3:43 am

Hi,

Thanks for your message.

We are going to look into it and keep you updated asap!

Regards,
JS-Support

JS-Support @Userware
Site Admin
Posts: 883
Joined: Tue Apr 08, 2014 3:42 pm

Re: Unimplemented form of generic method parameter: 'T'.

Postby JS-Support @Userware » Wed Feb 21, 2018 2:28 am

Hi,

We have investigated and isolated the issue.

The following code snippet is apparently not supported by the current version of the JSIL transpiler (when the generic type parameter is passed to a generic method):

Code: Select all

public void MethodThatBlocksJSCompilation<T>()
{
    var v = new Dictionary<string, T>(); //this doesn't work
}


We are going to fix it asap.

In the meantime, there is an easy workaround, which is to instantiate the dictionary using the "ToDictionary" Linq method, as shown below:

Code: Select all

List<KeyValuePair<string, T>> k = new List<KeyValuePair<string,T>>();
Dictionary<string, T> d = k.ToDictionary(x => x.Key, x => x.Value);


Thank you.
Regards,
JS-Support

Ajcek
Posts: 7
Joined: Thu Mar 09, 2017 7:03 am

Re: [WORKAROUND] Unimplemented form of generic method parameter: 'T'.

Postby Ajcek » Mon Mar 05, 2018 12:16 am

It works. Thanks :)


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 1 guest

 

 

cron