I have a c# app with .net framework 4.7 working. I read that .net Framework will be replaced with .net Core, .net Standard so I wanted to move it to .net core 3.1
Surprisingly, to get emails from exchange online the example that one can find everywhere
"foreach (EmailMessage email in exchange.FindItems(WellKnownFolderName.Inbox, new ItemView(100))"
does not work, returning VS CS1579 error
"foreach statement cannot operate on variables of type 'type1' because 'type2' does not contain a public definition for 'identifier'"
Of course, exchange.FindItems type is "(awaitable) System.Threading.Tasks.Task<FindItemsResults>"
Looking at dozens of examples, I always find the same examples not using Tasks, so I do not find an example to make this works,
is this new return type "Task" correct because of net core ?
how can I implement this new type ?
Thanks
Olivier
Related
I am using Apache ignite version 2.7.5. and using .net core as server and thin client.
Cache configuration with key as string and value as Model class for example Employee.And this model class having properties including dictionary data type fields.
I am performing get and put record into cache from application which having target platform is .net framework.
In my .net core(v2.2.103) client Load() method returning result but in caller application getting the following exception.
{"No matching type found for object [typeId=596790889,
typeName=System.Collections.Generic.NonRandomizedStringEqualityComparer].
This usually indicates that assembly with specified type is not loaded
on a node. When using Apache.Ignite.exe, make sure to load assemblies
with -assembly parameter. Alternatively, set
IgniteConfiguration.PeerAssemblyLoadingEnabled to true."}
Any one can you give suggestion,how to solve this exception.
I think you have mismatch of .Net versions - one uses NonRandomizedStringEqualityComparer as comparer for its dictionaries, which other one does not have this type.
Please see this related .Net core bug: https://github.com/dotnet/corefx/issues/26033
It is possible that Ignite handles such dictionaries incorrectly on its own, but I'm not sure what are steps to reproduce. Right now the recommendation is to make sure you're using exactly the same verison of .Net runtime everywhere.
I have been searching around for an answer to this the last couple of hours without any success. I´m relatively new to programming so please go easy on me :-)
My problem is that it seems that I can´t use IActionResult in one of my projects in my solution which is targeting .NET Framework 4.6.1 but in the same solution (different project) targeting .NET Standard 2.0 I can use it.
I have tried to install exactly the same Nuget packages and everything looks exactly the same except for what framework that is targeted.
I just want to write Azure Functions using IActionResults like:
public static async Task<IActionResult> MyFuntcion([HttpTrigger(AuthorizationLevel.Function, "get", Route = null")]HttpRequest req, TraceWriter log)
{
//Do some stuff then redirect
}
I'm guessing that my targeted framework is whats causing me to not be able to use IActionResult, but I don't understand why.
Any help would be much appreciated, especially if one might know how to make this work.
Thank you
Short Version
You can't use an IActionResult in a Full Framework MVC or Web API as a result object. You'll have to map it to the appropriate type first. You should probably not use IActionResult in your class libraries, let the core project handle with return types
But ASP.NET Core doesn't require the .NET Core runtime, it can target the Full Framework as well. Perhaps you can use an ASP.NET Core project targeting the Full framework for your main project?
Explanation
ASP.NET Core is the "new" name for ASP.NET 5. It's a new framework that merges the MVC and Web API stacks and was built to run on both the older Full framework and what was then called DNXCore. Both names changed to ASP.NET Core 1.0 and Core .NET 1.0, leading to the confusion we have today.
Before ASP.NET Core, ASP.NET MVC and Web API were two different stacks, they used different controller base classes and returned different results. ASP.NET MVC used the abstract ActionResult class and Web API used the IHttpActionResult interface. Using an interface means it's a lot easier to test and mock the results, among other things. It also means that classes that implement it don't have to handle potentially unneeded properties and base methods.
In ASP.NET Core, the web framework, the entire stack was redesigned and now there's a single stack with a single base interface for results, IActionResult. Core's ActionResult is the default implementation but anyone can create a different implementation. RedirectResult for example doesn't need a Content property so it doesn't have one.
This interface is available to every .NET Standard 2.0 library as long as the appropriate package are added.
That doesn't mean it can be used as the actual return type in ASP.NET MVC 6 or Web API 2 projects though, because neither MVC's ActionResult nor Web API's IHttpActionResult implement it. One would have to write code to map from a concrete IActionResult instance to a concrete MVC ActionResult or Web API IHttpActionResult instance.
If your main project is ASP.NET Core though, you can use the interface whether it runs on the Full or Core framework.
.NET Standard
.NET Standard is a set of API specifications not a specific runtime. Each version specifies a set of classes and APIs that should be provided by a runtime that complies with that Standard version. When one creates a .NET Standard 2.0 library it means the code can use any of the classes and APIs defined in the 2.0 version.
Adding just the interface
IActionResult is not part of .NET Standard 2.0. It's provided by a package Microsoft.AspNetCore.Mvc.Abstractions.
SOLUTION.
I needed to install Microsoft.AspNetCore.Mvc package in order to get it to work.
Sry for my newbie questions and thank you very much for the help.
Edit: As #PanagiotisKanavos writes its enough with the Microsoft.AspNetCoreMvc.Abstractions package for IActionResult. Needed some other stuff beyond that so went for the whole package.
Does it even exist in .net? It seems to exist only in .net core.
Source on Microsoft:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.iactionresult?view=aspnetcore-2.1
See "Applies to" on that page.
during migration of .net framework from 4.6 to 4.6.2 on VS 2015 for one of the web related projects ran into the following problem.
The application settings are split into 2 for testing and production.
The switch used to happen in run time based on value of key value pair in a ini file.
Additional properties were added in run time by passing values from a different process.
The conversion into interface was simple by simple assignment.
For ex:
IInterface sInterface = Properties.Settings.Default;
Unfortunately this doesnt work any more after upgradation to .net 4.6.2.
Ends up with the error : cannot implicitly convert type "Properties.Settings.Default" to IInterface.
Explicit casting doesnt work either.
Tried following:
System.Convert.ChangeType ended up with System.InvalidCastException.
Any way this can be done?
I need to create a covariant interface with a method that takes a delegate with covariant generic parameter. Here's the code sample under question:
interface IExample<out T1>
{
void ExampleMethod(Action<T1> someAction);
}
On Mono/ .NET 4 profile it compiles OK (tested it in Xamarin studio). However, on .NET 2 (which I'm forced to use since I'm using Unity game engine), I get the following error:
error CS1961: The covariant type parameter 'T1' must be invariantly valid on `CovarianceExample.IExample.ExampleMethod(System.Action)'
Why does this error occur in early .Net versions? How can I fix it?
Why does this error occur in early .Net versions?
Because Action wasn't contravariant in .NET 2.0 (or 3.5).
How can I fix it?
Don't use .NET 2.0 :) I thought that modern versions of Unity were based on more recent versions of Mono anyway - perhaps an upgrade is available?
Alternatively, you could declare your own ContravariantAction delegate:
public delegate void ContravariantAction<in T>(T value);
I haven't tried doing so against .NET 2.0, but I believe the appropriate attributes were already present, and at least the MS .NET implementation supported generic variance - it just wasn't exposed in C# or used in the BCL.
I've just downloaded the dynamic object framework Clay and am running into issues regarding castle project versions. Clay uses functionality from v2.0 of "castle" whilst I have a project which has been started referencing v2.5. Needless to say just to make matters more interesting I'm a complete beginner in all things "Castle" and IoC.
The real problem is that upgrading the references within clay solution results in a depreciated method warning. Regardless of whether you supress the method or not, the provided unit tests fail with a "Cannot perform runtime binding on a null reference" exception in the following code in "Intercept" of "InterfaceProxyBehavior":
var invoker = BindInvoker(invocation);
invoker(invocation);
The code that produces the run-time warning is in "CreateInstance" of "DefaultClayActivator":
//var proxyType = _builder.CreateClassProxy(baseType, options);
var proxyType = _builder.CreateClassProxyType(baseType, null, options);
As previously stated I'm still a complete beginner with Castle Windsor and just starting out with IoC so haven't even come across the Proxy stuff yet. Frustratingly I have no idea what the error message is even telling me, or asking for.
Have anyone already ported Clay across to version 2.5 of the castle project, so know the steps needed. Or can any one with experience of this part of castle throw anymore light on the error and what I may need to do to resolve it.
Updated
I'm still not really any the wiser as to the functionality that is failing, but have had chance to revisit the code running it both with v2.0 (works) and v2.5 (breaks) in castle.core. Attached are two images of the debug information when it works and then when it breaks. The test that it fails on is below, I've indicated the call with a comment.
namespace ClaySharp.Tests {
[TestFixture]
public class BinderFallbackTests {
...
[Test]
public void TestInvokePaths() {
var dynamically = ClayActivator.CreateInstance<Alpha>(new IClayBehavior[] {
new InterfaceProxyBehavior(),
new AlphaBehavior()
});
Alpha statically = dynamically;
IAlpha interfacially = dynamically;
Assert.That(dynamically.Hello(), Is.EqualTo("World-"));
Assert.That(statically.Hello(), Is.EqualTo("World-"));
Assert.That(interfacially.Hello(), Is.EqualTo("World-")); // <- Fails on this call
Assert.That(dynamically.Foo(), Is.EqualTo("Bar-"));
Assert.That(interfacially.Foo(), Is.EqualTo("Bar-"));
Assert.Throws<RuntimeBinderException>(() => dynamically.MissingNotHandled());
}
...
}
}
This is the debug information when using v2.5 of castle.core and the exception is thrown:
This is the debug information using v2.0 of castle.core (which works) for the same call / line that causes the problem with v2.5
It seems I fixed this. (all tests passing)
See the workitem on codeplex I created and the changes I pushed to my fork:
http://clay.codeplex.com/SourceControl/network/Forks/remcoros/Clay
I have never used this Clay thing, so all stuff below is based on assumptions.
The error message from BindInvoker is not a Castle error, but I'm guessing it's happening because the invoker is trying to bind to invocation target of the proxy which in DynamicProxy 2.1 used to have a value in some cases, which was wrong, and later versions 2.2 and 2.5 fixed that but it was a breaking change that you're now experiencing.
The other error message is telling you
Use CreateClassProxyType method
instead.
Which is the other method you commented out. What's not obvious here?
Some nice tutorials on Clay dynamic objects:
Malleable C# dynamic objects Part 1 Link
Malleable C# dynamic objects Part 2 Link.