无法加载System.Threading.Tasks组装,使用谷歌日历API [英] Cannot load System.Threading.Tasks assembly, using Google Calendar API

查看:1257
本文介绍了无法加载System.Threading.Tasks组装,使用谷歌日历API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决了!



巨大的感谢山姆·利奇



下面是我工作的app.config样本文件:

 <结构> 

<&运行GT;
< assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
< dependentAssembly>
< assemblyIdentity名称=System.Threading.Tasks公钥=B03F5F7F11D50A3A文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-2.5.19.0NEWVERSION =2.5.19.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Net.Http公钥=B03F5F7F11D50A3A文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-2.1.10.0NEWVERSION =2.1.10.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Net.Http.Primitives公钥=B03F5F7F11D50A3A文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-2.1.10.0NEWVERSION =2.1.10.0/>
< / dependentAssembly>
< / assemblyBinding>
< /运行>
< /结构>



我还发现的来源






编辑:原题是线下。



我使用的是.NET 4.0框架,并从我的研究,我知道System.Threading.Tasks组件不再需要(因为它包含自动)。
我错了这件事?



如果我是正确的,现在我敢肯定,在引发错误,因为使用System.Threading.Tasks版本由谷歌-API DOTNET客户端的开发者和Visual Studio 2010的不同所使用的。



我注意到,检查我的应用程序的行为的时候,当我。删除一些行



和这些行就出来了:

 兆千卡=新CalendarService(新BaseClientService.Initializer()
{
的Authenticator =权威性,
=应用程序名称APP_NAME,
});



所以,我的新问题是:



<块引用>

有没有办法强制的参考组件的一个特定版本在VS2010中使用?




谢谢你对我的帮助,我相信这将帮助许多人,因为谷歌日历的API-V3被严重记载。



亲切的问候,
布鲁诺。






我的问题是我不能访问谷歌API通过VisualStudio的服务。



我得到这个错误:

  L'例外System.IO.FileLoadException n'a PAS ETEgérée
消息=不可能去充电器乐fichier OU L'集'System.Threading.Tasks,版本= 1.5.11.0,文化=中性公钥= b03f5f7f11d50a3a瓯UNE德SESdépendances。香格里拉定义trouvée杜manifeste DE L'装配NE PAS对应点菜提及此战争DE L'组装。 (例外德HRESULT:0x80131040)
来源= MVMA
=文件名System.Threading.Tasks,版本= 1.5.11.0,文化=中性公钥= b03f5f7f11d50a3a
FusionLog ====信息ð政变德联络préalable===
JRN:utilisateur = MODAL\brbo
JRN:显示名称= System.Threading.Tasks,版本= 1.5.11.0,文化=中性公钥= b03f5f7f11d50a3a
(全指定)
JRN:应用平台=文件:/// C:/用户/ brbo /文档/ Visual Studio 2010中/项目/ MVMA-V5.0(甘特)/ MVMA /斌/调试/
JRN:PrivatePath初始= NULL
大会appelant:Google.Apis,版本= 1.4.0.28227,文化=中立,公钥=空。
===
JRN:CETTE联络démarre丹斯乐德contexte德chargement默认。
JRN:利用杜fichier去配置DE L'应用程序:C:\Users\brbo\Documents\Visual工作室2010\Projects\MVMA-V5.0(甘特)\MVMA\\ \\bin\Debug\MVMA.vshost.exe.Config
JRN:利用杜fichier去配置套餐:
JRN:利用杜fichier去配置DE L'ordinateuràpartir德C:\\ \\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config。
JRN:参考stratégie后:System.Threading.Tasks,版本= 1.5.11.0,文化=中性公钥= b03f5f7f11d50a3a
JRN:暂定德téléchargement德拉新式的URL文件:/// C: /用户/ brbo /文档/ Visual Studio 2010中/项目/ MVMA-V5.0(甘特)/MVMA/bin/Debug/System.Threading.Tasks.DLL。
AVT:LA comparaison杜NOM DE L'装配一个entraînéL'incompatibilité:版本PRINCIPALE
错误:不可能去terminer L'安装DE L'总成(HR = 0x80131040)。检测terminée。

