How to get filepath in class Library - asp.net-core

I am creating a class library and I want to get path of a file in the library package. I tried to use IApplicationEnvironment but it gives me the error
NULL Reference exception

Related

VB.NET Connected SAP WSDL Preventing Solution from building

I'm trying to build a .NET Class Library that utilises a SAP generated WSDL.
In the reference.vb file that one of the WSDLs generates, I'm getting the following error in this line:
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, Order:=0)> _
With the error being BC30369 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. on System.
This only occurs within one of the generated Partial Public Classes that it generates, and not the rest.
After removing System it works:
'''
<System.Xml.Serialization.XmlElementAttribute(Form:=Xml.Schema.XmlSchemaForm.Unqualified)>
Public Property MESSAGE_V4() As String
Get
Return Me.mESSAGE_V4Field
End Get
Set
Me.mESSAGE_V4Field = Value
End Set
End Property

Custom SOAP client DLL exposed as com component using vs2013

One of our clients have an existing access db which connects to our wsoap web service. MS has deprecated the library we once used to access the web service from VBA.
This custom DLL is my only choice other than writing a new app for them which am not authorized to do because of cost.
I've written the following class
namespace MAServicesComClient
{
public class TiRequestComClient
{
public Task<ServiceReference1.SubmitAsXmlResponse> SubmitAsXmlRequest(string username, string password,string xml)
{
ServiceReference1.ServiceSoapClient srv = new ServiceReference1.ServiceSoapClient();
return srv.SubmitAsXmlAsync(username, password, xml);
}
}
}
When I execute that method in VBA it says it can't find a reference to the end point.
I have implemented this class within a console app and it works.
How do I get it to use the configuration file in the same directory as the access db file?
Edit:
It seems to work if I copy the dll file to where the database file is then register it using regasm.exe. Then drop the .dll.config where msaccess.exe is then rename to msaccess.exe.config.
But is there no way I can get to use the config within the same directory as the dll
Quite sure you can FORCE load the config file with this:
AppDomain.CurrentDomain.SetData ("APP_CONFIG_FILE",ConfigFile);
The configfile in above has to be a full path name. And if you place the .dll in the current folder. So something like this should work:
' intilize event:
Dim strP As String
strP = System.Reflection.Assembly.GetExecutingAssembly.Location
strP = strP & ".config"
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", strP)

Function pointers in C++/CLI

I am creating C++/CLI application in which I have using 3rd party tools API. One of the API has declaration in help documents as as
Error GetDrawingComponents(Drawing oDrawing,DrawingComponentVisit compVisit,DrawingComponentFilter compFilter)
Error (*DrawingComponentVisit) (DrwSolid solid,Error status)
Error (*DrawingComponentFilter) (DrwSolid solid,Error status,Filter filStatus)
Now I have used this API in my application in my .CPP I have used it like below-
Error chkError = GetDrawingComponents(Drawing oDrawing,(DrawingComponentVisit)oClsObj::VisitDrawingComponents,(DrawingComponentFilter)oClsObj::FilterDrawingComponents);
CPP file also contains defination of VisitDrawingComponents and FilterDrawingComponents. They are declared in .h file as following -
Error VisitDrawingComponents(DrwSolid solid,Error status);
Error FilterDrawingComponents(DrwSolid solid,Error status,Filter filStatus);
So now using it above way I am getting typecast error
Error 1 error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'DrawingComponentVisit'
I Can use this API the same way if I have unmanaged C++ application. Please let me know waht changes I will need to do to make this work in C++/CLI application?

Specify path of a file in a Class Library, a method in that class library called from console application

I have a ClassLibrary Project which is my business layer - Demo.Business
For this class library,
I have folder in the class library as below
TRT
|
TRT.cs
TRTDetails.cs
TRTFiles(Folder)
|
**TRTFile.txt**
In TRT.cs class i have a method
public void UpdateDetails()
{
var typeSeq = from val in TRTDetails.Read**(#"TRTFile.txt")**
}
Now i have added reference of this class library "Demo.Business.dll" to my console application - "DemoProcess.exe".
In the above Console Application I am calling the method "UpdateDetails()" as follows:
public void CallMethod()
{
UpdateDetails();
}
How can I specify the path of the file "TRTFile.txt" in the method "UpdateDetails()" in class library?
I tried using System.IO.Path.GetDirectoryName
(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Which always gives the path of executing application.
i.e
C:\\Projects\\Demo.Process\\bin\\Debug
How can i get the path as
C:\\Projects\\Demo.Business\\TRT\\TRTFiles............
There are two ways to do this:
I.
This can be done using relative path. If your's dll is also situated in Debug folder, the following path = #"..\..\..\Demo.Business\TRT\TRTFiles\" will do the work.
First ..\ will get us to C:\\Projects\\Demo.Process\\bin\\.
Second ..\ will get us to C:\\Projects\\Demo.Process\\.
Third ..\ will get us to C:\\Projects\\.
II.
Or by using classes used for writing visual studio extensions (Extensibility, EnvDTE namespaces, etc.), they provide functionality to get all information about your project and it's content. But it's complicated.

Code Analysis Error: Declare types in namespaces

Is VS2010, I analyzed my code and got this error:
Warning 64 CA1050 : Microsoft.Design : 'ApplicationVariables' should be declared inside a namespace. C:\My\Code\BESI\BESI\App_Code\ApplicationVariables.vb 10 C:\...\BESI\
Here is some reference info on the error. Essentially, I tried to create a class to be used to access data in the Application object in a typed way.
The warning message said unless I put my (ApplicationVariables) class in a Namespace, that I wouldn't be able to use it. But I am using it, so what gives?
Also, here is a link to another StackOverflow article that talks about how to disable this warning in VS2008, but how would you disable it for 2010? There is no GlobalSuppressions.vb file for VS2010.
Here is the code it is complaining a bout:
Public Class ApplicationVariables
'Shared Sub New()
'End Sub 'New
Public Shared Property PaymentMethods() As PaymentMethods
Get
Return CType(HttpContext.Current.Application.Item("PaymentMethods"), PaymentMethods)
End Get
Set(ByVal value As PaymentMethods)
HttpContext.Current.Application.Item("PaymentMethods") = value
End Set
End Property
'Etc, Etc...
End Class
I suspect that the code you entered is in your App_Code fodler of your web app. This code is accessible from your web code as you have deomnstrated but is not accessible from any other assembly.
You can suppress the instance of the error by right mouse clicking on the particular error and selecting "Suppress Message In Source." That'll result in code being added to your source that says "the next time you check this error-fuggedabodit!"
When to Suppress Warnings
--------------------------------------------------------------------------------
While it is never necessary to suppress a warning from this rule, it is safe to do this when the assembly will never be used with other assemblies.
To suppress the error on all occurences, select "Suppress in Project Suppression File"