Audit.WebAPI configuration - c#

I am using version 7.0.6 of Audit.NET.
I added the following line to my WEB API registration method
config.Filters.Add(new Audit.WebApi.AuditApiAttribute());
When i run the application it gives the following runtime error
self referencing loop detected with type Appinstance.Path 'Action.ActionParameters.request.Properties.MS_HttpContext.ApplicationInstance.Context'.
I am using latest version of Newtonsoft.JSON from Nuget.

Can you provide the stack trace?
That error means Newtonsoft.Json was unable to serialize an object that has a reference loop, but the json conversion used by default on Audit.NET already handles this, by ignoring the reference loops with ReferenceLoopHandling setting set to Ignore.
https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.NET/AuditEvent.cs#L73
Are you using a custom data provider to save the events?
If so, please be sure to use the provided AuditEvent ToJson method, or any other method that handles self references.

Related

.net core COM with Excel range

I have an issue where I am unable to access the Name object of a range. So, I am calling Excel.Application.get_Range() and passing in a name. It returns a non-null object and I can access methods. However, Range.Name returns a System.__ComObject(). If I try to access Range.Name.Name I get an exception similar to the following
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.__ComObject' does not contain a definition for "Name"
Also, this project is one that I migrated from .net Framework to .net Core. The exact same code works in Framework. I have tried various methods of trying to determine what the underlying type is (because it does not appear to be a Name object). ITypeInfo returns that the typename is Name so it does appear to be a name object.
I'm at a loss as to why I'm unable to access Name.Name in .net core. When I check the .net Core Excel sample they never access a name object.
Also, I am able to access other COM objects like ListObject just fine.
I figured out what the issue is. For anyone else running into this with .net Core, the problem is that .net core appears to not support dynamic types through COM automatically. This is discussed in the following github issue Github issue about dynamic not working. Where it talks about why this doesn't work.
Basically, for my specific case I needed to cast the type manually and then it worked. This also impacts use of IEnumerable COM types needing to be cast directly to IEnumerable before iterating through them.
Assuming you have the following using statement.
using Excel = Microsoft.Office.Interop.Excel;
I had to turn the following:
return range.Name.Name;
into
return ((Excel.Name)range.Name).Name;
As an aside, I also noticed that if you copy/paste the cast above into the debug watch window it does not display properly and instead shows an exception about an invalid cast.

BizTalk custom pipeline component - Read a JSON node value and promote properties

In my BizTalk receive port I receive JSON from a web service. I want to read the particular JSON node value(comma separated value) in custom pipeline component and promote the property for the message if the node value has the expected value.
For example :
Json Node in message
"Dept": "support, Development,Test"
So I want read the JSON node Dept and if it has value Development then I need to promote a property for the message say devDept is true otherwise false.
I have an idea how it can be done using orchestration. But I want to do this in custom pipeline component. Can any one share the idea or help on this?
There are few approaches to do this:
You can use Newtonsoft JSON library to read JSON and then promote the property. You can add this to your project using Nuget packages. And then you would need to deploy the assembly in packages folder to GAC.
Alternatively, You can also use BizTalk JSON decoder pipeline component to convert JSON to XML and then use XmlReceive pipeline to promote properties without any use of orchestration.
Both approaches are fine, depends on other processing you are doing with JSON. Deployment wise approach 2 is better as you don't have to deploy Newtonsoft Json library to GAC
As Vikas has said, you will first want to use a JSON Decoder.
To actually promote a property depending on what is in a list of values comma separated, I would use the BRE Pipeline Framework, this allows you to execute Business Rules in Policies in a pipeline, rather than having to execute it in the Orchestration. You would just have a rule that would look at that element and if it contains Development, then create the promoted property.
Please refer to SDK samples how to implement custom pipeline component for promoting a value of XPath expression under given name:
"c:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\SDK\Samples\Pipelines\ArbitraryXPathPropertyHandler"
Using this component you can evaluate and promote to specified property name any expressions like
//*[local-name()='Dept' and contains(text(), 'Development')]

SSIS Reference Error Oracle DataAccess - Call PL/SQL procedure with custom type parameters

I'm trying to call a PL/SQL procedure with custom type parameters from a SSIS Workflow.
I tried:
Using the ADO.NET connection manager for Oracle - doesn’t work, since it doesn’t allow for parameter mapping.
Using the OLEDB connection manager - ok, but only for simple datatypes on INPUT / OUTPUT -> doesn’t solve my problem since I can’t use custom types, and I don’t have the option to use IN OUT parameters (which also occur in the procedures on the Oracle db).
I then tried to make my own custom mapping through C# by implementing all the necessary classes and interfaces used for custom UDT mapping. This way I managed to make it work to pass custom type parameters to and from the procedure. (POC created as a ConsoleApplication).
The tutorial I followed in creating the custom classes: https://www.codeproject.com/Articles/1139474/ODP-NET-User-Defined-Type-Implementation
I tried using the same code that I used in the Console Application within the SSIS Script Task. And here I met with a strange problem ☹
In order to implement the customType used in the procedure, I used the Oracle.DataAccess reference. Whenever I add this reference to the script task, I get the following error on execution:
DTS Script Task: Runtime Error
The error occurs as soon as I implement a class that uses a reference to Oracle.DataAccess. The class declaration itself seems to be causing this error, cause even when I don’t use them In scriptMain the error remains.
Whenever I comment out the classes (but leave the reference within the script) the component executes without error…
CONFIGURATION:
I'm using Visual Studio 2017 Enterprise Edition,
TargetServerVersion: SQL Server 2017
Target framework on package: .NET Framework 4.5
PATH Environment setting for Oracle client: C:\app\client32\product\12.2.0\client_1\bin
I tried changing the SQL Server target, the Target Framework and some other setting at project and package level but nothing worked.
Anyone knows how to solve this problem so that I can use my C# custom mapping within the Script Task?
Any other solutions offering calling procedures with custom parameters are also welcome :)
Lastly, if anyone knows a good auto UDT mapper I would be grateful :) I tried Odapter - ok but uses Oracle.ManagedDataAccess instead of DataAccess and I can't seem to use OracleDbType.Object there...
EDIT:
I managed to find out that the problem occurs whenever I implement an interface from a reference (f.ex. IOracleCustomType). If I only use this type as a parameter in a method or so, the script executes. As soon as I add a class implementing the interface, the 'Could not load script for execution' error appears..