堆栈跟踪:
A MVMA.Classes.GoogleCalendar.BuildCalendarService()
A System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象状态,布尔ignoreSyncCtx)
A System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回调,对象状态)
A System.Threading.ThreadHelper.ThreadStart()

和这里是我的类(相同的命名空间),它尝试使用JSON网络令牌连接到谷歌日历API第3版:

 公共类Google日历
{

// CHAINES D'ACCES辅助服务,谷歌
公共常量字符串APP_NAME =隐藏;
公共常量字符串CLIENT_ID =隐藏;
公共常量字符串CLIENT_SECRET =隐藏;
公共常量字符串SERVICE_CLIENT_ID =隐藏;
公共常量字符串EMAIL_ADDRESS =隐藏;
公共常量字符串PUB_KEY =隐藏;
公共常量字符串PRIV_KEY_PATH = @C:\MVMA\HIDDEN-privatekey.p12
公共常量字符串PRIV_KEY_SECRET =notasecret;
公共常量字符串SIMPLE_API_KEY =隐藏;
公共常量字符串SCOPE_CALENDAR =https://www.googleapis.com/auth/calendar;
公共常量字符串SCOPE_CALENDAR_READONLY =https://www.googleapis.com/auth/calendar.readonly;

私有静态CalendarService兆千卡;

公共静态无效ImportFromMVMA()
{
螺纹逸=新主题(新的ThreadStart(BuildCalendarService));
yat.Start();
}

//柏美日récupérer乐服务calendrier
//定义接收时,结果是可用的回调方法。
私有静态无效BuildCalendarService(){

无功证书=新X509Certificate2(PRIV_KEY_PATH,PRIV_KEY_SECRET,X509KeyStorageFlags.Exportable);
VAR privateKey = certificate.Export(X509ContentType.Cert);

VAR提供商=新AssertionFlowClient(GoogleAuthenticationServer.Description,证书)
{
ServiceAccountId = EMAIL_ADDRESS,
SCOPE = SCOPE_CALENDAR
};

变种AUTH =新OAuth2Authenticator< AssertionFlowClient>(供应商,AssertionFlowClient.GetState);

兆千卡=新CalendarService(新BaseClientService.Initializer()
{
的Authenticator =权威性,
=应用程序名称APP_NAME,
});
}
}

公共枚举JwtHashAlgorithm
{
RS256,
HS384,
HS512
}

公共类JsonWebToken
{


私有静态字典< JwtHashAlgorithm,Func键<字节[],字节[],字节[]>> HashAlgorithms;

静态JsonWebToken()
{
HashAlgorithms =新词典< JwtHashAlgorithm,Func键<字节[],字节[],字节[]>>
{
{JwtHashAlgorithm.RS256,(键,值)=> {使用(VAR SHA =新HMACSHA256(键)){返回sha.ComputeHash(值); }}},
{JwtHashAlgorithm.HS384,(键,值)=> {使用(VAR SHA =新HMACSHA384(键)){返回sha.ComputeHash(值); }}},
{JwtHashAlgorithm.HS512,(键,值)=> {使用(VAR SHA =新HMACSHA512(键)){返回sha.ComputeHash(值); }}}
};
}

公共静态字符串编码(对象的有效载荷,串键,JwtHashAlgorithm算法)
{
返回编码(有效载荷,Encoding.UTF8.GetBytes(键),算法);
}

公共静态字符串编码(对象的有效载荷,字节[] keyBytes,JwtHashAlgorithm算法)
{
变种段=新的List<串>();
变种头= {新ALG = algorithm.ToString(),典型值=智威汤逊};

字节[] = headerBytes Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(头,Formatting.None));
字节[] = payloadBytes Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(有效载荷,Formatting.None));

