|
Thank you, that's a good idea. I'll see if I can get into the source code for some further investigation.
All the best,
AJ
|
|
|
|
|
This was based on silly oversight on my part. Although I was unable to access the functions and files through the .dll itself. After looking through the source code I found that it was in fact accessing everything and the result it was producing was in fact perfectly fine as per the underlying code.
The issue truned out to be with the data I had been sent to test the API with as it did not match a suitable record in another system used to retrieve additional record data.
I'm still not sure why I was unable to navigate to the file in question through the .dll but thankfully, as I was able to get into the original sorce code, I managed to work aroung this.
Thank you Richard for your input!
AJ
|
|
|
|
|
Hello,
I am trying to get a leg up at my job, so this is not a homework assignment.
I need help to begin to understand Constructor Injection.
there are five types; Default, Parameterized, Copy, Static and Private. The constructor creates an instance for the class, and initializes Private fields.
Where would Injection be used?
What are the risks of modifications to the constructor, does it break the "target" code?
How do constructors allow for unit testing?
What is unit testing?
What book can you recommend to learn C#? I have some experience in C, Visual Studio, and way back Assembly.
Thanks in advance, I am sure I will have other questions also.
Tom.
|
|
|
|
|
You have many questions in one message.
I have created a "Zelda" example with lot of constructors. I hope you find it useful.
Hint: Start a new console application in C#, called ConsoleApplication1. Paste the code, set break points and debug.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var maxArrows = Link.ArrowMaximum;
var link = new Link();
IWeapon weapon = new KokiriSword();
link = new Link(10);
link = new Link(weapon);
link = new Link("Go to Lost woods");
var fierceDeityLink = new FierceDeityLink();
}
}
public interface IWeapon
{
int Damage { get; }
}
public class NoWeapon : IWeapon
{
public int Damage { get; private set; }
public NoWeapon()
{
Damage = 0;
}
}
public class KokiriSword : IWeapon
{
public int Damage { get; private set; }
public KokiriSword()
{
Damage = 1;
}
}
public class BigGoronSword : IWeapon
{
public int Damage { get; private set; }
public BigGoronSword()
{
Damage = 100;
}
}
public class Link
{
public static int ArrowMaximum { get; private set; }
public int Rupies { get; private set; }
public bool RecuredZelda { get; private set; }
public string HintFromNavi { get; private set; }
public IWeapon Weapon { get; private set; }
static Link()
{
ArrowMaximum = 100;
}
public Link()
{
Rupies = 5;
Weapon = new NoWeapon();
}
private Link(bool recusedZelda)
{
RecuredZelda = recusedZelda;
}
public Link(int rupies)
{
Rupies = rupies;
}
public Link(IWeapon weapon)
{
Weapon = weapon;
}
protected Link(int rupies, bool recuedZelda, IWeapon weapon) : this(rupies)
{
RecuredZelda = recuedZelda;
Weapon = weapon;
}
internal Link(string hintFromNavi)
{
HintFromNavi = hintFromNavi;
}
}
public class FierceDeityLink : Link
{
public FierceDeityLink() : base (int.MaxValue, true, new BigGoronSword())
{
}
}
}
Answers for your other questions:
Where would Injection be used?
Lots of places. Depends on the logic of the code. Read here.
What are the risks of modifications to the constructor, does it break the "target" code?
Impossible to say without reviewing the code.
Try... and learn from mistakes.
How do constructors allow for unit testing?
Constructors are used to create objects from classes. That has nothing to do with unit testing.
What is unit testing?
Something which is very useful and you should adapt immediately. Read here.
|
|
|
|
|
Hello,
Even though webcam quality is 5mp , webcam seems and takes low quality of picture via below codes.
Is there any way to fix this and raise quality to maximum possible?
namespace DXApplication2
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
}
private FilterInfoCollection webcam;
private VideoCaptureDevice cam;
private void Form1_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in webcam)
{
comboBox2.Items.Add(VideoCaptureDevice.Name);
}
comboBox2.SelectedIndex = 0;
}
if (pictureBox3.Image != null)
{
iTextSharp.text.Image png2 = iTextSharp.text.Image.GetInstance(pictureBox3.Image, System.Drawing.Imaging.ImageFormat.Jpeg);
png2.Alignment = Element.ALIGN_CENTER;
if (png2.Height > png2.Width)
{
float percentage = 0.0f;
percentage = 400 / png2.Height;
png2.ScalePercent(percentage * 100);
}
else
{
float percentage = 0.0f;
percentage = 320 / png2.Width;
png2.ScalePercent(percentage * 100);
}
pdf1.Add(png2);
}
private void cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bit = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = bit;
}
private void button6_Click(object sender, EventArgs e)
{
pictureBox2.Image = pictureBox1.Image;
}
modified 13-Feb-19 21:02pm.
|
|
|
|
|
i need to get a picture (.BMP or image) convert to .dpx format. The DPX is Digital Picture Exchange , so how can i convert image to DPX format in C# ?
|
|
|
|
|
.NET (and thus C#) does not natively support DPX files, so to write them you will need to either write the code to convert and save them yourself, or use a prewritten library for that. This one seems well appreciated: GraphicsMagic @ CodePlex Archive[^] - I've not used it myself though.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
When some exception occurs in a class of the .Net framework, we see the public function of a public class called by our code only, the further details (private functions, or even non-public classes) used by the public function are hidden in the StackTrace of the exception object, when the exception occurred somewhere down there.
Now I have some functionality where I'd like to have such a feature, too:
For testing, we use MS Test. I added some extensions, e.g. "ThrowsAssert " (based on Asserting Exceptions in MSTest with Assert.Throws()[^]). When such an Assert fails, I get a long StackTrace like:
bei TestUtilities.ExceptionAssert.OnNoExceptionThrown[T](String _customMessage) in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\C_TestUtilities\ExceptionAssert.cs:Zeile 29.
bei TestUtilities.ThrowsAssert.Throws[T](Action _task, String _expectedMessage, ExceptionMessageCompareOptions _messageOptions, ExceptionInheritanceOptions _inheritOptions, String _customMessage) in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\C_TestUtilities\ThrowsAssert.cs:Zeile 42.
bei MyAssembly.Tests.MyClassTests.MyFunctionTest() in C:\Users\bernhard.hiller\SVN\Product-SW\trunk\MyAssemblyTests\MyClassTests.cs:Zeile 36.
or even longer...
Is there some way to "hide" all those functions of class ThrowsAssert and ExceptionAssert in the StackTrace?
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
As far as I'm aware, the only way to hide methods from the stack trace is to get the compiler to inline them - since they are no longer called, they are no longer available to stack tracing. Unfortunately for you, there is no way that I know of to force the compiler to inline a method - you can force it to not inline, but the reverse does not apply. I understand that you can (in v4.5 and later) hint that you might like it inlined: MethodImplOptions Enum (System.Runtime.CompilerServices) | Microsoft Docs[^] using the AgressiveInlining field, but that is just a suggestion, not an order!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Take the "stack trace", run it through a "string reader", and eliminate the entries you don't want (via a class or method "name" related to the exception).
I do all my "trace filtering" in the
Application_DispatcherUnhandledException
event handler.
At that point, I can even "continue execution" via "e.handled" (if the situation calls for it).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I got a class and I have created an array in the class
<pre>class myclass
{
string array = new string[5];
for (int i = 0; i< array.Length; i++)
{
array[i] = "whatever"
}
}
now I want to transfer this array into my main, maybe create new array at main and just transfer the info. how do i create and
string GetArray() in class to return an array, and how do I get the info into main. thanks
|
|
|
|
|
|
I have a VB.NET class library with a single public function with a single parameter that calls a method to produce the string return value. I referenced it in the C# project, and added a using statement for the namespace. However, I have no success in even coding to use the function from the dll. Can someone point me in the right direction? There are lots of answers to the problem on the web, but none work for me. Here is a portion of the VB dll code. GetSeparators() prepares and returns the string. I am developing the library to get information from a COM library. I have not found a convenient code for C# to use the COM library. The VB dll is NET 3.5 and the C# app is NET 4.6.1.
Public Class HYSYSFetch
<pre>
Private _filename As String
Private _sepstring As String = ""
Public Function FetchSeparators(filename As String) As String
_filename = filename
GetSeparators()
Return _sepstring
End Function</pre>
|
|
|
|
|
All you have to do is create an instance of the containing class, and call the function on that
private void MyFunction()
{
HYSYSFetch hsf = new HYSYSFetch(...);
string result = hsf.FetchSeparators(strPathToFile);
} If that doesn't work, you need to tell us exactly what you get as an error message, and show us the exact code you tried.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you. This is something I have done a hundred times with projects. But I never used a VB dll with a C# project. I shall remember that the right solution is the simple one.
|
|
|
|
|
Once they are compiled, VB and C# DLLs are the same thing - you can treat them as if they were written in any language. (The same applies to any language which compiles to IL, so F#, Cobol, C++ - all "look the same" once compiled.)
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Griff, Once you cleared the fog and got me started, the rest was easy. Everything works smoothly when the C# application calls the VB.NET library functions. Thanks again.
I needed the VB library because C# doesn't easily communicate with a COM object. And I already had the VB code in a VB application. I develop most of my class libraries with C#, just to keep in practice. My VB application that uses Selenium Basic (Selenium wrapper for VB & VBA) doesn't play with Firefox latest editions. So my need to use C# to make use of Selenium which doesn't work with VB. My main use is to get information from a process simulator and transfer it to a web page, thus eliminating transcribing errors. This takes several technologies to get it to work.
|
|
|
|
|
You're welcome!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Well, I spoke too soon. The VB dll is not playing well with the C# app. The C# app doesn't recognize a particular method in the dll. Call to a different method works OK. Throws an error, something about Reflection and the wrong number of arguments. But the number of arguments is correct; there is only one. I had an earlier version working, but the C# app was not getting the proper data from the dll which fetches data from a COM app. I'll have to go back to an earlier version and trace the problem.
|
|
|
|
|
Don't forget the error may have "bubbled up" from a method below the one you are calling.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Turns out I had a few minor errors in the VB code. I found all of them, and cleaned up the code while I was finding them. It all works as it should. I learned a lot with this little project. It was a cascade with a C# app calling a VB.NET dll which in turn called a licensed COM library. So there was lots of opportunity to get the code wrong. Thanks for the help.
|
|
|
|
|
This is the message received. Is there a way around this without changing the GOP?
Severity Code Description Project File Line Suppression State
Error Fody: An unhandled exception occurred:
Exception:
Failed to execute weaver C:\FTDTLRepos\DTPLite\packages\Costura.Fody.3.1.0\netclassicweaver\Costura.Fody.dll
Type:
System.Exception
StackTrace:
at InnerWeaver.ExecuteWeavers()
at InnerWeaver.Execute()
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
Exception has been thrown by the target of an invocation.
Type:
System.Reflection.TargetInvocationException
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Security.Cryptography.CryptoConfig.CreateFromName(String name, Object[] args)
at System.Security.Cryptography.MD5.Create()
at ModuleWeaver.CalculateHash()
at ModuleWeaver.Execute()
at InnerWeaver.ExecuteWeavers()
Source:
mscorlib
TargetSite:
System.Object InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.
Type:
System.InvalidOperationException
StackTrace:
at System.Security.Cryptography.MD5CryptoServiceProvider..ctor()
Source:
mscorlib
TargetSite:
Void .ctor() DTP_Lite
|
|
|
|
|
The code is apparently using MD5, which is not FIPS compliant. Your workstations apparently have a GPO applied to them that enables FIPS, which prevents certain crypto algorithms from being used, like MD5.
You cannot use the library unless you have options to change out the crypto it's using. Contact the people that made that library you're using to see if they have a FIPS-compliant version or can change something in it so it works under FIPS.
If not, you have two choices. Either find and use a different library that is FIPS compliant, or get the network/Windows/Security admins to turn FIPS off. (Being a government installation, good luck with that.)
Read this: Why We’re Not Recommending “FIPS Mode” Anymore
|
|
|
|
|
What you explained, I understand. I'm wondering, however if there's code I can write that will embed the dlls during compile time.
|
|
|
|