RavenDb 4.0 - RavenJValue from Raven.Abstractions - c#

I am migrating to RavenDB 4.0, as a part of Migration I came across setting the meta-data session.Advanced.GetMetadataFor(data)["Raven-Expiration-Date"] = new RavenJValue(data.Promotion.DateToUtc);
The only place I found that type is Raven.Abstractions reference, but that on is in version 3.5 Is that still valid for 4.0?
Also, I am not sure if that Raven.Abstractions package comes together with RavenDB 4.0 package, and it looks like those things depend on each other.
Anybody has any kind of experience with that? I understand RavenDB 4.0 is not final yet, and there might be some of the issues.
Thank you.

That value has changed. For 4.0, you need to use:
session.Advanced.GetMetadataFor(data)["#expires"] = data.Promotion.DateToUtc.ToString("O");

Related

What does <ImportWindowsDesktopTargets> do in a try-convert generated *.csproj?

I have used the try-convert tool to convert my projects from .NET Framework to .NET 5.0
When inspecting the converted *.csproj files for projects that are targeting .net50-windows I noticed the element:
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
I am curious to understand what it does?
Is this essential or another example of something that try-convert puts in the *.csproj but is not really required to be present in the *.csproj any more?
Thanks.
The same happened when I used upgrade-assistant to do the upgrade and I also
wondered what the ImportWindowsDesktopTargets means and whether I needed it. I could find no official documentation for it, only this discussion. According to the question in the discussion, adding an ImportWindowsDesktopTargets property is one way to allow multitargetting using the TargetFramworks property, like this:
<TargetFrameworks>net472;net5.0-windows</TargetFrameworks>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
As my project does not need to target multiple frameworks, just net5.0-windows, and as I have other projects, both Windows Forms and WPF, that target only net5.0-windows and work fine without ImportWindowsDesktopTargets, I removed ImportWindowsDesktopTargets from the converted project with no problems.
According to the proposed answer in the linked discussion, even if you do want to target multiple frameworks, there may be a better way to do it.
This is for pre-Net5.0 behavior to force importing WindowsDesktop Targets.
If you are using Net 5.0 or a newer version, Microsoft.NET.Sdk.WindowsDesktop will always be imported by the SDK, so you may remove it.

Dynamic Code Compilation in .Net Core 2.1

Has anyone managed to find a workaround/way to dynamically compile a file, or files, or text, into a .dll in .Net Core (2.1)?
var csProvider = CodeDomProvider.CreateProvider("CSharp");
CompilerResults compilerResults = csProvider.CompileAssemblyFromFile(options, files);
results in a PlatformNotSupportedException and it seems CodeDom is only of very limited use in .Net Core. See similar complaint and compare view of System.CodeDom.Compiler in .Net Core 2.1 vs .Net Framework 4.7.2.
We need to be able to write and dynamically compile custom code on-site. I have a way of dynamically loading any resultant .dll, but I just need to be able to get that .dll in the first place.
The only workaround I can see at the moment is to create a .Net Framework api/service to do this. Is the only other solution here to give up on .Net Core and go to .Net Framework?
Note: I wanted to do this dynamically within the code base. So the solution for "Is it possible to compile a single C# code file with .net core Roslyn compiler?" is not relevant as it states: "To invoke Roslyn compiler directly it is necessary to use command line driver" which would have set me on completely the wrong path. However "How to compile a C# file with Roslyn programmatically?" would provide the solution if I'd known that that is what I was looking to do.
The link provided by #Sami Kahmonem to Joel Martinez' solution in .Net Core 1 was what I used to solve this problem.
There are two options for you.
Use the Roslyn Scripting API (Microsoft.CodeAnalysis.CSharp.Scripting). This is pretty easy and surprisingly fast. Also you do not write any binaries to the file system.
Use the full compiler to create a DLL and load it. I would not recommend doing this if possible.
For detailed explanations you should look at this question: Compiling and Running code at runtime in .Net Core 1.0 (you do not need to create a NuGet.config or anything like this)

Install Microsoft.AspNet.Identity.EntityFramework.3.0.0-rc1-final into Class Library