segments.Add(Base64UrlEncode(headerBytes));
segments.Add(Base64UrlEncode(payloadBytes));

VAR stringToSign =的string.join(,segments.ToArray()。);

VAR bytesToSign = Encoding.UTF8.GetBytes(stringToSign);

字节[] =签名HashAlgorithms [算法(keyBytes,bytesToSign);
segments.Add(Base64UrlEncode(签字));

返回的string.join(,segments.ToArray()。);
}

公共静态字符串解码(字符串标记,字符串键)
{
返回解码(令牌,钥匙,真正的);
}

公共静态字符串解码(字符串标记,串键,布尔确认)
{
VAR部分= token.Split('。');
VAR头=零件[0];
无功负载=部分[1];
字节[] =密码Base64UrlDecode(部件[2]);

VAR headerJson = Encoding.UTF8.GetString(Base64UrlDecode(头));
VAR headerData = JObject.Parse(headerJson);
变种payloadJson = Encoding.UTF8.GetString(Base64UrlDecode(有效负载));
VAR payloadData = JObject.Parse(payloadJson);

如果(验证)
{
VAR bytesToSign = Encoding.UTF8.GetBytes(string.Concat(头,有效载荷)。);
VAR keyBytes = Encoding.UTF8.GetBytes(键);
变种算法=(字符串)headerData [ALG];

VAR签名= HashAlgorithms [GetHashAlgorithm(算法)](keyBytes,bytesToSign);
VAR decodedCrypto = Convert.ToBase64String(加密);
VAR decodedSignature = Convert.ToBase64String(签字);

如果(decodedCrypto!= decodedSignature)
{
抛出新ApplicationException的(的String.Format(无效的签名。预计{0}有{1},decodedCrypto,decodedSignature) );
}
}

返回payloadData.ToString();
}

私有静态JwtHashAlgorithm GetHashAlgorithm(字符串变换算法)
{
开关(算法)
{
案RS256:返回JwtHashAlgorithm .RS256;
案HS384:返回JwtHashAlgorithm.HS384;
案HS512:返回JwtHashAlgorithm.HS512;
默认:抛出新的InvalidOperationException异常(不支持算法。);
}
}

//从智威汤逊规范
私人静态字符串Base64UrlEncode(字节[]输入)
{
无功输出=转换.ToBase64String(输入);
输出= output.Split('=')[0]; //删除任何尾随'=的
输出= output.Replace('+',' - '); //编码
输出的字符62 = output.Replace('/','_'); //编码
返回输出的字符第63;
}

//从智威汤逊规范
私人静态的byte [] Base64UrlDecode(字符串输入)
{
无功输出=输入;
输出= output.Replace(' - ','+'); //编码
输出的字符62 = output.Replace('_','/'); //编码
开关(output.Length%4)//垫的第63届炭尾随'=的
{
的情况下0:打破; //在这种情况下,
2的情况下没有垫字符:输出+ ===;打破; //两个垫字符
案例3:输出+ ==;打破; //一垫字符
默认:抛出新的System.Exception(非法base64url串!);
}
无功转换= Convert.FromBase64String(输出); //标准Base64编码解码器
返回转换;
}
}

公共类GoogleJsonWebToken
{

公共静态字符串GetAccessToken(字符串email,字符串certificateFilePath,串serviceScope)
{
变种utc0 =新日期时间(1970年,1,1,0,0,0,0,DateTimeKind.Utc);
VAR issueTime = DateTime.Now;

VAR IAT =(int)的issueTime.Subtract(utc0).TotalSeconds;
VAR EXP =(int)的issueTime.AddMinutes(55).Subtract(utc0).TotalSeconds; //过期时间长达1个小时,但让玩家在安全方面

无功负载=新的
{
ISS =电子邮件,
=范围serviceScope,
AUD =https://accounts.google.com/o/oauth2/token,
EXP = EXP,
IAT IAT =
};

无功证书=新X509Certificate2(certificateFilePath,GoogleCalendar.PRIV_KEY_SECRET);

VAR privateKey = certificate.Export(X509ContentType.Cert);

返回JsonWebToken.Encode(有效载荷,privateKey,JwtHashAlgorithm.RS256);
}
}



