Ignoring properties in RavenDB 3.5 (.NET Core) - asp.net-core

Is there any way to ignore a property in a RavenDB entity class for RavenDB 3.5?
I'm working on upgrading a project to .NET core and this project relies on RavenDB.
Before when saving an object to RavenDB I could just add the attribute JsonIgnore from the Raven.Imports.Newtonsoft.Json namespace in the Raven.Abstraction library to the property I wanted to be ignored but this library doesn't seem to exist for 3.5.
Any ideas on how to solve this?

In the same way, the client is embedding the attribute, and it is available.

Related

What Microsoft.AstNetCore.SpaServices.Extension version has UseHsts method or alternative method that is compatible with .Net Framework 4.61?

I have a .Net Core 3.1 web application. Since I have to communicate to a legacy service using .Net Remoting, I decided to change the TargetFramework to 4.61. This has caused error with (IApplicationBuilder)app.UseHSTS(). So, I updated my referenced version of Microsoft.AspNetCore.SpaServices.Extension to 2.2.0. However, UseHSTS is not available with it. Is there an alternative solution?

Add Class Library reference to ASP.NET Core project

I am using VS Pro Update 3
I have been following the guide here: https://www.hanselman.com/blog/HowToReferenceAnExistingNETFrameworkProjectInAnASPNETCore10WebApp.aspx
I have 3 existing .NET 4.5.1 Class Libraries, written in VB.NET but I don't think that should matter as it's all on CLR.
My ASP.NET Core project is C#, targeting .NET 4.5.1.
Here is the Framework section of my project.json:
"frameworks": {
"net451": {
"dependencies": {
"WebApp.Api.Services": {
"target": "project"
}
}
}
},
If I add all my VB.NET class libraries using Add Existing Project to my solution and try to add them as project reference, I get the following error:
Project XXX type is unsupported by current project and cannot be added
as a reference
I also tried adding a C# class Library (WebApp.Api.Services), add VB.NET references to that, then add the C# Class Library as a reference to the ASP Core project
Doing this shows the references in Solution Explorer okay, it seems as though I can use types from the C# Class library but I can't use the VB.NET library's types in my code.
I also created a NuGet package, but no luck
I have read that you can create a 'wrapper' project somehow, or Visual Studio can do this automatically.
Has anyone ever tried adding VB.Net projects to ASP Core solution?
A project built for .NET Core cannot use class libraries built for .NET Framework. They are not directly compatible with each other. In fact I'm confused when you say:
My ASP.NET Core project is C#, targeting .NET 4.5.1.
If it's targeting .NET 4.5.1, then it's not actually a .NET Core project.
You should port your class libraries to .NET Standard; that way they can be used by a wide range of compatible frameworks. It is also possible to have a class library target multiple frameworks.
I managed to solve my issue.
The guide here is correct, I had another different issue that I didn't realize.
I found a System.BadImageFormatException error which lead me to the following question Start an asp.net core project as x86 under visual studio 2015
I uninstalled the x94 version of .NET Core and installed the x86 one.
I still could not add references to the VB.NET libraries to the ASP Core project, so my C# services 'Bridge' library was vital.
In my 'Bridge' library I have Models that I can return from my ASP Controllers:
Public BridgeModelA : VB.NETLibrary.ActualModelA
{
…
}
Then extensions
Public static VB.NETLibrary.ActualModelA ToModel(this BridgeModelA)
{
…
}
Although the base members of these models cannot be accessed in the controllers, due to ASP proj not referencing the VB projs, they are returned by the controller with JSON result containing all base members.
This is actually great as it fits in with the design of thin controllers.

Assembly.GetExecutingAssembly() available in .NET Core?

