Reputation: 668
I translated following C# code
using (var a = new A(args1...))
{
using (var b = new A(args2...))
{
dostuff(a,b);
}
}
into C++/CLI Code like this:
try
{
a = gcnew A(args1...);
b = gcnew A(args2...);
dostuff(a, b);
}
finally
{
if (a != nullptr)
delete a;
if (b != nullptr)
delete b;
}
Types A, B, dostuff() are part of a .NET library. I dont have the source code of that library.
The library received an update, a constructor got an additional argument.
Now it got messy. I added the additional argument (a string^
) to both calls (C++/CLI and C#).
Now C# runs just fine, C++/CLI gives an internal compiler error.
fatal error C1001: An internal error has occurred in the compiler. (compiler file 'f:\dd\vctools\compiler\cxxfe\sl\p1\c\cpimport.cpp', line 16424)
VS2017 latest updates
@Some programmer dude: Yes, but atm of the implementation i wasn't certain it is the case in CLI too. Now i know.
@Hans passant: The code worked previously, so i'm pretty sure thats not the case here. I could minimize the example further.
Actually A and B are actually not different types. 'A' has a constructor of the form (c#):
A(System.IO.Stream stream); // old version
A(System.IO.Stream stream, string filename); // new version
Now the following single line leads to the internal error (c++):
A^ a = gcnew A( System::IO::File::Open(filename, System::IO::FileMode::Create), filename);
Upvotes: 0
Views: 413
Reputation: 15375
The code seams ok, I don't know why you get a compiler error but the code might be written much easier.
Simply use the C++/CLI stack semantics:
{
A a{args1...};
B b{args2...};
dostuff(%a, %b);
}
This implies all IDispose using stuff you need.
Upvotes: 2