我不明白为什么我上有一个FileLoadException在System.Threading.Tasks装配。
我尝试了新的功能添加到已经使用任务没有问题的应用程序。该应用程序使用它在不同的线程运行的TabPage对象。


解决方案

删除以的System.Threading所有引用。任务,然后在一个加无论从任何.NET版本使用的是(.NET 4.0)。



谷歌日历API可能会使用不同版本的.NET



手动重定向大会



您可以指定你的app.config



<$ p $要使用的程序集的版本p> < dependentAssembly>
< assemblyIdentity名称=someAssembly
公钥=32ab4ba45e0a69a1
文化=EN-US/>

< bindingRedirect oldVersion =7.0.0.0NEWVERSION =8.0.0.0/>
< / dependentAssembly>


SOLVED !

Huge thank to Sam Leach

Here is a sample of my working app.config file:

<configuration>
       ...
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Net.Http" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

I have also found that source


EDIT: The original question is below the line.

I am using the .NET 4.0 Framework and from my research I know that the System.Threading.Tasks assembly is no longer needed (because it's included automatically). Am I wrong about this?

If I am right, I am now pretty sure that the error is raised because the version of System.Threading.Tasks used by the developers of the google-api-dotnet-client and the one used by Visual Studio 2010 are different.

I noticed that when inspecting the behavior of my app when I remove some lines.

And these lines came out:

gcal = new CalendarService(new BaseClientService.Initializer()
{
    Authenticator = auth,
    ApplicationName = APP_NAME,
});

So, my new question is:

Is there a way to force the usage of one specific version of a reference assembly in VS2010 ?

Thank you for helping me, I am sure it will help lots of people because the google-calendar-api-v3 is badly documented.

Kind regards, Bruno.


My problem is that I can't get access to the Google API as a service through VisualStudio.

I get this error:

L'exception System.IO.FileLoadException n'a pas été gérée
  Message=Impossible de charger le fichier ou l'assembly 'System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ou une de ses dépendances. La définition trouvée du manifeste de l'assembly ne correspond pas à la référence de l'assembly. (Exception de HRESULT : 0x80131040)
  Source=MVMA
  FileName=System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  FusionLog==== Informations d'état de liaison préalable ===
JRN : utilisateur = MODAL\brbo
JRN : DisplayName = System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
JRN : Appbase = file:///C:/Users/brbo/Documents/Visual Studio 2010/Projects/MVMA-V5.0 (With Gantt)/MVMA/bin/Debug/
JRN : PrivatePath initial = NULL
Assembly appelant : Google.Apis, Version=1.4.0.28227, Culture=neutral, PublicKeyToken=null.
===
JRN : cette liaison démarre dans le contexte de chargement de default.
JRN : utilisation du fichier de configuration de l'application : C:\Users\brbo\Documents\Visual Studio 2010\Projects\MVMA-V5.0 (With Gantt)\MVMA\bin\Debug\MVMA.vshost.exe.Config
JRN : utilisation du fichier de configuration d'hôte : 
JRN : utilisation du fichier de configuration de l'ordinateur à partir de C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
JRN : référence post-stratégie : System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
JRN : tentative de téléchargement de la nouvelle URL file:///C:/Users/brbo/Documents/Visual Studio 2010/Projects/MVMA-V5.0 (With Gantt)/MVMA/bin/Debug/System.Threading.Tasks.DLL.
AVT : la comparaison du nom de l'assembly a entraîné l'incompatibilité : Version principale
ERR : impossible de terminer l'installation de l'assembly (hr = 0x80131040). Détection terminée.

  StackTrace:
   à MVMA.Classes.GoogleCalendar.BuildCalendarService()
   à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   à System.Threading.ThreadHelper.ThreadStart()

And here is my classes (same namespace) which tries to connect to the Google Calendar API v3 using Json Web Tokens:

public class GoogleCalendar
{

    // Chaînes d'accès aux services Google
    public const string APP_NAME = "HIDDEN";
    public const string CLIENT_ID = "HIDDEN";
    public const string CLIENT_SECRET = "HIDDEN";
    public const string SERVICE_CLIENT_ID = "HIDDEN";
    public const string EMAIL_ADDRESS = "HIDDEN";
    public const string PUB_KEY = "HIDDEN";
    public const string PRIV_KEY_PATH = @"C:\MVMA\HIDDEN-privatekey.p12";
    public const string PRIV_KEY_SECRET = "notasecret";
    public const string SIMPLE_API_KEY = "HIDDEN";
    public const string SCOPE_CALENDAR = "https://www.googleapis.com/auth/calendar";
    public const string SCOPE_CALENDAR_READONLY = "https://www.googleapis.com/auth/calendar.readonly";

    private static CalendarService gcal;

    public static void ImportFromMVMA()
    {
        Thread yat = new Thread(new ThreadStart(BuildCalendarService));
        yat.Start();
    }

    // Permet de récupérer le service calendrier
    // Define the method that receives a callback when the results are available.
    private static void BuildCalendarService() {

        var certificate = new X509Certificate2(PRIV_KEY_PATH, PRIV_KEY_SECRET, X509KeyStorageFlags.Exportable);
        var privateKey = certificate.Export(X509ContentType.Cert);

        var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
        {
            ServiceAccountId = EMAIL_ADDRESS,
            Scope = SCOPE_CALENDAR
        };

        var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);

        gcal = new CalendarService(new BaseClientService.Initializer()
                        {
                            Authenticator = auth,
                            ApplicationName = APP_NAME,
                        });
    }
}

