0

we are generating a mass of documents very dynamically. Therefore we concatenate source code and build a dll at runtime. This is running since windows XP. Now we are in tests of windows 10 and it fails compiling this dll with the error "BC31019: Unable to write to output file 'C:\Users[name]AppData\Local\Temp\xyz.dll': The specified image file did not contain a resource section"

For testing purposes we remove all generated source code and replace it by a rudimental class with only one function (throwing an exception with specified text) and no referenced assemblies. This is also running on all machines except windows 10. Same error.

Can anybody guess why?

This is the rudimental method

Public Sub Compile()

   Dim lSourceCode = "Namespace DynamicOutput" & vbCrLf &
                              "   Public Class Template" & vbCrLf &
                              "      Sub New()" & vbCrLf &
                              "      End Sub" & vbCrLf &
                              "      Public Sub Generate(ByVal spoolJob As Object, ByVal print As Object)" & vbCrLf &
                              "         Throw New System.Exception(""Generate reached"")" & vbCrLf &
                              "      End Sub" & vbCrLf &
                              "" & vbCrLf &
                              "   End Class" & vbCrLf &
                              "End Namespace"

   Dim lParams As CodeDom.Compiler.CompilerParameters = New CodeDom.Compiler.CompilerParameters
   lParams.CompilerOptions = "/target:library /rootnamespace:CompanyName /d:TRACE=TRUE /optimize "
   lParams.IncludeDebugInformation = True
   lParams.GenerateExecutable = False
   lParams.TreatWarningsAsErrors = False
   lParams.GenerateInMemory = True

   Dim lProviderOptions As New Dictionary(Of String, String) From {{"CompilerVersion", "v4.0"}}

   Dim lResult As CodeDom.Compiler.CompilerResults = Nothing

   Using provider As New VBCodeProvider(lProviderOptions)
      lResult = provider.CompileAssemblyFromSource(lParams, lSourceCode)
   End Using

   ' ... check for errors

   Dim lInstance As Object = lResult.CompiledAssembly.CreateInstance("CompanyName.DynamicOutput.Template")
   lInstance.GetType.GetMethod("Generate").Invoke(lInstance, New Object() {Me.SpoolJob, Me.Print})

End Sub
Twelve
  • 1
  • 2
  • Just by looking at your first sentence "we are generating a mass of documents very dynamically. Therefore we concatenate source code and build a dll at runtime", what are you talking about?! Providing code is not always required; but at least a clear enough picture of what might be provoking the problem. The error is clear: the code is referring to a resource which cannot be found; focus your problem search (description here) on this issue and avoid general (and extremely unclear) ideas. – varocarbas Dec 09 '15 at 09:30
  • The first sentence was only an introduction. The problem is that we cannot compile a dll at runtime in windows 10 without getting the error BC31019. – Twelve Dec 09 '15 at 09:48
  • The point of my comment was that with the provided information it is impossible to understand what is going wrong/help. Error messages without further context are useless (i.e., the same error can be triggered because of many different reasons). In any case, in this specific situation it seems clear where you should look at: all the references in your code to the xyz.dll (and/or make sure that the given path still exists; a directory existing in XP doesn't have to also exist in Windows 10. In fact, a directory existing in certain machine doesn't have to exist in another one). Offtopic post. – varocarbas Dec 09 '15 at 09:51
  • I understand what you mean. But the problem is that our testing purposes are throwing the same error. I have added the code. – Twelve Dec 09 '15 at 10:03
  • This is a different story. Now the problem is much clearer. I have tried to execute your code (which does things I haven't ever tried in VB.NET) and it does complain about a missing library (I am also using Windows 10). I guess that the only solution is finding this library (e.g., in Windows XP) and making sure that this code finds it. BUT my true recommendation is moving outside this weird approach; not sure why you are doing what you are doing, but there are surely plenty of .NET alternatives allowing to do it easier and in a more compatible way (with Windows 10 or anything else). – varocarbas Dec 09 '15 at 10:13
  • We do what we do because we need to create a large mass of documents. These documents can be build via templates designed by the user. And out of pure performance reasons we generate source code that includes only the components that are actually needed. Because when you generate 200,000 documents 150 milliseconds / document more or less makes a different. – Twelve Dec 09 '15 at 10:26
  • I insist: completely up to you, but I am sure that there is nothing which an old approach can add to the new .NET capabilities. To not mention that old approaches are likely to continue having compatibility problems. If you want to keep it anyway, the solution is clear: locate what it needs and make sure that can find it. – varocarbas Dec 09 '15 at 10:29

0 Answers0