reportviewercore icon indicating copy to clipboard operation
reportviewercore copied to clipboard

replace GetExecutingAssembly with more proper assembly

Open SelvinPL opened this issue 10 months ago • 2 comments

Can we replace code like:

Assembly executingAssembly = Assembly.GetExecutingAssembly();
string str = typeof(RVSplitContainer).Namespace + ".Resources.";
m_bitmaps[4] = new Bitmap(executingAssembly.GetManifestResourceStream(str + "SplitterHorizExpand.png"));

from here (and in similar places)

with more context aware code, like:

Assembly executingAssembly = typeof(RVSplitContainer).Assembly;
string str = typeof(RVSplitContainer).Namespace + ".Resources.";
m_bitmaps[4] = new Bitmap(executingAssembly.GetManifestResourceStream(str + "SplitterHorizExpand.png"));

why?

Because in other case it is not working with single code publish. image

it is working fine without publishing as single file but this nasty single file assembly connnot be referenced

SelvinPL avatar Apr 26 '24 11:04 SelvinPL

Both Assembly.GetExecutingAssembly() and typeof(RVSplitContainer).Assembly should return same value, for both normal and single-file deployment (and both would fail if used with Native AoT).

Unfortunately this package won't work with single file deployment, because it uses Roslyn VB compiler to compile RDLC formulas and scripts. To do so, Roslyn needs to reference and load assemblies for both .NET, Report Viewer and (if used) your project. When you publish to a single file, Roslyn gets confused and throws an exception as in your screenshot. I haven't checked if anything changed since .NET 6, though.

(duplicate: #49)

lkosson avatar Apr 26 '24 14:04 lkosson

I tried to do single file publish and ended up here. WinForms .NET 8 seems to work if you use the IncludeAllContentForSelfExtract flag and change the two uses of Environment.CurrentDirectory with Directory.GetParent(Assembly.GetExecutingAssembly().Location)!.FullName. I am using ReportPath, not embedded resource. Maybe not the best but I was getting slowed down with clickonce selfcontained and having each file scanned or something slow, both in publish and in install. This ended up better, but still feels lame. Maybe it would be cool to figure out what Rosylyn needs and then exclude them from the single file if it wasn't a huge list.

frankashley avatar May 09 '24 23:05 frankashley