public enum JwtHashAlgorithm
{
    RS256,
    HS384,
    HS512
}

public class JsonWebToken
{


    private static Dictionary<JwtHashAlgorithm, Func<byte[], byte[], byte[]>> HashAlgorithms;

    static JsonWebToken()
    {
        HashAlgorithms = new Dictionary<JwtHashAlgorithm, Func<byte[], byte[], byte[]>>
        {
            { JwtHashAlgorithm.RS256, (key, value) => { using (var sha = new HMACSHA256(key)) { return sha.ComputeHash(value); } } },
            { JwtHashAlgorithm.HS384, (key, value) => { using (var sha = new HMACSHA384(key)) { return sha.ComputeHash(value); } } },
            { JwtHashAlgorithm.HS512, (key, value) => { using (var sha = new HMACSHA512(key)) { return sha.ComputeHash(value); } } }
        };
    }

    public static string Encode(object payload, string key, JwtHashAlgorithm algorithm)
    {
        return Encode(payload, Encoding.UTF8.GetBytes(key), algorithm);
    }

    public static string Encode(object payload, byte[] keyBytes, JwtHashAlgorithm algorithm)
    {
        var segments = new List<string>();
        var header = new { alg = algorithm.ToString(), typ = "JWT" };

        byte[] headerBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(header, Formatting.None));
        byte[] payloadBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload, Formatting.None));

        segments.Add(Base64UrlEncode(headerBytes));
        segments.Add(Base64UrlEncode(payloadBytes));

        var stringToSign = string.Join(".", segments.ToArray());

        var bytesToSign = Encoding.UTF8.GetBytes(stringToSign);

        byte[] signature = HashAlgorithms[algorithm](keyBytes, bytesToSign);
        segments.Add(Base64UrlEncode(signature));

        return string.Join(".", segments.ToArray());
    }

    public static string Decode(string token, string key)
    {
        return Decode(token, key, true);
    }

    public static string Decode(string token, string key, bool verify)
    {
        var parts = token.Split('.');
        var header = parts[0];
        var payload = parts[1];
        byte[] crypto = Base64UrlDecode(parts[2]);

        var headerJson = Encoding.UTF8.GetString(Base64UrlDecode(header));
        var headerData = JObject.Parse(headerJson);
        var payloadJson = Encoding.UTF8.GetString(Base64UrlDecode(payload));
        var payloadData = JObject.Parse(payloadJson);

        if (verify)
        {
            var bytesToSign = Encoding.UTF8.GetBytes(string.Concat(header, ".", payload));
            var keyBytes = Encoding.UTF8.GetBytes(key);
            var algorithm = (string)headerData["alg"];

            var signature = HashAlgorithms[GetHashAlgorithm(algorithm)](keyBytes, bytesToSign);
            var decodedCrypto = Convert.ToBase64String(crypto);
            var decodedSignature = Convert.ToBase64String(signature);

            if (decodedCrypto != decodedSignature)
            {
                throw new ApplicationException(string.Format("Invalid signature. Expected {0} got {1}", decodedCrypto, decodedSignature));
            }
        }

        return payloadData.ToString();
    }

    private static JwtHashAlgorithm GetHashAlgorithm(string algorithm)
    {
        switch (algorithm)
        {
            case "RS256": return JwtHashAlgorithm.RS256;
            case "HS384": return JwtHashAlgorithm.HS384;
            case "HS512": return JwtHashAlgorithm.HS512;
            default: throw new InvalidOperationException("Algorithm not supported.");
        }
    }

    // from JWT spec
    private static string Base64UrlEncode(byte[] input)
    {
        var output = Convert.ToBase64String(input);
        output = output.Split('=')[0]; // Remove any trailing '='s
        output = output.Replace('+', '-'); // 62nd char of encoding
        output = output.Replace('/', '_'); // 63rd char of encoding
        return output;
    }

    // from JWT spec
    private static byte[] Base64UrlDecode(string input)
    {
        var output = input;
        output = output.Replace('-', '+'); // 62nd char of encoding
        output = output.Replace('_', '/'); // 63rd char of encoding
        switch (output.Length % 4) // Pad with trailing '='s
        {
            case 0: break; // No pad chars in this case
            case 2: output += "=="; break; // Two pad chars
            case 3: output += "="; break; // One pad char
            default: throw new System.Exception("Illegal base64url string!");
        }
        var converted = Convert.FromBase64String(output); // Standard base64 decoder
        return converted;
    }
}

