Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)
Solution 1
According to its MSDN page, the overload you're using is only supported on .NET 4.6.
Either configure the host to run .NET 4.6 or change the target framework of the project to 4.5 and recompile.
In 4.5 there's a params object[]
overload which will then be chosen, without having to alter your code.
Solution 2
This doesn't make sense. We've had a line of code like this in our application since 2009
String.Format(CultureInfo.CurrentCulture, "You must specify a new password of {0} or more characters.", _membershipService.MinPasswordLength);
Recently we upped the project to .NET 4.6 and now, for me at least, this line breaks with the same error. So obviously the new overload is breaking something, and the method is not new.
Solution 3
If you can neither upgrade host to 4.6 nor downgrade project to 4.5 there is a workaround : pass an "object[]" as args instead of an "object". So you will force usage of the "params object[]" overload. Example :
return string.Format(formatProvider, "{0:" + format + "}", new object[] { value });
Solution 4
In case this helps anyone. We encountered this issue recently after upgrading our development environment to VS2015 (Our target environment is .Net 4)
Our C++/clr projects had not been setup correctly to use the /clr switch i.e. they were set to no common language support, even though we were using the clr. This didn’t cause an issue until we upgraded to VS2015.
I’m not completely clear on why this works. I’m guessing c++/clr project must bind to a specific version of the CLR runtime at compile time. I’d be interested if someone could explain this more clearly.
Solution 5
We are using custom build server. Even if project TargetFrameworkVersion is v4.5.1, when .net 4.6.1 installed to build server and single argument passed as format argument, the compiler prefers to use this overload
public static string Format(IFormatProvider provider, string format, object arg0)
instead of
public static string Format(IFormatProvider provider, string format, params object[] args)
Only solution is creating and passing array argument
Example:
string.Format(CultureInfo.CurrentCulture, "Hello {0}", new[] { name });
Related videos on Youtube
Dale Alleshouse
Updated on November 22, 2020Comments
-
Dale Alleshouse over 3 years
I have a Web API 2 project with help pages that runs fine locally but throws this error when I push it to Azure:
Method not found: 'System.String System.String.Format (System.IFormatProvider, System.String, System.Object)
I temporarily turned custom errors off so full stack trace can be seen here
The error is originating from this line of code:
string selectExpression = String.Format(CultureInfo.InvariantCulture, MethodExpression, GetMemberName(reflectedActionDescriptor.MethodInfo));
See Line 96 here
The full source code is available on GitHub
I'm not even sure where to go with this one.
-
Alex almost 9 yearsPlease post the code snippet containing the offending line, instead of a link to a github repo.
-
Sql Surfer almost 9 yearsI have seen similar behaviors where the code had a right to left casting ambiguity. When going from .NET 3 to .NET 4 . The solution ended up being something like this ((string)(MyFunction).ToString())
-
Dale Alleshouse almost 9 years@Alex - I added more detail. Sorry I didn't add it in initially, I didn't think it would be important because the missing method is from the dot net framework.
-
CodesInChaos almost 9 yearsTry
String.Format(CultureInfo.InvariantCulture, MethodExpression, new object[]{GetMemberName(reflectedActionDescriptor.MethodInfo)});
I expect the underlying cause to be related to incorrect targeting. Either you're targeting the wrong version or the wrong variant of the framework. -
CodeCaster almost 9 yearsThat overload was added in .NET 4.5. What framework is your Azure platform running?
-
Dale Alleshouse almost 9 years@CodesInChaos - Changing that line of code produces a slightly different error - Method not found: 'System.String System.String.Format(System.IFormatProvider, System.String, System.Object, System.Object)'.
-
CodesInChaos almost 9 years@DaleAlleshouse Is that new error in a different line? You could apply the same work around there. But like CodeCaster remarked, you should either upgrade the server or target a lower version in your project. The error results from overloads your compiler sees but which are missing on the server.
-
Dale Alleshouse almost 9 years@CodesInChaos - It's the same line. My project is targeting 4.6 and Azure is set to 4.5. This shouldn't be a problem, right?
-
Alex almost 9 years@DaleAlleshouse you may want to ensure you are running on the platform version you expect by checking the version in
Environment.Version
(or like this: msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx#net_d). The most logical explanation for what you are observing is that you are not running a CLR version 4.5 or higher. -
CodeCaster almost 9 yearsOh, on that MSDN page I linked to it says ".NET Framework 4.6 and 4.5" at the top, but "Supported in: 4.6" at the bottom. Test it on a machine running 4.6.
-
Dale Alleshouse almost 9 years@CodeCaster - That was it. I guess they don't have 4.6 on Azure yet. I changed the target framework on my project to 4.5 and it works. I guess that's what I get for using RC bits...
-
Dale Alleshouse almost 9 yearsStupid question, how can I mark this question as answered?
-
Philip Atz over 8 yearsSo, is the overload only supported in 4.6 or is it also supported in 4.5? My project targets .NET 4.5.2, but I am getting this error from a machine that is supposed to have .NET 4.5.2 installed. Isn't is supposed to be recognised as a
params object[]
?
-