Method not found: RestSharp.IRestReuqest RestSharp.RestRequest.AddFile - c#

Use the Docusign API to send a Document for a signature
string accountId = loginApi(username, password, integratorKey);
Which then calls LoginAPI method which breaks at line:
LoginInformation loginInfo = authApi.Login();
Which should allow me to receive the accountId for my integrator key/login credentials
Instead I am getting an error of:
{"Method not found: 'RestSharp.IRestRequest RestSharp.RestRequest.AddFile(System.String, System.Action`1, System.String, System.String)'."}
Just started integrating Docusign into our application so using these versions which are dependencies to attempt to recreate this issue:
Docusign.eSign.dll V2.1.8
RestSharpv106.1.0
RestSharpSignedv105.2.3
Newtonsoft.Json v10.0.3
BouncyCastle v1.8.1
Any Idea?

This is because of RestSharp and RestSharpSigned have the same dll file name and one overwrites the other.
You should use RestSharpSigned only to avoid conflict.
I solved the issue by uninstalling RestSharp and its binding redirect in *.config file:
<dependentAssembly>
<assemblyIdentity name="RestSharp" publicKeyToken="598062e77f915f75" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-106.6.10.0" newVersion="106.6.10.0" />
</dependentAssembly>

Know this is a bit of an old one, but I had the same problem. As Nick suspected, the issue was down to a conflict between RestSharpSigned and RestSharp.
I uninstalled both and the DocuSign library, then re-installed RestSharpSigned, then DocuSign. Our other code that was using the standard RestSharp library seems to be working fine with the signed version.

Related

Issues with TokenClient in IdentityModel