Abp.AspNetCore.OData self-referencing loop when accessing odata/$metadata

I am configuring a new OData project using this package. I have configured the project as per the documentation: https://aspnetboilerplate.com/Pages/Documents/OData-AspNetCore-Integration
When I access the route /odata/$metadata, I get the following exception:
Newtonsoft.Json.JsonSerializationException: 'Self referencing loop
detected for property 'declaringType' with type
'Microsoft.OData.Edm.EdmEntityType'. Path
'result.schemaElements[0].declaredKey[0]'.'
This is thrown in the AbpUnitOfWorkMiddleware class when await _next(httpContext); is called.
I can bypass the issue by adding .AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); to the Startup class, but then this just keeps rendering the $metadata until the browser dies.
Could this be an issue with how the ABP framework handles this particular route? If I use the Microsoft.AspNetCore.OData without the ABP framework, then the $metadata route renders fine; it's actually returned as an XML document.
Targeted solution
The solution is the same as the answer to Disable Wrapping of Controller Results.
One-liner quickfix
Alternatively, you can disable wrapping by default in the PreInitialize method of your module:
Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnSuccess = false;
Before:
After:

Operation Contract Serialization Error With Entity Framework 6.0 and WCF

In my C# app I am trying to send a request through an intermediary DLL to add data to QuickBooks. The intermediary DLL, based off of a setting, sends the item add request through a WCF service. The service project is using Operation Contracts for all methods housed within it. It does not have any data contract/data members.
This works find for invoices and other transactions. However, when adding an item, I receive this error:
A first chance exception of type
'System.Runtime.Serialization.SerializationException' occurred in
System.Runtime.Serialization.dll
Additional information: Type
'System.Data.Entity.DynamicProxies.QBLookUp_A96F53AD8DA6F21651FEF0B25078616AB4989DA745EE06E345D365196574CE0F'
with data contract name
'QBLookUp_A96F53AD8DA6F21651FEF0B25078616AB4989DA745EE06E345D365196574CE0F:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies'
is not expected. Consider using a DataContractResolver if you are
using DataContractSerializer or add any types not known statically to
the list of known types - for example, by using the KnownTypeAttribute
attribute or by adding them to the list of known types passed to the
serializer.
Looking around here on Stack Overflow, I ran into several threads that suggested to turn off proxy creation in my EF Model to get around this issue. So I inserted this bit of code into the constructor in my EF project:
this.Configuration.ProxyCreationEnabled = false;
However, when I turn off proxy creation, I run into two new problems:
A) Various bits of data do not show up in my C# app. This data is supplied to the app by Entity Framework.
B) I receive this error when trying to save the item via the WCF service:
Additional information: Object graph for type 'System.Collections.Generic.HashSet`1[[EFModel.Item, EFModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' contains cycles and cannot be serialized if reference tracking is disabled
This leads me to the following conclusion - I need to have proxy creation enabled in order for my application to work, and at the same time I may be doing something wrong with my service. Does anyone have any suggestions as to what I could change to get things working?
This problem generally comes when you try to serialize data which cannot be done by WCF. Why the first answer works fine for some casea because if you will turn off the proxy creation WCF will know which data need to be serialized if you mark your class with DataContract attribute if proxy would be on then proxy classes will be created on FLY and WCF can not serialize those classes.
IF you are using entity framework so I guess you would have been using lambda expression to retrieve those records from db in your client. Since WCF does not serialize lambda Expression by default so you can not pass lambda expression to querying those records from client.(Why - since WCF is used for SOA architecture and service is generic so that any kind of client(JAVA,C++ etc) can consume this service and lambda expression is specific to some language. If it will implement this feature in WCF then it will violate the rule of SOA architecture).
If you still want to use lambda expression then you need to create dynamic lambda expression. But that is not better way to implement because client will be bound to use in that way. Try not to use lambda expression in client.
creating Dynamic Lambda expression is given in this link:
https://www.codeproject.com/Articles/1079028/Build-Lambda-Expressions-Dynamically
In the end I resorted to using a DTO for all of the objects that EF was creating proxies for that which WCF could not handle. It was a bit of extra code but the results worked out nicely, as I am still able to use proxies and lazy loading.

Categories