I'm trying to create a class library for the new Microsoft Identity model but am being beaten back by an odd error.
If I create a regular C# Class Library (not a PCL) and attempt to install Microsoft.AspNet.Identity.EntityFramework.3.0.0-rc1-final via Nuget it goes so far, chokes, rolls back and then displays the following error:
Failed to add reference to 'System.Runtime'. Please make sure that it
is in the Global Assembly Cache.
I know that this is a pre-release version of the library but this cannot be such a radical idea that I'm trying to achieve here.
Any pointers greatly appreciated.
It seems to be a known issue and confirmed by Microsoft. It leads to this NuGet issue.
A workaround, according to the comments, is to install Microsoft.AspNetCore.Identity.EntityFrameworkCore, which is the RC2 equivalent. From what I can find this hasn't been officially released yet, and you might need to build from source.

ASP.NET 5 Dependency Resolution

I'm trying to tinker arround with ASP.NET5 and all the new Magic we get.
I created a small Application, which receives a MAC-Address and sends a WakeOnLan-Package. For the abstraction of the WoL, I tried to use the SharpPCap-Library: http://www.codeproject.com/Articles/12458/SharpPcap-A-Packet-Capture-Framework-for-NET
I can add the References and even set the Object, but it seems only be avaliable on 4.5. Simply put, do need Asemblies be compatible to DNX 4.5.1 AND DNX Core 5.0?
I tried to add the Automapper, which works, but this one is shown on both Reference-Folders DNX 4.5.1 and 5.0. Does this mean, this Assembly is kindahow working on both Versions? If yes so, how is this possible, if other Assemblies don't seem to be compatible?
My 3. question raises from the Project-References: I added the Model-Project to my WebGui one, but Intellisense keeps marking the Model-Objects red and telling me, he can't resolve it. Funnily enough, building and Runtime work perfectly fine. Is this an issue of the Compiler atm?
If you have any resources on the general topic, I would be glad as well. I found some threads about this theme, like Jon Skeets problem: How can I diagnose missing dependencies (or other loader failures) in dnx? or the diagnosing: http://davidfowl.com/diagnosing-dependency-issues-with-asp-net-5/ but I guess, my problem is on a more basic level.
Thanks in advance.
You don't need DNX Core 5.0 - that's all the .NET Core stuff which SharpPCap probably isn't compatible with. If you can, just get rid of that framework like this in your project.json file:
"frameworks": {
"dnx451": {
}
},
It's probably the same thing for your Model-Project. getting rid of dnxcore50 should help. Basically by doing that you are saying your project needs full .NET, so it might not be as easy to run it on Linux etc...
The red line issue might be a re-sharper problem if you're running that?
see: Dnx 4.5.1/Dnx Core 5.0 Ambiguous reference

ANTLR C# Can't find 'IAstRuleReturnScope'

I have downloaded the csharp grammar project from here http://antlrcsharp.codeplex.com/releases/view/47523, and it runs fine.
But when I add 'output=AST' to the grammar, I get a TON of errors:
I am admittedly new to ANTLR, so I am not sure how to proceed at this point. I would have assumed this type would have existed in the antlr csharp runtime dll, but obviously not. Has anyone come across this problem before?
I ran into this migrating from a v3.2 script generating from the Java tool to using v3.4 with the dotNet build tools.
I was able to figure out (thx to the documentation that comes with the .net VS integration) that the problem with not getting the right return type was because a class is only generated if you have a return type on the rule. Adding a dummy integer return type to my rules that had no return value cleared that up.
There is a discussion of the rule returns in the C# generator and target in the documentation from the C# target page at antlr, follow the link at the top of the page and check out section 4.1.1 "Return values"
About a year ago I did a project with Antlr and ran into an issue where I got tons of errors. As odd as it sounds but by using an older runtime I got it to work. I think I used a dll that had been compiled for the 2.0 .Net Framework.
I do not remember exactly what the error was or what had actually caused it. All I remember is that it solved the issue. I have no idea if this will help in your situation but it's worth a shot if you are stuck.
You are not the first person to have this problem. The patch at https://github.com/antlr/antlr/pull/1 addresses it by providing the missing file. Include it in your source and recompile.

Categories