I have a new MVC project using TokenClient from IdentityModel
var tokenClient = new TokenClient(tokenUrl, clientId, CLIENT_SECRET, null, AuthenticationStyle.BasicAuthentication);
I have the nuget package in for IdentityModel and everything compiles fine. However, at runtime I get the following error.
Method not found: 'Void
IdentityModel.Client.TokenClient..ctor(System.String, System.String,
System.String, System.Net.Http.HttpMessageHandler,
IdentityModel.Client.AuthenticationStyle)'.
The .NET version of the MVC project is 4.6.1
What can be causing this issue? I have been searching google and cannot find anything that helps. It must be something simple that i am missing.
EDIT:
initializing it by declaring the parameters explicitly does not work either.
var tokenClient = new TokenClient(tokenUrl, clientId: clientId, clientSecret: CLIENT_SECRET);// CLIENT_SECRET, null, AuthenticationStyle.BasicAuthentication);
However initializing it with the one parameter works fine.
var tokenClient = new TokenClient(tokenUrl);
IdentityModel is a 3rd party library built by the creators of Identity Server. v3.10.1 definitely does have that method overload in it. I have recreated your error and the reason you are getting the error is because IdentityModel v3.10.1 is not compatible with .NET Framework 4.6.1. The creators changed the signature of that overload and made the HttpMessageHandler an optional parameter so your code will compile, but will throw this Method Not Found error at runtime. The IdentityModel project you are referencing has been archived by the guys at Identity Server so I would recommend migrating if you can.
You have a couple of options as I see it:
1) Migrate to .NET Core and leverage IdentityModel v2.
2) Downgrade your project to .NET Framework 4.5.2 (the last compatible version for IdentityModel V1)
3) Do not use this overload (as you've already found the single tokenUrl param works). I would stay away from this approach as you are likely to run into additional compatibility issues.
Basically, if you don't want to migrate to .NET Core, keep this project on 4.5.2. If you can migrate, do that instead. Identity Server is moving toward .NET Core as a whole anyway and you will get more mileage by making that leap now.
I encountered the same problem while working through the MVC Getting Started example for IdentityServer3. If you check the dependencies for IdentityModel v3.10.1 you'll notice that it depends on System.Net.Http (>= 4.3.3). My project had v 4.2, updating to the current version solved the problem.
If you are using ASP.Net MVC application check binding redirect of "System.Net.Http" in web.config
it should be like
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

Could not load file or assembly 'System.Spatial' or one of its dependencies

I get this error message:
Could not load file or assembly 'System.Spatial, Version=5.7.0.0,
Culture=neutral, PublicKeyToken=49ba329had364evz' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
I tried to uninstall/update System.Spatial and WindowsAzure.Storage Nuget packages but still get the error.
It's a dependency of WindowsAzure.Storage package, but funny thing is that I don't get this error when running my ASP.NET Web API project locally, but only on the Azure server.
I don't know where to find the assembly's manifest, is it packages.config?
How to get rid of this error? I already wasted two days :(
Changed the version details in configuration file based on DLL version present in bin folder of project having issue.
In configuration file it was referring to version 5.6.4 but I have changed to version 5.6.3 which resolved the error.
Before Change
<dependentAssembly>
<assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" />
</dependentAssembly>
After change.
<dependentAssembly>
<assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.3.0" newVersion="5.6.3.0" />
</dependentAssembly>
if you are using visual studio, go to nugget package manager and view installed packages, and use update pane to update system.spatial package,
this solved my issue
For some reason I don't know, Visual Studio wasn't uploading newer .dll file to the server.
So I manually uploaded System.Spatial version 5.7.0 on the server.
(although still I don't know how could I change the version in a so called manifest.)
Fit all dependencies to your current azure version by the following two steps:
open Package Manager Console window
enter PM> Install-Package WindowsAzure.Storage -Version [your_version_number]-preview -Pre
this is what solved the problem in my case.

Google.Apis.Calendar.v3.dll ask 1.9.2 version on Google APIs

I setup nuget packages
Install-Package Google.Apis.Core
Install-Package Google.Apis
Install-Package Google.Apis.Auth
As it said there http://google-api-dotnet-client.blogspot.ca/
We have released a 1.9.3 version of NuGet packages only for the Core packages - that’s where the new features are. You should still use 1.9.2 version of the API specific packages (such as Drive) and only update the Core packages
Install-Package Google.Apis.Calendar.v3
When I tried to build it I'm getting error:
Assuming assembly reference 'Google.Apis, Version=1.9.2.27817, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab' matches 'Google.Apis, Version=1.9.3.19379, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab',
you may need to supply runtime policy
I added redirect script in web.config:
<dependentAssembly>
<assemblyIdentity name="Google.Apis" publicKeyToken="4b01fa6e34db77ab"/>
<bindingRedirect oldVersion="1.9.2.27817" newVersion="1.9.3.19379" />
</dependentAssembly>
but still getting the same error. I check it with spy and it appears Calendar dll wants old API.
Any idea how to fix it? (Thanks)

Asp.net MVC 5.2.2 on Azure

After upgrading mvc nuget package from version 5.1.0 to 5.2.2 our machine (webrole) on Azure refuses to start the web role. It was in recycling state. I found an error in event log :
The description for Event ID 1007 from source Windows Azure Runtime 2.4.0.0 cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
820
WaIISHost
Role entrypoint could not be created: System.TypeLoadException: Unable to load the role entry point due to the following exceptions:
-- System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CreateRoleEntryPoint(RoleType roleTypeEnum)
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum)
the message resource is present but the message is not found in the string/message table
I tried to search over the internet, but with no useful answer.
I wasn't able to solve it otherwise than downgrade. Luckily package version 5.1.1 is working.
Update 1:
After some trial and error I found, that asp.net mvc packages are OK up to version 5.1.3
It looks like packages from 5.2.0 upwards are not supported.
Update 2:
We have decided to split our web and web.api, so I didn't have this problem anymore. My best guess is, that there was indeed nuget, which was referencing older asp.net mvc package.
I had a similar problem. We inherited a project and updated the ASPNET MVC version to 5.2.2.0. We couldn't deploy to Azure. The only error we could find was the one you mentioned here.
We corrected every web.config file so older versions were redirected to a newer version but we still had the same problem.
Then we wrote a small test method that iterated over every Assembly and we saw that one NuGet package was still using Asp.net MVC 4.0. This package was an old version and hadn't been updated for a while. I downloaded the source, updated the Mvc Nuget and manually inserted the dll.
We deployed again and everything went flawless.
Here is are test method.
private void TestAssemblies()
{
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly item in allAssemblies)
{
PrintAssembly(item);
}
}
private void PrintAssembly(Assembly assembly)
{
foreach (var item in assembly.GetReferencedAssemblies())
{
if (item.FullName.Contains("System.Web.Mvc"))
{
Debug.WriteLine(item);
Debug.WriteLine("Parent: " + assembly.FullName);
Debug.WriteLine("------------------------------------------------------------");
}
}
}
MVC 5.2.2 works perfectly fine in Azure. Your role recycling is most likely an indication that either you have not properly deployed your application properly or that you have a hidden dependency on an older version of MVC that a binding redirect may not handle.
I would strongly suggest that you read all of the entries in Kevin Williamson's great series on trouble shooting Azure deployments.
There are a ton of things that can go wrong, so rather than try to create a generic one-size-fits-all list, review the blog posts and then post a comment if you are unable to figure out what specifically is happening.
Given the error that you did post, assuming you have the proper binding redirect that #Yishai Galatzer mentions, you might have a DLL in your deployment that has a hidden dependency on MVC 5.1.0.0. I would suggest using a program like Jetbrains DotPeek to inspect all of your DLLs in your package and look at their references. I suspect you'll find one that itself depends on 5.1.0.0.
I have also face similar problem with mvc5.2.2 azure deployment..
the ultimate solution is we need to add this web.config
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>``
From the looks of it, looks like you are missing a binding redirect to MVC 5.2.2 in your web.config. This should just work.
We are working on verifying this scenario. But let us know if this works for you. In your web.config please take a look at the following section, and makes sure it matches with this xml below:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>
I had exactly similar problem couple of days back. Please refer to this post.
You need to add <dependentAssembly> section to WaIISHost.exe.config which is generally # 'E:\base\x64' on your VM.
Many times I've found the problem to be in the ~\Views\Web.config file. It keeps a reference to the old MVC version. Just manually update it.
If that doesn't work do a full text search of your solution in Sublime Text or some other tool outside of VS and search for the version string causing you issues.
I had the same issue, where it worked fine on my Dev machine, but when deployed I was getting the assembly error. To resolve this, I had to change the "oldVersion" from version 0.0.0.0 to version 1.0.0.0
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>
To
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>

Error unit testing webapi controller

I'm using AspNet Web Api Client 5.0 and i am trying to unit test a web api controller.
var encservice = new EncryptionService();
var acctservice = FakeServices.GetAccountService();
var controller = new AccountController(acctservice, encservice);
controller.Request = new HttpRequestMessage();
when the code
controller.Request.SetConfiguration(new HttpConfiguration());
is executed i hit an exception
Message: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source: System.Net.Http.Formatting
Stacktrace: at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor()
at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters()
at System.Net.Http.Formatting.MediaTypeFormatterCollection..ctor()
at System.Web.Http.HttpConfiguration.DefaultFormatters()
at System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes)
at System.Web.Http.HttpConfiguration..ctor()
at EMR.Test.Controller.AccountControllerTest.Should_Get() in c:\PremiumProjectsCollection\emr\src\EMRAzure\EMRAzure\EMR.Test\Controller\AccountControllerTest.cs:line 34
the version of newsoft.json that i am using is 6.0
I also have a assembly redirection in my confguration file
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
The test runner that im using is MStest, VS2012
You'll need to add an assembly redirect:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json"
publicKeyToken="30ad4fe6b2a6aeed"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
(assuming that the assembly version of Newtonsoft.Json is exactly 6.0.0.0.)
(note comment below is referring to a Web Api Client project having this issue)
I had the same problem with the version of Newtonsoft.Json so I deleted the older version references and used Package Manager Console to install the latest version of Newtonsoft.Json on my Web Api Client Library and Test Project.
Install-Package Newtonsoft.Json -Version 6.0.8
(note u might need to find out which is the latest version)
The problem remained so I realized there is a crash between System.Net.Http.Formatting and my latest version of Json.
To solve this, delete the System.Net.Http and System.Net.Http.Formatting references and install the WebApi Client Library via Nuget instead, as below:
Install-Package Microsoft.AspNet.WebApi.Client
This solved it for me.
I did not try this myself, but there seems to be a bug in 2012 mstest. Where you have to use .testsettings file for app.config to be picked up.
See the following link: http://social.msdn.microsoft.com/Forums/vstudio/en-US/234926d1-42c0-4ebb-af39-1626e72f6c39/why-does-assemblybinding-work-only-if-testsettings-file-is-used-vs2012rc?forum=vsunittest
I faced the same problem days ago and it took me hours to find a solution for this one.
I was testing a unit that had the latest version of NewtonSoft installed while my test project had an older version.
What i did to get around this was consolidate the versions of this library in my solution via the "Manage Nuget packages for solution" option by right clicking the solution in solution explorer.
This will update all NewtonSoft libraries present in your projects under the current solution and remove all old versions from the package control VisualStudio creates in a folder named packages in your solution directory.

Categories

Resources