public class GoogleJsonWebToken
{

    public static string GetAccessToken(string email, string certificateFilePath, string serviceScope)
    {
        var utc0 = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
        var issueTime = DateTime.Now;

        var iat = (int)issueTime.Subtract(utc0).TotalSeconds;
        var exp = (int)issueTime.AddMinutes(55).Subtract(utc0).TotalSeconds; // Expiration time is up to 1 hour, but lets play on safe side

        var payload = new
        {
            iss = email,
            scope = serviceScope,
            aud = "https://accounts.google.com/o/oauth2/token",
            exp = exp,
            iat = iat
        };

        var certificate = new X509Certificate2(certificateFilePath, GoogleCalendar.PRIV_KEY_SECRET);

        var privateKey = certificate.Export(X509ContentType.Cert);

        return JsonWebToken.Encode(payload, privateKey, JwtHashAlgorithm.RS256);
    }
}

I don't understand why I have a FileLoadException on the System.Threading.Tasks assembly. I try to add a new functionality to an application which already use Tasks without problems. This app uses TabPage objects which run in different threads.

解决方案

Remove all references to System.Threading.Tasks and then add in the one from whatever .NET version you are using (.NET 4.0).

The Google Calendar API might be using a different version of .NET

Manually Redirecting Assembly

You can specify which version of the assembly to use in your app.config

  <dependentAssembly>
    <assemblyIdentity name="someAssembly"
      publicKeyToken="32ab4ba45e0a69a1"
      culture="en-us" />

    <bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" />
  </dependentAssembly>

这篇关于无法加载System.Threading.Tasks组装,使用谷歌日历API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