Need to embed a json file as a source for testing in my .NET Core application. The author of this post http://codeopinion.com/asp-net-core-embedded-resource/ provided sample code that included the use of var assembly = Assembly.GetExecutingAssembly();However when I try this I get the error: Cannot resolve symbol ‘GetExecutingAssembly’ and ‘Assembly’ does not contain a definition for ‘GetExecuringAssembly’
If you are targeting .NET Standard 1.5 or above, you may call any of the following:
System.Reflection.Assembly.GetExecutingAssembly();
System.Reflection.Assembly.GetEntryAssembly();
System.Reflection.Assembly.GetCallingAssembly();
If targeting earlier versions of .NET Standard then the typeof(SomeClass).GetTypeInfo().Assembly method is the only way.
There is no "static" Assembly class in .NET Standard prior to version 1.5. Instead you have to do something like:
typeof(<AClassHere>).GetTypeInfo().Assembly
Where <AClassHere> should be replaced by the name of a class/type in the assembly you wish to load.
Nope, it's not available in .NET Core 1.0/1.1.
However, if I remember correctly it will be back in .NET Core 2.0 and the netstandard2.0 which is to be released later this year, which will have a much bigger API surface and increased compatibility with libraries written against .NET >= 4.5 making it easier to port these to .NETStandard 2.0/2.1.
But many of the APIs implementations will be platform dependent. Means, you will be able to call SomeAPI.GetSomething() everywhere, but if run on .NET Core it may throw a PlatformNotSupportedException.
But most APIs about assembly scanning and discovering should be back in .NET Core/Standard 2.0. Stuff around AppDomain will still be missing as there are no AppDomains in .NET Core and processes should be used for isolation.

ASP.NET Web API conflict after installing VS 2012 Ultimate

I installed asp.net mvc-4 beta a while ago to host our api. It worked fine until I just installed vs2012 ultimate on my machine. The project is neither compiling in vs2010 nor in vs2012. What can I do to resolve this conflict. Furthermore, I bin deployed asp.net web api assemblies on my server. What I have to do to run the latest build (once the previous problem is solved) on server?
Edit:
The compilation errors when I open in vs2012 are
'System.Net.Http.HttpRequestMessage' does not contain a definition for 'GetUserPrincipal' and no extension method 'GetUserPrincipal'...
'System.Web.Http.Hosting.HttpPropertyKeys' does not contain a definition for 'UserPrincipalKey'
In vs 2010 on the other hand, it refuses to accept types like DelegatingHandler and others. Some errors are as follows.
The type or namespace name 'DelegatingHandler' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'HttpResponseMessage' could not be found (are you missing a using directive or an assembly reference?)
I have installed the latest build of asp.net mvc 4 as well and the version its showing me is 4.0.20713.0. Previously, I added web-api beta using nuget. I have removed them all and installed latest builds of web-api from nuget. I don't know what could be the problem. One thing, I don't understand: why do I need to install web-api assemblies seprately when they are supposedly part of mvc framework?
thanks
Add using System.ServiceModel.Channels; to your file. The Extension methods for HttpRequestMessage exist in this namespace according to THIS.
add
using System.Net.Http;
You probably have the reference already, so just add the using for the extension method.
Otherwise add the Assembly of the same name.

log4net and .net Framework 4.0

I was having issues in log4net when I updated my solutions to .net 4.0 , and then I downloaded the source of it and built log4net and targeted it to .net 4.0 and used it in my projects.
Initially when I referred log4net that is targeted to run time 2.0 it complied and run the application but log did not work.
Now when I run my project with log4net targeted to .net 4.0 I get the error "The type initializer for 'Log4NetTest.TestLog' threw an exception."
Any Idea how to solve this?
Edit: this is the inner exception:
InnerException: System.TypeLoadException Message=Inheritance security rules violated while overriding member:
'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'.
Security accessibility of the overriding method must match the security accessibility of the method being overriden.
Source=log4net
TypeName=log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
StackTrace:
at log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory loggerFactory)
at log4net.Repository.Hierarchy.Hierarchy..ctor() in C:\src\Repository\Hierarchy\Hierarchy.cs:line 150
In the log4net source code, add a [SecurityCritical] attribute to the
Util.ReadOnlyPropertiesDictionary.GetObjectData method and build.
Just compiled the source for target framework 4.0 (not client). Source code of version 1.2.11 already contains this attribute, but be sure to use 'NET_4_0' as a compiler argument. Otherwise, this attribute will not be added.
I've found a compiled version of log4net for .NET client profile here:
http://gosheg.blogspot.com/2011/04/log4net-in-net-40-c-applications-net.html
This worked for me:
In the log4net source code, add a [SecurityCritical] attribute to the Util.ReadOnlyPropertiesDictionary.GetObjectData method and build.
There might be some other things you'll need to do to get it to build for the 4.0 framework.
See this post:
Weird override problem with Fluent NHibernate and .NET 4
I have fixed the similar issue by simply updating the Log4Net package from Visual Studio package manager.
Thanks,
Khachatur
I Fixed it by adding [assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
to log4net AssemblyInfo but now its not logging